前置要求

dlv调试要求可执行文件不能删掉调试信息,即-ldflags参数中不能包含 -w -s标志。可以使用如下方式查看可执行文件是否有删除调试信息,"not stripped"表示没有删除调试信息

# file alert-sd-engine
alert-sd-engine: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

使用方式

使用funcs查找支持的函数

使用funcs可以打印可以查看调试的函数。可以在后面加上函数的名字或部分名字可以检索出支持的函数,如:

(dlv) funcs VmSvc
devops/alert-sd-engine/pkg.(*Monitor).createVmSvcScrape
devops/alert-sd-engine/pkg.(*Monitor).deleteVmSvcScrape
devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape
devops/alert-sd-engine/pkg.(*Monitor).isVmSvcScrapeExist
devops/alert-sd-engine/pkg.(*Monitor).updateVmSvcScrape
devops/alert-sd-engine/pkg.createVmSvcScrape
devops/alert-sd-engine/pkg.deleteVmSvcScrape
devops/alert-sd-engine/pkg.getVmSvcScrape
devops/alert-sd-engine/pkg.updateVmSvcScrape

使用break(b)打断点

根据funcs找到的函数,使用break在需要的函数上打断点

(dlv) break devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape

当然也可以使用如下方式将断点打到文件的某一行

(dlv) b engine.go:196

使用breakpoints查看当前活动的断点。

(dlv) breakpoints
Breakpoint runtime-fatal-throw (enabled) at 0x4345e0 for runtime.throw() /usr/local/go/src/runtime/panic.go:1188 (0)
Breakpoint unrecovered-panic (enabled) at 0x434940 for runtime.fatalpanic() /usr/local/go/src/runtime/panic.go:1271 (0)
print runtime.curg._panic.arg
Breakpoint 2 (enabled) at 0x1399452 for devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape() .alert-sd-engine/pkg/engine.go:195 (0)
Breakpoint 4 (enabled) at 0x1399479 for devops/alert-sd-engine/pkg.(*Monitor).getVmSvcScrape() ./alert-sd-engine/pkg/engine.go:196 (0)

使用clear清除断点

使用clear 清除某个断电

使用clearall可以清除所有断点

使用goroutines查看所有协程

(dlv) goroutines
Goroutine 1 - User: /usr/local/go/src/net/fd_unix.go:173 net.(*netFD).accept (0x5f4f55) [IO wait]
Goroutine 2 - User: /usr/local/go/src/runtime/proc.go:367 runtime.gopark (0x4370f6) [force gc (idle) 455958h37m56.413188346s]
Goroutine 3 - User: /usr/local/go/src/runtime/proc.go:367 runtime.gopark (0x4370f6) [GC sweep wait]
Goroutine 4 - User: /usr/local/go/src/runtime/proc.go:367 runtime.gopark (0x4370f6) [GC scavenge wait]

使用goroutine 可以切换goroutine

使用stack(bt)查看goroutine的栈信息

(dlv) goroutine 1 stack
0 0x00000000004370f6 in runtime.gopark
at /usr/local/go/src/runtime/proc.go:367
1 0x000000000042f7fe in runtime.netpollblock
at /usr/local/go/src/runtime/netpoll.go:445
2 0x000000000045efa9 in internal/poll.runtime_pollWait
at /usr/local/go/src/runtime/netpoll.go:229

使用frame可以设置当前栈位置,使用up可以向上移动栈,使用down可以向下移动栈

使用attach连接到正在运行的进程

使用attach 可以连接到正在运行的进程

使用locals打印当前的局部遍历,使用-v可以打印更详细的信息

(dlv) locals -v req
req = devops/alert-sd-engine/pkg.Req {
Base: devops/alert-sd-engine/pkg.commData {
Env: 0,
ClusterName: "",
DualActive: false,
Namespace: "",
Name: "",
Endpoints: []devops/alert-sd-engine/pkg.Endpoint len: 0, cap: 0, nil,},
Selector: struct { Appid string "json:\"appId,omitempty\"" } {Appid: ""},}

更多参见官方文档

