Using the Delve Debugger in Visual Studio Code for Go Development
If you're experiencing issues using the Delve debugger within Visual Studio Code for Go development, the following detailed steps will guide you through the setup process:
Install and Configure Go Environment:
Install Visual Studio Code:
Install Go Extension in VS Code:
Open Workspace and Source Code:
Open Debugger and Set Breakpoint:
Start Debugging:
Debug Controls:
Launch.json Configuration:
An unmodified launch.json file for reference:
{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${workspaceRoot}", "env": {}, "args": [], "showLog": true } ] }
Sample Go Code to Demonstrate Debugging:
package main import "fmt" func main() { fmt.Println("Hello World!") i := 101 fmt.Println(i) }
Expected Output:
The debugger will break at the breakpoint set and allow you to step through your code, inspect variables, and control the program's execution.
The above is the detailed content of How to Set Up and Use the Delve Debugger in Visual Studio Code for Go Development?. For more information, please follow other related articles on the PHP Chinese website!