I asked this question on Stackoverflow and vscode-ruby but did not get any responses. Perhaps someone here can help?
Using Visual Studio Code and the rebornix.Ruby
extension, launch
ing a Ruby program for debugging works fine: when execution encounters a break point, the code corresponding to the top of the stack is displayed and variables in scope are also displayed.
However, when debugging a Ruby gem by attach
ing to a running gem, when execution encounters a break point in the gem, the code corresponding to the top of the stack is not displayed, although the variables in scope are displayed. This is the launch.json
configuration:
{
"cwd": "${workspaceRoot}",
"name": "Attach rdebug-ide",
"request": "attach",
"remoteHost": "localhost",
"remotePort": "1234",
"remoteWorkspaceRoot": "/",
"restart": true,
"showDebuggerOutput": true,
"type": "Ruby",
},
This is the script that runs the Jekyll gem, which Visual Studio Code attaches to:
bundle exec rdebug-ide \
--host 0.0.0.0 \
--port 1234 \
--dispatcher-port 26162 \
-- \
/usr/local/bin/jekyll serve \
--livereload_port 35721 \
--force_polling \
--host 0.0.0.0 \
--port 4001 \
--future \
--incremental \
--livereload \
--drafts \
--unpublished
To explain further, the gem’s source code is available locally because it was provided in the gem, in the lib/
directory, as is normal.
$ gem info jekyll
*** LOCAL GEMS ***
jekyll (4.2.2, 4.2.1)
Authors: Tom Preston-Werner, Parker Moore, Matt Rogers
Homepage: https://jekyllrb.com
License: MIT
Installed at (4.2.2): /home/mslinn/.gems
(4.2.1): /home/mslinn/.gems
A simple, blog aware, static site generator.
$ cd $HOME/.gems/gems/jekyll-4.2.2/lib
$ ls
blank_template/ jekyll/ jekyll.rb site_template/ theme_template/
$ find . -name '*.rb' | wc -l
88
How can Visual Studio Code associate the source code for the gem when attaching to its running process?
More detail is available on a blog post that I wrote.