-
Notifications
You must be signed in to change notification settings - Fork 757
debug adapter
The Debug Adapter runs in a separate Node.js process, which is spawned by VS Code when you debug Go code.
Please see the Debug Adapter Protocol (DAP) to understand how the Debug Adapter acts as an intermediary between VS Code and the debugger (Delve).
This codebase is currently in flux: We are working on using Delve
's native DAP implementation instead of this one. Follow along with golang/vscode-go#23 for updates on that work.
- Before you begin
- Debug only the Debug Adapter
- Debug the VS Code extension and the Debug Adapter
- Debug VS Code and the Debug Adapter
Before you start working on your change, please read the contribution guidelines. This document assumes that you are already familiar with the process of building, running, and sideloading the VS Code Go extension.
As a next step, you may want to debug the Debug Adapter, in order to understand how your change work with Delve.
NOTE: Since the Debug Adapter runs in a separate process from the rest of the extension, the steps below only enable you to debug the Debug Adapter code, not the entire extension. To debug the entire extension, as well as the debug adapter, see the instructions below.
- Open the
vscode-go
folder in VS Code. - Go to the Run view and choose the
Launch as server
debug configuration. - Add breakpoints as needed to the
vscode-go/src/debugAdapter/goDebug.ts
file. - Open another instance of VS Code and open the Go project to debug.
- Create a debug configuration for the Go project if it doesn't exist. Set
"debugServer": 4711
in the root of the configuration. - Start debugging your Go program using this configuration. This will trigger the breakpoints in
goDebug.ts
file.
You can take this step if your change modifies both the Debug Adapter and the main extension.
- Open the
vscode-go
folder in VS Code. - Go to the Run view and choose the
Extension + Debug server
debug configuration. This combinesLaunch Extension
andLaunch as server
debug configurations. - Add breakpoints as needed and start debugging (
F5
). It will start an Extension Development Host window and the Debug Adapter server process at port 4711. Debuggers are attached to both processes and the breakpoints will apply to both of them. - In the Extension Development Host window, open the Go application source code you'd like to debug. As above, create a debug configuration pointing to the program you want to debug. Add
"debugServer": 4711
to the root of the configuration. Then, run the debug configuration (F5
), which will start debugging the Go application. - Combined debug information (call stacks, breakpoints, etc.) of the debugged Extension Development Host and the Debug Adapter will be displayed in the debug view of the original VS Code window. You can use the drop-down menu in the Debug toolbar to switch between the two instances (
Launch Extension
andLaunch as server
).
In some very rare cases, you may find it helpful to debug VS Code itself. An example of such a case might be verifying workbench behavior and state before executing debug adapter API calls.
First, ensure that you can build and run VS Code from source successfully.
Next, follow these steps:
- Open an instance of VS Code that you have built from source.
-
Sideload your local
vscode-go
extension to the local instance of VS Code. This can be done by copying the contents of thevscode-go
directory into$HOME/.vscode-oss-dev/extensions/ms-vscode.go
(the exact location may vary by OS). - Open the
vscode
folder in Visual Studio Code. - Launch the VS Code debug instance (OSS - Code) by choosing the
Launch VS Code
debug configuration from the drop-down in the Run view. Add breakpoints as needed. - In another instance of VS Code, open the
vscode-go
folder. Choose theLaunch as server
debug configuration in the Run view. Add breakpoints as desired in thevscode-go/src/debugAdapter/goDebug.ts
file. - Open the Go application you want to debug in the OSS Code instance initiated in step 4.
- Create a debug configuration with the setting
"debugServer": 4711
. - Start debugging your Go application. Observe that any breakpoints you set in the VS Code and debug adapter codebases will be triggered.
✏️ Want to contribute to this wiki?
Update the source and send a PR.