VS Code
The DebugHero extension adds a Debug Sessions view to VS Code. From this view you start sessions, see their status, and connect the VS Code debugger to Delve.
Requirements
- The Go extension (
golang.go). DebugHero uses its debug adapter (dlv-dap). VS Code installs it together with DebugHero. debugdruns on your machine. See Your first debug session.
Open the workspace
Open the root folder of the Go module that was built into the image, as the first folder of the workspace. DebugHero maps this folder to the build directory of the binary. See Map source paths.
Sign in
- Select the DebugHero icon in the Activity Bar.
- Select Sign In. Your browser opens the sign-in page.
You can also run DebugHero: Login from the Command Palette.
The extension stores its credentials in the VS Code Secret Storage. debugctl stores its credentials in the OS keychain. Sign in to each one separately.
Start a session
-
In the Debug Sessions view, enter the values of the target pod:
Field Required Description Pod labels Yes A label selector, for example app=checkout. DebugHero uses the first pod that matches.Namespace No Default: default.Container name No Default: the first container of the pod. Match process name No Text to find the target process. Default: PID 1. App port No An application port to forward to the same port on localhost.Kubeconfig path No A path, or a list of paths separated by :. Prefilled withKUBECONFIGof the IDE, else~/.kube/config, the same askubectl. The form keeps the value you submit. After you changeKUBECONFIG, check this field. -
Select Start Debug Session.
-
The session shows in the list. When it is ready, select Connect.
VS Code starts a debug session with this configuration. You do not need a launch.json file.
{
"type": "go",
"request": "attach",
"mode": "remote",
"host": "127.0.0.1",
"port": "<debugger_port>",
"debugAdapter": "dlv-dap",
"substitutePath": [{"from": "${workspaceFolder}", "to": "<substitute_binary_path>"}]
}
Templates
To reuse the values of a form, select Save current values as template. To fill the form from a template, select it in Load template. Templates are stored in VS Code on your machine. They are not synchronized.
Disconnect and stop
There are two actions. They do different things.
| Action | What it does |
|---|---|
| Disconnect | Closes the connection of VS Code to Delve. The session continues, and Delve stays attached. You can connect again. |
| Stop Session | Ends the session. Delve removes its breakpoints and detaches. The app continues to run. The debug container exits, and the session becomes COMPLETED. You cannot connect again. |
Disconnect
Run DebugHero: Disconnect from Remote Debug Pod from the Command Palette, or stop the VS Code debug session.
When you disconnect, VS Code shows a reminder: "Disconnected. Session N is still attached to POD." Select Stop session to stop it, or Keep running to keep it. VS Code never stops a session automatically.
If you do not stop the session, it stops automatically after 1 hour.
Stop
- Select Stop Session on the session in the Debug Sessions view, or run DebugHero: Stop Debug Session from the Command Palette.
- Confirm the stop.
If VS Code is connected to the session, it disconnects first.
The stop usually takes a few seconds. It can take up to 75 seconds: debugd waits up to 45 seconds for the debug server to shut down, then up to 30 seconds for the debug container to exit. VS Code waits up to 90 seconds for the result.
| Message | What to do |
|---|---|
| The session is still starting | Wait until the session is READY, then try again. |
| The debug container does not answer | Try again. If the problem continues, restart the pod. |
debugd did not answer in time | The stop can still finish. Refresh the session list to see the result. |
| Delve did not detach through its API | The session stopped, but the debug container stopped Delve with a signal. Make sure that the pod still runs. If the app crashed at a breakpoint, restart the pod. |
You can also stop a session from a terminal with debugctl stop.
Settings
| Setting | Default | Description |
|---|---|---|
debughero.port | 58090 | The port of debugd. If you change it, also set DEBUG_DAEMON_PORT for debugd. |
Session limit
If your plan does not allow another session, the view shows a message and a View plans button.