用法
2 分钟阅读
原文:https://github.com/go-delve/delve/blob/master/Documentation/usage/README.md
收录该文档时间:
2024-12-09T08:04:37+08:00
Using Delve
You can invoke Delve in multiple ways, depending on your usage needs. Delve makes every attempt to be user-friendly, ensuring the user has to do the least amount of work possible to begin debugging their program.
 您可以根据需要通过多种方式调用 Delve。Delve 力求为用户提供便利,确保用户以最少的操作即可开始调试程序。
The available commands can be grouped into the following categories:
 可用命令可分为以下几类:
- Specify target and start debugging with the default terminal interface: 指定目标并通过默认的终端界面开始调试:
- Trace target program execution 跟踪目标程序执行:
- Start a headless backend server only and connect with an external frontend client: 仅启动无界面后端服务器并通过外部前端客户端连接:- dlv –headless <command> <target> <args>- starts a server, enters a debug session for the specified target and waits to accept a client connection over JSON-RPC or DAP 启动服务器,进入指定目标的调试会话,并通过 JSON-RPC 或 DAP 等待客户端连接
- <command>can be any of- debug,- test,- exec,- attach,- coreor- replay
- if --headlessflag is not specified the default terminal client will be automatically started instead 如果未指定--headless标志,将自动启动默认的终端客户端
- compatible with dlv connect, VS Code Go, GoLand 兼容 dlv connect、VS Code Go、GoLand
 
- dlv dap- starts a DAP-only server and waits for a DAP client connection to specify the target and arguments 启动仅支持 DAP 的服务器,并等待 DAP 客户端连接以指定目标和参数
- compatible with VS Code Go 兼容 VS Code Go
- NOT compatible with dlv connect, GoLand 不兼容 dlv connect、GoLand
 
- dlv connect <addr>- starts a terminal interface client and connects it to a running headless server over JSON-RPC 启动终端界面客户端并通过 JSON-RPC 连接到运行中的无界面服务器
 
 
- dlv –headless <command> <target> <args>
- Help information 帮助信息:
The above list may be incomplete. Refer to the auto-generated complete usage document to further explore all available commands.
 上述列表可能不完整。请参阅自动生成的完整使用文档以进一步探索所有可用命令。
环境变量 Environment variables
Delve also reads the following environment variables:
 Delve 还会读取以下环境变量:
- $DELVE_EDITORis used by the- editcommand (if it isn’t set the- $EDITORvariable is used instead)- $DELVE_EDITOR由- edit命令使用(如果未设置,则使用- $EDITOR变量)
 
- $DELVE_PAGERis used by commands that emit large output (if it isn’t set the- $PAGERvariable is used instead, if neither is set- moreis used)- $DELVE_PAGER由输出大量内容的命令使用(如果未设置,则使用- $PAGER变量,如果两者都未设置,则使用- more)
 
- $TERMis used to decide whether or not ANSI escape codes should be used for colorized output- $TERM用于决定是否使用 ANSI 转义码来输出带颜色的内容
 
- $DELVE_DEBUGSERVER_PATHis used to locate the debugserver executable on macOS- $DELVE_DEBUGSERVER_PATH用于在 macOS 上定位 debugserver 可执行文件