This is a creation in
Article, where the information may have evolved or changed.
Want to know more, add QQ group 72132378
Google's official debug example for Golang uses GDB by default
However, using GDB to debug go programs will encounter goroutine problems, because GDB does not understand the go
Therefore, delve black technology is used to debug the Golang program.
The Pure command line debugging method is easy to search on the net, this article mainly takes the liteide to carry on the program debugging
Turn off compiler optimizations
Normal go build/install out of the GO program is fully optimized, forced to use the debugger hook debugging, some local variables/lamda expression captured variables will go directly into the register, cannot use the debugger to view
Delete all pkg, add the parameter-gcflags "-n-l" to the build or install parameter to turn off compiler optimization
For example:
go install -gcflags "-N -l" svc\gamesvc
Delve Debugger Installation Method
Liteide comes with GDB, but does not have a delve debugger, it needs to install itself, the command is as follows
go get github.com/derekparker/delve/cmd/dlv
The delve debugger will be placed under your gopath/bin.
Delve debugger configuration in Liteide
Select Debugger
In the Liteide menu, select Debug->debugger/delve
Delve environment variable settings
At this time, Liteide still cannot find delve, because it is not in the environment variable path, there is no need to modify environment variables, only need to liteide environment configuration
In the Liteide menu, select View--Edit current environment, modify in Popup document
PATH=c:\mingw32\bin;%GOROOT%\bin;%PATH%;c:\your\path\to\delve
Remove the comment # before path, add a semicolon in%path%, and then the path to the delve debugger
Start debugging
Select your project, click F5, enter debug mode
Debugger Displays variable values
Liteide when debugging with delve, it is not possible to properly capture delve debug return data in Windows such as variable monitoring (because the format is too complex ...)
It doesn't matter, we can use the command line to display
Liteide console or debug Output window is actually a standard command line when delve debugging
The command is as follows
-
P variable name to view variable values
-
Locals viewing local variables
-
LS to view the current file
-
Stack View Stack
-
Help can see a variety of helpful
Debugging external Programs
If your program is an external program, or a program installed to the Gopath/bin directory using go install, you may encounter a startup path error when you start the program using the delve debugger
debugging other applications using liteide menu debugging ... Fill in the path you want to debug the program and working directory, you can solve this problem