Delve进行Golang代码的调试

本文介绍了如何使用Delve这一Golang源代码调试器进行调试。内容包括Delve的概述、常用命令如help、attach、debug等的使用,以及通过core dump文件进行调试的方法。此外,还展示了调试过程中设置断点、查看栈信息和变量值的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Delve进行Golang代码的调试

Delve是托管在Github上的一个开源项目。

项目地址:https://github.com/go-delve/delve

概要

Delve是Go程序的源代码级调试器。

Delve使您可以通过控制进程的执行,评估变量并提供线程/ goroutine状态,CPU寄存器状态等信息来与程序进行交互。

该工具的目的是为调试Go程序提供一个简单而强大的界面。

使用
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.
————————————————————————————————————————————————————————————————————————————————————
  attach      连接到正在运行的流程并开始调试.
  connect     连接到无头调试服务器.
  core        检查核心转储.
  dap		  [EXPERIMENTAL]启动通过调试适配器协议(DAP)进行通信的TCP服务器。
  debug       编译并开始调试当前目录下的主包或指定的包.
  exec        执行预编译的二进制文件,并开始调试会话.
  help        帮助信息
  run         弃用的命令。使用“debug”替代它.
  test        编译测试二进制文件并开始调试程序.
  trace       编译并开始跟踪程序.
  version     打印版本.

使用"dlv [command] --help"获取有关命令的详细信息.

上面列举了dlv的一些命令,其中常用的有如 help、attach、core、debug、trace、version 等。

dlv help:上面的信息只是列出了命令列表,具体使用方法没有给出,这里可以运行 dlv help 查看具体命令的使用方法。也可以运行 dlv help help 查看 help 命令的使用说明。这里以查看 core 命令为例。

Examine a core dump (only supports linux and windows core dumps).

The core command will open the specified core file and the associated
executable and let you examine the state of the process when the
core dump was taken.

Currently supports linux/amd64 and linux/arm64 core files and windows/amd64 minidumps.

Usage:
  dlv core <executable> <core> [flags]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值