Home >Development Tools >VSCode >Detailed explanation of how to debug Golang projects in VSCode
This article will introduce to you how to use VSCode to debug Golang projects. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
## Recommended study: "vscode tutorial"
{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": { "GOPATH":"D:/Develop/vscodegolang" }, "args": [], "showLog": true } ] }Among them: "port" and "host" are automatically generated by the go plug-in"env" is to set the environment variable, just set it to your project directory (the folder containing bin, src)
Prepare debugging plug-inAt this time, find main.go and press F5, an error message will be reported:
Failded to continue:"Cannot find Delve debugger. Install from https://github.com/derekparker/delve & ensure it is in your "GOPATH/bin" or "PATH"We use the go command line to compile the debugger
go get github.com/derekparker/delve/cmd/dlvDebug the dlv Place the tool in the bin directory of GOPATH (project directory)Start debuggingSelect main.go to be debugged, click F5, you can start debuggingDebugging shortcut keys Consistent with Visual Studio system
{ "version": "0.2.0", "configurations": [ { "name": "client", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": { "GOPATH":"D:/Develop/vscodegolang" }, "args": [], "showLog": true }, { "name": "server", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${workspaceRoot}/src/server", "env": { "GOPATH":"D:/Develop/vscodegolang" }, "args": [], "showLog": true } ] }"program" The "${fileDirname}" uses the currently selected file as the starting pointIt is more recommended to use the "${workspaceRoot}" of "program" and configure it with the package name as the starting pointFor more programming-related knowledge, please visit:
programming video! !
The above is the detailed content of Detailed explanation of how to debug Golang projects in VSCode. For more information, please follow other related articles on the PHP Chinese website!