introduce
Delve is a source-level debugger for Go programs.
Delve enables you to interact with your program by controlling the execution of the process, evaluating variables, and providing information about thread/Goroutine state, CPU register state, and more.
The goal of this tool is to provide a simple yet powerful interface for debugging Go programs.
The project address
Github.com/go-delve/de…
The installation
Support MAC, Linux,win platform installation.
mac install
$ git clone https://github.com/go-delve/delve
$ cd delve
$ go install github.com/go-delve/delve/cmd/dlv
Copy the code
Confirm the installation.
dlv version
Copy the code
operation
Obtaining Help Information
dlv
Copy the code
The results of
Usage:
dlv [command]
Available Commands:
attach Attach to running process and begin debugging.
connect Connect to a headless debug server.
core Examine a core dump.
dap [EXPERIMENTAL] Starts a TCP server communicating via Debug Adaptor Protocol (DAP).
debug Compile and begin debugging main package in current directory, or the package specified.
exec Execute a precompiled binary, and begin a debug session.
help Help about any command
run Deprecated command. Use 'debug' instead.
test Compile test binary and begin debugging program.
trace Compile and begin tracing program.
version Prints version.
Flags:
--accept-multiclient Allows a headless server to accept multiple client connections.
--allow-non-terminal-interactive Allows interactive sessions of Delve that don't have a terminal as stdin, stdout and stderr
--api-version int Selects API version when headless. New clients should use v2. Can be reset via RPCServer.SetApiVersion. See Documentation/api/json-rpc/README.md. (default 1)
--backend string Backend selection (see 'dlv help backend'). (default "default")
--build-flags string Build flags, to be passed to the compiler. For example: --build-flags="-tags=integration -mod=vendor -cover -v"
--check-go-version Checks that the version of Go in use is compatible with Delve. (default true)
--disable-aslr Disables address space randomization
--headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "127.0.0.1:0")
--log Enable debugging server logging.
--log-dest string Writes logs to the specified file or file descriptor (see 'dlv help log').
--log-output string Comma separated list of components that should produce debug output (see 'dlv help log')
--only-same-user Only connections from the same user that started this instance of Delve are allowed to connect. (default true)
-r, --redirect stringArray Specifies redirect rules for target process (see 'dlv help redirect')
--wd string Working directory for running the program.
Additional help topics:
dlv backend Help about the --backend flag.
dlv log Help about logging flags.
dlv redirect Help about file redirection.
Use "dlv [command] --help" for more information about a command.
Copy the code
Go to the GO directory
dlv debug
Copy the code
Enter help to get help for the command
Common Debugging Commands
break
To set breakpoints
break main.main
Copy the code
breakpoints
Prints information about the active breakpoint.
continue
Run until the breakpoint or program terminates.
disassemble
Disassembles to display assembly code for the current function plan9
step
Step by step
Execute an expression that prints the current function variable
args
Print function parameters
locals
Print local variables
Refer to the article
Detail Go in the memory allocation source implementation
Detail Go language scheduling loop source implementation