2019-02-26 在ubuntu上调试go-ethereum

参考2018-11-22 Debug以太坊go-ethereum实战
这个在windows上调试挺方便的,但是放到ubuntu上死活debug出错,goland到底存在啥问题呢,实在找不到原因,就想到一个折中的方法来解决:使用goland启动go-ethereum,然后使用dlv调试,方法如下:

1、用su修改文件,然后重启

使用dlv attach的时候回出现类似下面的错误

Could not attach to process.  If your uid matches the uid of the target process

需要修改文件/etc/sysctl.d/10-ptrace.conf,将此文件下的kernel.yama.ptrace_scope = 1 改为0, 允许普通用户调试。但必须重启生效。

2、goland启动go-ethereum

参考2018-11-22 Debug以太坊go-ethereum实战配置,然后启动,当然如果选择debug一定退出

3、使用dlv调试

启动一个终端,执行ps

ps aux | grep geth
elikong   2504  0.9  4.8 960080 194284 pts/0   Sl+  10:58   0:00 /tmp/___go_build_github_com_ethereum_go_ethereum_cmd_geth --datadir /home/elikong/temp/geth-data0 --networkid 1314 --nodiscover --rpcport 6001 --port 30001 --ipcpath /home/elikong/temp/geth-data0/geth1.ipc console
elikong   2543  0.0  0.0  21536  1036 pts/1    S+   10:59   0:00 grep --color=auto geth

然后使用dlv

dlv attach 2504
Successfully moved config from: /home/elikong/.dlv to: /home/elikong/.config/dlv/config.yml
Type 'help' for list of commands.
(dlv) funcs SendTransaction
github.com/ethereum/go-ethereum/eth.(*peer).AsyncSendTransactions
github.com/ethereum/go-ethereum/eth.(*peer).SendTransactions
github.com/ethereum/go-ethereum/ethclient.(*Client).SendTransaction
github.com/ethereum/go-ethereum/internal/ethapi.(*PrivateAccountAPI).SendTransaction
github.com/ethereum/go-ethereum/internal/ethapi.(*PrivateAccountAPI).SignAndSendTransaction
github.com/ethereum/go-ethereum/internal/ethapi.(*PublicTransactionPoolAPI).SendTransaction
(dlv) b ethapi.(*PublicTransactionPoolAPI).SendTransaction
Breakpoint 1 set at 0xa0a77b for github.com/ethereum/go-ethereum/internal/ethapi.(*PublicTransactionPoolAPI).SendTransaction() ./go/src/github.com/ethereum/go-ethereum/internal/ethapi/api.go:1278
(dlv) c

然后回到goland的run窗口里面输入

personal.unlockAccount(eth.accounts[0])
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(10,"ether")})

回车后,返回到dlv的终端,这个时候看到断点断下来了,剩下的就是参考使用Delve进行Golang代码的调试进行代码调试了

你可能感兴趣的:(2019-02-26 在ubuntu上调试go-ethereum)