Delve是Go语言的调试工具

安装

执行如下命令:

go get -u github.com/go-delve/delve/cmd/dlv

查看是否安装成功:

dlv version

如果没有dlv命令,常见问题是由于没有将dlv路径增加到PATH中,默认安装在GOPATH/bin路径下,或通过find命令进行查找确定具体安装路径

find / -name dlv 2>/dev/null

确定完安装路径后,将路径加入PATH中,或者将dlv拷贝到/usr/local/bin目录

PATH=$PATH:$DLV_PATH
或者
cp dlv /usr/local/bin

执行dlv version命令,出现如下情况表示安装成功:

user$ dlv version
Delve Debugger
Version: 1.6.0
Build: $Id: 8cc9751909843dd55a46e8ea2a561544f70db34d $
基本用法

先通过输入dlv或dlv --help来查看支持的命令

$ dlv --help
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 of 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.Pass flags to the program you are debugging using `--`, for example:`dlv exec ./hello -- server --config conf/config.toml`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 commandrun         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.-h, --help                             help for dlv--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.

可以通过描述看出每个dlv command所具有的功能,也可通过dlv [command] --help来查看每个命令所具有的功能。
以dlv exec 有例,来介绍一下常用的调试命令:

$ dlv exec ./main
Type 'help' for list of commands.
(dlv) help
The following commands are available:Running the program:call ------------------------ Resumes process, injecting a function call (EXPERIMENTAL!!!)continue (alias: c) --------- Run until breakpoint or program termination.next (alias: n) ------------- Step over to next source line.rebuild --------------------- Rebuild the target executable and restarts it. It does not work if the executable was not built by delve.restart (alias: r) ---------- Restart process.step (alias: s) ------------- Single step through program.step-instruction (alias: si)  Single step a single cpu instruction.stepout (alias: so) --------- Step out of the current function.Manipulating breakpoints:break (alias: b) ------- Sets a breakpoint.breakpoints (alias: bp)  Print out info for active breakpoints.clear ------------------ Deletes breakpoint.clearall --------------- Deletes multiple breakpoints.condition (alias: cond)  Set breakpoint condition.on --------------------- Executes a command when a breakpoint is hit.trace (alias: t) ------- Set tracepoint.Viewing program variables and memory:args ----------------- Print function arguments.display -------------- Print value of an expression every time the program stops.examinemem (alias: x)  Examine memory:locals --------------- Print local variables.print (alias: p) ----- Evaluate an expression.regs ----------------- Print contents of CPU registers.set ------------------ Changes the value of a variable.vars ----------------- Print package variables.whatis --------------- Prints type of an expression.Listing and switching between threads and goroutines:goroutine (alias: gr) -- Shows or changes current goroutinegoroutines (alias: grs)  List program goroutines.thread (alias: tr) ----- Switch to the specified thread.threads ---------------- Print out info for every traced thread.Viewing the call stack and selecting frames:deferred --------- Executes command in the context of a deferred call.down ------------- Move the current frame down.frame ------------ Set the current frame, or execute command on a different frame.stack (alias: bt)  Print stack trace.up --------------- Move the current frame up.Other commands:config --------------------- Changes configuration parameters.disassemble (alias: disass)  Disassembler.edit (alias: ed) ----------- Open where you are in $DELVE_EDITOR or $EDITORexit (alias: quit | q) ----- Exit the debugger.funcs ---------------------- Print list of functions.help (alias: h) ------------ Prints the help message.libraries ------------------ List loaded dynamic librarieslist (alias: ls | l) ------- Show source code.source --------------------- Executes a file containing a list of delve commandssources -------------------- Print list of source files.types ---------------------- Print list of typesType help followed by a command for full documentation.
(dlv)

从调试命令上看,dlv的调试命令和gdb相似,如果对于gdb调试比较熟悉,对于dlv也会比较容易上手,例如常用的命令及缩写:step(s)、continue©、break(b)。
调试工具,需要经常使用才会越用越熟,只看一些用法对于提高调试水平有限。

