使用 dlv 调试smartraiden

by 白振轩


对于程序运行过程中碰到的莫名其妙的问题,比如不明原因的阻塞,命令行 dlv 调试可能比 ide 调试效果更好

一 正常启动 smartraiden

./smartraiden --datadir=.smartraiden --api-address=0.0.0.0:5001 --listen-address=127.0.0.1:40001  --address="0x292650fee408320D888e06ed89D938294Ea42f99" --keystore-path ~/privnet3/keystore --registry-contract-address 0xf450955d87F23DF5DFc7297ed6DdDF4fb896Eff2  --password-file 123      --verbosity 5    --debug  --conditionquit "{\"QuitEvent\":\"EventSendRevealSecretBeforex\"}" --debugcrash  --eth-rpc-endpoint ws://127.0.0.1:8546

二 dlv 调试

  1. 出了问题,但是没有崩溃,直接 attach 即可
  2. 出了问题,但是崩溃了,可以提前设置断点

三 dlv attach

attach 成功以后,程序会停止运行

goroutines -s 查看所有 goroutine 的栈

解决问题

  1. 如果觉得某个 goroutine 有问题

    goroutine 108 就可以切换到这个 goroutine, 进行调试
  2. bt 查看堆栈
(dlv) goroutine 108
Switched from 0 to 108 (thread 4644478)
(dlv) bt
0 0x000000000402f66a in runtime.gopark
at /usr/local/go/src/runtime/proc.go:292
1 0x000000000403f150 in runtime.selectgo
at /usr/local/go/src/runtime/select.go:392
2 0x0000000004608329 in github.com/SmartMeshFoundation/SmartRaiden/blockchain.(*Events).startListenEvent.func1
at /Volumes/dev/smdev2/src/github.com/SmartMeshFoundation/SmartRaiden/blockchain/events.go:275
3 0x000000000405c3d1 in runtime.goexit
at /usr/local/go/src/runtime/asm_amd64.s:2361
  1. 在栈之间移动up/down
up
up

会显示当前可以控制的栈

Frame 2: /Volumes/dev/smdev2/src/github.com/SmartMeshFoundation/SmartRaiden/blockchain/events.go:275 (PC: 4608329)
270: go func(name string) {
271: ch := be.LogChannelMap[name]
272: sub := be.Subscribes[name]
273: defer rpanic.PanicRecover(fmt.Sprintf("startListenEvent %s", name))
274: for {
=> 275: select {
276: case l, ok := <-ch:
277: if !ok {
278: //channel closed
279: return
280: }
(dlv)
  1. 查看局部变量

    locals 可以显示目前所有的局部变量,也可以通过p 来打印具体的局部变量和全局变量.
(dlv) p ch
chan github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log {
qcount: 0,
dataqsiz: 10,
buf: *[10]struct github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log [
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc420335500),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc4203355a8),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc420335650),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc4203356f8),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc4203357a0),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc420335848),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc4203358f0),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc420335998),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc420335a40),
(*github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log)(0xc420335ae8),
],
elemsize: 168,
closed: 0,
elemtype: *runtime._type {
size: 168,
ptrdata: 56,
hash: 3390961113,
tflag: tflagUncommon|tflagExtraStar|tflagNamed,
align: 8,
fieldalign: 8,
kind: 25,
alg: *(*runtime.typeAlg)(0x5218c40),
gcdata: *72,
str: 56993,
ptrToThis: 1205856,},
sendx: 0,
recvx: 0,
recvq: waitq<github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log> {
first: *(*sudog<github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log>)(0xc4304ae4e0),
last: *(*sudog<github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log>)(0xc4304ae4e0),},
sendq: waitq<github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log> {
first: *sudog<github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log> nil,
last: *sudog<github.com/SmartMeshFoundation/SmartRaiden/vendor/github.com/ethereum/go-ethereum/core/types.Log> nil,},
lock: runtime.mutex {key: 0},}
(dlv)

可以看到 ch 这个 chann 目前没有任何数据,所以阻塞.

5. 也可以查看全局变量.也就是包级别的变量.

(dlv) p "github.com/SmartMeshFoundation/SmartRaiden/params".MobileMode
false
(dlv) p "github.com/SmartMeshFoundation/SmartRaiden/params".ChainID
*math/big.Int {
neg: false,
abs: math/big.nat len: 1, cap: 5, [8888],}
(dlv)

