2019-03-08 在ubuntu上除錯go-ethereum(2)
在2019-02-26 在ubuntu上除錯go-ethereum 中,goland無法在ubuntu下除錯,但是dlv除錯又太複雜,因此參考以太坊 (go-ethereum) 編譯除錯環境的搭建 ,搞定了vscode在ubuntu上的除錯
1、安裝go外掛
需要安裝:
go get -u -v github.com/nsf/gocode go get -u -v github.com/rogpeppe/godef go get -u -v github.com/golang/lint/golint go get -u -v github.com/lukehoban/go-outline go get -u -v sourcegraph.com/sqs/goreturns go get -u -v golang.org/x/tools/cmd/gorename go get -u -v github.com/tpng/gopkgs go get -u -v github.com/newhook/go-symbols go get -u -v golang.org/x/tools/cmd/guru go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv
2、配置vscode
檔案launch.json內容如下:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/bin/geth", "args": ["--datadir", "/home/elikong/go/src/github.com/ethereum/go-ethereum/build/bin/geth-data0", "--networkid", "1314", "--nodiscover", "--rpcport", "6001", "--port", "30001", "--ipcpath", "geth1.ipc", "console"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
主要是在自動生成的檔案上修改了program和args引數
3、除錯
使用ctrl+p開啟檔案ethapi\api.go,找到函式func (s *PublicTransactionPoolAPI) SendTransaction
在函式第一行設定斷點
參考2018-11-22 Debug以太坊go-ethereum實戰 除錯轉賬
./geth attach ./geth-data0/geth1.ipc miner.start() personal.unlockAccount(eth.accounts[0]) eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(10,"ether")})