Go Remote debugging: no source path mapping setting, breakpoints disabled

Problem

A Go Remote run/debug configuration connects to Delve on a remote machine or in a container. The debugger suspends on a panic and the stack frames appear, but the editor does not open the matching source file. Breakpoints render as a circle with a slash instead of a red dot.

The configuration has no table for mapping source paths. The PHP debugger offers path mappings for the same purpose, and the Go Remote configuration has no equivalent setting.

Cause

The Go Remote configuration holds three settings: Host, Port, and On disconnect. No path mapping table exists, and none is planned. A manual table was requested in GO-3988 and declined.

GoLand resolves remote paths to local files without configuration. GoLand reads the file paths recorded in the debugged binary and compares them against the files in the project. Resolution fails when those recorded paths do not correspond to the project layout.

GoLand 2018.3 added a pluggable path converter in place of a manual table, tracked in GO-4844. A build-system plugin can register a converter and supply mapping rules for the layout that build system produces.

GoLand connects to Delve over the JSON-RPC v2 API. It does not implement the Debug Adapter Protocol, and it sends no substitute-path rules to Delve. A substitute-path setting on the Delve side therefore does not change how a GoLand session resolves paths.

Resolution

  1. Compile the application with debug information:
    go build -gcflags="all=-N -l"
    
  2. Do not pass -ldflags="-w" or -ldflags="all=-w". These flags strip the DWARF data that Delve needs.
  3. Compile Delve with the same Go version, host, and target as the application.
  4. With the GOPATH layout, compile the project at the same path relative to $GOPATH on both machines.
  5. Remove symbolic links from the project path. Symlinks are not compatible with the Go toolchain, Delve, and GoLand together.

The full remote setup is documented in Attach to running Go processes with the debugger.

Bazel projects

The Bazel plugin registers its own path converter for Go debug sessions. The converter resolves execution-root paths against local files in both directions, through the Bazel server. The converter is registered per project rather than per run configuration, so it can also apply to a Go Remote configuration in a project opened as a Bazel project.

When the converter cannot match a path, it writes a warning to idea.log:

Server could not resolve remote path '<path>' to local path.

That line names the path the binary recorded. Compare it against the project layout to find which prefix does not match.

If the paths still do not resolve

  1. Reproduce the session once with the Go Remote configuration.
  2. Select Help | Collect Logs and Diagnostic Data from the main menu.
  3. Upload the resulting ZIP file to uploads.jetbrains.com and send the Upload ID to support.

Automatic resolution can also select the wrong file when two files share a name. That defect is tracked in GO-19917.

0 out of 0 found this helpful

Please sign in to leave a comment.

Have more questions?

Submit a request