Go语言Delve调试相关推荐

  1. mac pro下安装gdb和delve调试器

    2019独角兽企业重金招聘Python工程师标准>>> 我用liteide进行go环境的配置,最近升级以后发现两个调试器都不能debug代码 了,主要原因有两个.一个是软件签名问题和 ...

  2. Python语言学习:python语言代码调试—异常处理之详细攻略

    Python语言学习:python语言代码调试-异常处理之详细攻略 目录 python语言代码调试-异常处理 异常捕捉可以使用 try/except 语句 相关文章 Python3 错误和异常 | 菜 ...

  3. 是否要运行此应用程序_使用Delve调试Go应用程序

    调试器 任何编程语言中最简单的调试形式是使用打印语句或日志来写入标准输出.这肯定没有问题,但是当我们的应用程序规模增加并且逻辑变得更加复杂时,这种方式变得极其困难.将打印语句添加到应用程序的每个代码路 ...

  4. C语言gdb调试之精髓 | gdb调试多线程

    C语言gdb调试之精髓(常用命令.多进程.多线程.程序日志) 起语: 版权声明: C语言技术网原创文章,转载请说明文章的来源.作者和原文的链接. 来源:C语言技术网(www.freecplus.net ...

  5. C语言入门(21)——使用DBG对C语言进行调试

    C语言入门(21)--使用DBG对C语言进行调试 程序中除了一目了然的Bug之外都需要一定的调试手段来分析到底错在哪.到目前为止我们的调试手段只有一种:根据程序执行时的出错现象假设错误原因,然后在代码 ...

  6. vscode配置C语言编译调试的方法

    一. 安装GCC 官方下载 如果你能从在线安装,那最好就在线安装吧.不过在线安装太容易中断失败了.如果你能连上官网,也可以选择从官网去下载离线安装包. https://sourceforge.net/ ...

  7. 使用Delve调试Go应用程序

    需要调试器 任何编程语言中最简单的调试形式是使用打印语句/日志并写入标准输出.这肯定可以工作,但是当我们的应用程序规模增加并且逻辑变得更加复杂时,它变得极其困难.将打印语句添加到应用程序的每个代码路径 ...

  8. C语言之调试技巧(VS2019编译器)

    C语言之调试技巧(VS2019编译器) 一.什么是调试?调试的作用 1.1 什么是调试 1.2 调试的基本步骤 1.3 Debug版本和Release版本的介绍 二.Windows环境调试的准备 2. ...

  9. C语言入门调试与思维

    C语言入门调试与思维 刚开始我作为一个C语言编译小白,对程序的书写和运行难以上手,初始阶段期间看了很多程序员路上的感想,也对程序这个行业有大致的了解,感到很新颖,很适合我的一个基础语言系,我用一学期来 ...

最新文章

  1. DDD领域驱动设计之聚合、实体、值对象
  2. 人大团队研究:面向文本生成,预训练模型进展梳理
  3. Python模拟赌博实验,赌博为什么能赌到倾家荡产?
  4. 远程挂载 NFS 共享目录引发死机问题
  5. 数据派新年寄语 | 新时代,新年好!
  6. 使用Slf4j集成Log4j2构建项目日志系统的完美解决方案
  7. OpenReports中文支持方案
  8. WinSock I/O 模型 -- OVERLAPPED I/O 模型
  9. 语音识别技术分析:语音变成文字其实没有那么神秘
  10. 【重点 递归构造二叉树】LeetCode 95. Unique Binary Search Trees II
  11. 如何在 Mac 上修复丢失的鼠标?
  12. poj Fibonacci(快速幂取模运算)
  13. android即时通信表情特效,微信英文代码表情特效-微信英文代码表情翻译特效大全v1.0 安卓版预约_飞翔下载...
  14. 分块矩阵乘法以及求逆应用
  15. 新浪微博热门话题(字符串处理)
  16. Premature end of Content-Length delimited message body解决方案
  17. 外卖骑手,巨头的炮灰
  18. c语言求圆的周长和面积
  19. Python Keras ValueError: Layer sequential expects 1 input(s), but it received 2 input tensors. 解决方法
  20. GAN网络详解(从零入门)

热门文章

  1. Catia 零件 曲面 装配 工程图 仿真运动 参数和知识工程视频教程
  2. 分析非学历培训管理系统系统架构及功能
  3. 怎样确保国际会议论文能被EI/ISTP等检索
  4. 一堂计算机课,“星愿”第一堂电脑实操课
  5. Python 之 matplotlib plt.rcParams[]
  6. [手机分享]黑莓手机9系列分享之——黑莓9500
  7. 思科模拟器安装与登录:Cisco packet tracer 7.3登录问题解决
  8. 快手永久封禁还能解开吗
  9. go 学习笔记之有意思的变量和不安分的常量
  10. windows当服务器不稳定,windows7网速不稳定上网总是断断续续的几种原因和解决方法...