Debugging Go Code in Visual Studio Code with Delve
Setting up Delve debugger in Visual Studio Code for Go development requires the following steps:
Prerequisites:
Setup:
Use keyboard shortcuts to control the debugger:
Example Configuration:
{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}", "env": {}, "args": [] } ] }
Sample Code:
package main import "fmt" func main() { fmt.Println("Hello World!") i := 101 fmt.Println(i) }
Result:
Visual Studio Code will launch the debugger and show the debug pane. You can hover over variables to see their values and use breakpoints to step through the code.
The above is the detailed content of How to Debug Go Code in Visual Studio Code with Delve?. For more information, please follow other related articles on the PHP Chinese website!