Linux command
dlv 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Debug an executable
dlv exec [./binary]
Debug with arguments
dlv exec [./binary] -- [arg1] [arg2]
Debug a Go package
dlv debug [package]
Attach to process
dlv attach [pid]
Debug a test
dlv test [package]
Start headless server
dlv debug --headless --listen=:[2345]
Connect to remote
dlv connect [localhost:2345]
说明
dlv (Delve) is a debugger for the Go programming language. It provides source-level debugging with support for goroutines, breakpoints, variable inspection, and expression evaluation. Delve understands Go's runtime, correctly handling goroutine scheduling, garbage collection, and other Go-specific features. It supports both local debugging and remote debugging through its headless mode. The debugger integrates with editors and IDEs via the Debug Adapter Protocol (DAP), enabling graphical debugging in VS Code, GoLand, and other editors.
参数
- debug _PACKAGE_
- Build and debug Go package.
- exec _BINARY_
- Debug prebuilt binary.
- test _PACKAGE_
- Debug tests.
- attach _PID_
- Attach to running process.
- connect _ADDR_
- Connect to headless server.
- --headless
- Run in headless mode.
- --listen _ADDR_
- Listen address for headless mode.
- --help
- Display help information.
FAQ
What is the dlv command used for?
dlv (Delve) is a debugger for the Go programming language. It provides source-level debugging with support for goroutines, breakpoints, variable inspection, and expression evaluation. Delve understands Go's runtime, correctly handling goroutine scheduling, garbage collection, and other Go-specific features. It supports both local debugging and remote debugging through its headless mode. The debugger integrates with editors and IDEs via the Debug Adapter Protocol (DAP), enabling graphical debugging in VS Code, GoLand, and other editors.
How do I run a basic dlv example?
Run `dlv exec [./binary]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does debug _PACKAGE_ do in dlv?
Build and debug Go package.