Backend Development 10 min read

Debugging Go Applications with Delve and VSCode: Launch and Remote Attach Techniques

This article explains how to efficiently debug Go programs using Delve (dlv) and VSCode, covering both local launch debugging and remote attach debugging, configuration steps, breakpoint types, and useful console commands for backend developers.

Sohu Tech Products
Sohu Tech Products
Sohu Tech Products
Debugging Go Applications with Delve and VSCode: Launch and Remote Attach Techniques

Debugging is essential for developers, and the article emphasizes that programs are not just written but also debugged, highlighting methods such as log printing, pprof metrics, and non‑intrusive single‑point debugging.

For C/C++ the standard tool is gdb , while Go developers commonly use dlv . Three typical dlv workflows are described: (1) compile to a binary then dlv exec , (2) attach to a running process with dlv attach , and (3) debug a core dump with dlv core .

The author prefers transparent, portable debugging over heavy IDE solutions; VSCode is presented as a lightweight UI that still relies on the underlying dlv commands.

Debugging modes are divided into two categories: launch (debug a compiled binary) and attach (debug a running process). Each mode can be further classified as local or remote, yielding four scenarios: local launch, local attach, remote launch, and remote attach.

Example 1 – Remote launch debugging: Compile the binary on the remote host (or via a task), then create a .vscode/launch.json file such as: { "name": "Launch file", "type": "go", "request": "launch", "mode": "debug", "program": "${file}" } Open the main Go file, set breakpoints, and start debugging; VSCode builds the binary, launches dlv , and pauses at breakpoints.

Example 2 – Remote attach debugging: Start the target program on the remote machine, then run a headless dlv DAP server: dlv --headless -l 0.0.0.0:2345 attach 7488 --api-version 2 Configure VSCode to connect to this server with a launch.json snippet like: "configurations": [ { "name": "Connect to server", "type": "go", "request": "attach", "mode": "remote", "remotePath": "{compiled project path}", "port": 2345, "host": "192.168.56.12" } ] The crucial remotePath must point to the directory where the binary was compiled, not the runtime location.

VSCode supports three breakpoint types: ordinary breakpoints, conditional breakpoints (e.g., tag == 2 ), and logpoints that print messages without stopping execution (e.g., result is {result.code()} ).

In the Debug Console you can issue Delve commands prefixed with -exec , such as -exec disassemble , -exec print $rip , or -exec help to explore available commands.

Summary:

Debugging consists of launch and attach modes; launch is common during development, attach during testing or production.

Running a dlv DAP server enables network‑based debugging from any editor.

VSCode acts as a thin client, allowing local code to debug remote processes.

The remotePath parameter is essential for successful remote attach debugging.

Beyond ordinary breakpoints, conditional and logpoint breakpoints greatly enhance debugging efficiency.

backenddebuggingdevelopmentGoVSCodeRemote Debuggingdelve
Sohu Tech Products
Written by

Sohu Tech Products

A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.