使用 dlv 调试go 程序的更多相关文章

  1. 在vscode中怎样debug调试go程序

    随着互联网时代的飞速发展,我们编码使用的开发利器也在不断更新换代,古话说工欲善其事必先利其器,对于Java开发者而言,eclipse和idea这两款神器各有千秋,因自己的爱好可以选取不同的IDE,但是 ...

  2. 使用VS+VisualGDB编译调试Linux程序

    Linux程序开发变得越来越多,越来越多的程序.产品需要跨平台,甚至有些开源项目只支持Linux平台,所以掌握Linux开发变得越来越重要. 但是对于习惯了Windows下的开发,使用了VS这个宇宙第 ...

  3. 使用未付费的账号真机调试 iOS 程序,过几天后程序一打开就会闪退

    使用未付费的苹果开发者账号真机调试 iOS 程序,过几天后程序一打开就会闪退.   解决办法: 删除 Provisioning Profile,重新配置一次. 终极解决办法:花钱购买苹果开发者账号. ...

  4. Gdb调试多进程程序

    Gdb调试多进程程序 程序经常使用fork/exec创建多进程程序.多进程程序有自己独立的地址空间,这是多进程调试首要注意的地方.Gdb功能强大,对调试多线程提供很多支持. 方法1:调试多进程最土的办 ...

  5. 利用 PhpStorm、Idea 等 IDE 如何 运行/调试 Go 程序 ?

    以自己常用的 PhpStorm 为例 第一步:下载安装 Go插件 File -> Settings -> Plugins -> 输入关键字:Go 第二步:新建 Go项目 File - ...

  6. PDB调试Python程序

    pdb是python内置的调试工具, 它可以在终端中调试Python程序, 这允许pdb在很多无法安装IDE的服务器上使用. 虽然远程调试使用广泛, 但在必要的时候(比如难以在本地搭建运行环境)pdb ...

  7. VS2010 win7 QT4.8.0,实现VS2010编译调试Qt程序,QtCreator静态发布程序

    下载源代码,注意一定是源码压缩包如qt-everywhere-opensource-src-4.8.0.zip, 不是Qt发布的已编译的不同版本的标准库如qt-win-opensource-4.8.0 ...

  8. 【php】使用gdb调试php程序

    1.简介 GDB是GNU开源组织发布的一个强大的UNIX下的程序调试工具.如果你是在 UNIX平台下做软件,你会发现GDB这个调试工具有比VC.BCB的图形化调试器更强大的功能.同时GDB也具有例如d ...

  9. 使用 GDB 调试多进程程序

    使用 GDB 调试多进程程序 GDB 是 linux 系统上常用的调试工具,本文介绍了使用 GDB 调试多进程程序的几种方法,并对各种方法进行比较. 3 评论 田 强 (tianq@cn.ibm.co ...

随机推荐

  1. Abstract(抽象)

    谈到抽象,就先谈谈面向对象语言的三大特性,也是人们口中常说的封装.继承.多态. 封装:什么是封装,按到我的理解,封装就是把某些类的相关属性和方法封装,对内实现数据影城,对外提供稳定接口. 继承:从字面 ...

  2. iOS学习之WebView的使用

    1.使用UIWebView加载网页 运行XCode 4.3,新建一个Single View Application,命名为WebViewDemo. 2.加载WebView 在ViewControlle ...

  3. C++ new到底new什么

    VS2010-Debug版本 9: int *obj = new int(6); 00F714CE push //压栈 00F714D0 call operator new (0F711EAh) // ...

  4. ASP.NET Web API(C#)学习01

    Web Api 记得去年公司有个分享会分享了这个,最近留意招聘信息的时候,发现有个招聘信息的要求是会用WebApi,然后花了半个小时不到,根据下面这篇文章了解了一下,觉得这个东西也不难啊. 突然发现在 ...

  5. Linux环境下搭建python+selenium+webdriver环境

    1.下载并安装python,一般安装linux系统,自带有python,则python不用安装.要下载可以在官网上下载: 或者使用下面命令安装: sudo apt-get install python ...

  6. 201671010127 2016-2017-18 Java期末总结

    通过本学期Java课程的学习,我对于面向对象的编程语言有了进一步的了解.首先面向对象编程的特点是抽象.封装.继承.多态.由于已经学过c语言,所以对Java的学习实际上是从第四章对向与类开始的,然后学习 ...

  7. rocketmq刷盘过程

     本文基于rocketmq4.0版本,结合CommitlLog的刷盘过程,对消息队列的刷盘过程源码进行分析,进而对RocketMQ的刷盘原理和过程进行了解.   rocketmq 4.0版本中刷盘类型 ...

  8. Avro总结(RPC/序列化)

    Avro(读音类似于[ævrə])是Hadoop的一个子项目,由Hadoop的创始人Doug Cutting(也是Lucene,Nutch等项目的创始人,膜拜)牵头开发,当前最新版本1.3.3.Avr ...

  9. 系统性能信息模块之psutil模块

    一.psutil模块介绍 官方网址:https://pypi.org/ psutil模块安装:https://github.com/giampaolo/psutil/blob/master/INSTA ...

  10. Checked异常和Runtime异常体系

    Java的异常被分为两大类:Checked异常和Runtime异常(运行时异常).所有的RuntimeException类及其子类的实例被称为Runtime异常:不是RuntimeException类 ...