VS Code debugging
This document describes how to set up Rails debugging in Visual Studio Code (VSCode) using the GitLab Development Kit (GDK).
Setup
- Install the
debug
gem by runninggem install debug
inside yourgitlab
folder. - Install the VSCode Ruby rdbg Debugger extension to add support for the
rdbg
debugger type to VSCode. -
In case you want to automatically stop and start GitLab and its associated Ruby Rails server, you may add the following VSCode task to your configuration under the
.vscode/tasks.json
file:{ "version": "2.0.0", "tasks": [ { "label": "start rdbg", "type": "shell", "command": "gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true rdbg --open -c bin/rails server", "isBackground": true, "problemMatcher": { "owner": "rails", "pattern": { "regexp": "^.*$", }, "background": { "activeOnStart": false, "beginsPattern": "^(ok: down:).*$", "endsPattern": "^(DEBUGGER: wait for debugger connection\\.\\.\\.)$" } } } ] }
-
Add the following configuration to your
.vscode/launch.json
file:{ "version": "0.2.0", "configurations": [ { "type": "rdbg", "name": "Attach with rdbg", "request": "attach", // remove the following "preLaunchTask" if you do not wish to stop and start // GitLab via VS Code but manually on a separate terminal. "preLaunchTask": "start rdbg" } ] }
The VSCode Ruby extension might have issues finding the correct Ruby installation and the appropriate
rdbg
command. In this case, add "rdbgPath": "/home/user/.asdf/shims/
(in the case of asdf) to the launch configuration above.Debugging
Prerequisites
- You must have a running GDK instance.
To start debugging, do one of the following:
- Press F5.
- Run the
Debug: Start Debugging
command.