Skip to main content

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​

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​

  1. Select the DebugHero icon in the Activity Bar.
  2. 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​

  1. In the Debug Sessions view, enter the values of the target pod:

    FieldRequiredDescription
    Pod labelsYesA label selector, for example app=checkout. DebugHero uses the first pod that matches.
    NamespaceNoDefault: default.
    Container nameNoDefault: the first container of the pod.
    Match process nameNoText to find the target process. Default: PID 1.
    App portNoAn application port to forward to the same port on localhost.
    Kubeconfig pathNoA path, or a list of paths separated by :. Prefilled with KUBECONFIG of the IDE, else ~/.kube/config, the same as kubectl. The form keeps the value you submit. After you change KUBECONFIG, check this field.
  2. Select Start Debug Session.

  3. 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.

Configuration that the extension uses
{
"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.

ActionWhat it does
DisconnectCloses the connection of VS Code to Delve. The session continues, and Delve stays attached. You can connect again.
Stop SessionEnds 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​

  1. Select Stop Session on the session in the Debug Sessions view, or run DebugHero: Stop Debug Session from the Command Palette.
  2. 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.

MessageWhat to do
The session is still startingWait until the session is READY, then try again.
The debug container does not answerTry again. If the problem continues, restart the pod.
debugd did not answer in timeThe stop can still finish. Refresh the session list to see the result.
Delve did not detach through its APIThe 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​

SettingDefaultDescription
debughero.port58090The 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.