使用delve调试golang的更多相关文章

  1. Golang 在mac上用VSCode开发、Delve调试

    本文包含以下内容: 1.安装VSCode: 2.用Delve调试Go项目: 3.自定义代码片段: 1.安装VSCode 先去下载VSCode,这个链接里面也有官方文档. 安装插件: vscode-ic ...

  2. mac下配置gdb调试golang

    mac下配置gdb调试golang 原文链接 https://sourceware.org/gdb/wiki/BuildingOnDarwin Building GDB for Darwin Crea ...

  3. 在MacOS上使用gdb(cgdb)调试Golang程序

    如果你在MacOS上使用GDB工具载入Golang程序时无法载入,这篇文章可以解决.本文不具体介绍调试的方法,网上的文章太多了就不赘述了. cgdb使用的是gdb的内核,方法和原理试用本文. 问题分析 ...

  4. VS Code 调试 Golang 出现 Failed to continue: Check the debug console for details

    VS Code断点调试Golang时候,弹出提示:Failed to continue: Check the debug console for details 点击Open launch.json, ...

  5. 使用Delve进行Golang代码的调试

    问题 安装好vscode编辑项目,出现以下错误: Failed to continue: "Cannot find Delve debugger. Ensure it is in your ...

  6. vscode调试golang环境搭建及配置

    准备VSCode 在官网下载最新版的VSCode: 安装Golang插件 打开扩展面板 VSCode->查看->扩展 找到Go插件 在搜索框里输入Go, 找到第二行写有 Rich Go l ...

  7. 使用 pprof 和 Flame-Graph 调试 Golang 应用

    前言 最近用 Golang 实现了一个日志搜集上报程序(内部称 logger 项目),线上灰度测试过程发现 logger 占用 CPU 非常高(80% - 100%).而此项目之前就在线上使用,用于消 ...

  8. VS Code调试Golang提示Failed to continue:Check the debug console for details.

    解决方法: 打开调试面板  VSCode->查看->调试 添加调试目标 在"没有调试"的下拉框中点击"添加配置.."添加目标调试配置 在" ...

  9. 解决windows配置visual studio code调试golang环境问题

    写这篇随笔是为了Mark下在这个过程中配到的几个问题 1.具体过程可参考https://www.cnblogs.com/JerryNo1/p/5412864.html,Jerry博主写的非常详细了 1 ...

随机推荐

  1. 2.9 go mod 之本地仓库搭建

    wikihttps://github.com/golang/go/wiki/Modules#how-to-prepare-for-a-release参考https://blog.csdn.net/be ...

  2. centos7.4 64位安装 redis-4.0.0

    1.  下载 redis 包 链接:https://pan.baidu.com/s/1g1UE_GTreXoD9uOXB7G3HA 提取码:ug8p 2. 安装gcc.ruby .rubygems等环 ...

  3. SQL错误总结

    ORA-00918: column ambiguously defined 异常原因: select 查询的字段在from的两张表中都存在,导致数据库无法区别需要查询的字段来自于哪张表 以下是例子 s ...

  4. 机器学习——可视化绘图matplotlib和seaborn

    安装matplotlib和seaborn https://blog.csdn.net/Jia_jinjin/article/details/80428598 seaborn pairplot:特征两两 ...

  5. DP笔记

    这是一篇蒟蒻被大佬踩爆后写的笔记 套路 0.贪心(废话)(排序...) 1.dp预处理出要用的东西 2.两头同时dp 3.化简题目中本质相同的东西 转化模型 4.数学计算优化 5.分析题目数据考虑该从 ...

  6. Tableau如何绘制堆叠柱状图

    一.将类别,子类别拖拽至列上 二.将度量值拖拽至行上 三.将度量名称拖拽至筛选器上,右键度量名称,编辑筛选器,选择销售额 四.将事先准备的目标销售额拖拽至度量值 五.将度量名称拖拽至标记,分别以颜色和 ...

  7. Go语言核心36讲(Go语言实战与应用二十七)--学习笔记

    49 | 程序性能分析基础(下) 在上一篇文章中,我们围绕着"怎样让程序对 CPU 概要信息进行采样"这一问题进行了探讨,今天,我们再来一起看看它的拓展问题. 知识扩展 问题 1: ...

  8. re正则表达式:import re ;re.search()

    http://www.cnblogs.com/alex3714/articles/5161349.html re模块 常用正则表达式符号 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...

  9. 出现此错误An association from the table refers to an unmapped class

    出现此错误An association from the table refers to an unmapped class,怎么解决: 把Diaocha.hbm.xml文件路径加入到applicat ...

  10. MAVEN项目打包报错:Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on pr ...