"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > VS Code & Delve Debug Go Code: Build Tags Configuration Guide

VS Code & Delve Debug Go Code: Build Tags Configuration Guide

Posted on 2025-03-12
Browse:848

How to Configure Debugging with Go Build Tags in Visual Studio Code and Delve Debugger?

Debugging Go with Tags in Visual Studio Code and Delve Debugger

When utilizing build tags to compile various versions of a Go program, it remains important to configure the debugger for optimal utilization.

Launch Configuration for Debugging with Build Tags:

To specify build tags within a launch configuration for Visual Studio Code's Go plugin, you can employ the buildFlags key along with a corresponding value of "-tags Tag". This enables the inclusion of build tags during the debugging process.

Configuration for Debugging with Build Tags:

Utilizing the buildFlags key, modify the launch configuration as follows:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "DebugBinWithTag",
      "type": "go",
      "request": "launch",
      "mode": "exec",
      "remotePath": "",
      "port": 2345,
      "host": "127.0.0.1",
      "program": "${workspaceRoot}/BinaryName",
      "env": {},
      "args": [],
      "showLog": true,
      "buildFlags": "-tags THISISAFLAG"  // Specify build tags here
    }
  ]
}

Multiple Launch Configurations for Different Build Tags:

If your project necessitates distinct build configurations, consider creating multiple launch configurations. Each configuration can then have its own buildFlags value corresponding to the required build tag. This customization ensures that each configuration targets the intended build variant.

Additional Tips:

  • Ensure that the build tag syntax is correct (e.g., // build THISISAFLAG).
  • Verify that the program field in the launch configuration points to the compiled binary with the desired build tags.
  • If you encounter issues, try clearing the debug cache (Ctrl Shift F5 in VSCode).
Release Statement This article is reproduced on: 1729735929 If there is any infringement, please contact [email protected] to delete it.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3