美文网首页
2019-03-08 在ubuntu上调试go-ethereum

2019-03-08 在ubuntu上调试go-ethereum

作者: oracle3 | 来源:发表于2019-03-08 19:42 被阅读0次

    2019-02-26 在ubuntu上调试go-ethereum中,goland无法在ubuntu下调试,但是dlv调试又太复杂,因此参考以太坊 (go-ethereum) 编译调试环境的搭建,搞定了vscode在ubuntu上的调试

    1、安装go插件

    参考golang+VScode安装与配置
    需要安装:

    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")})
    

    相关文章

      网友评论

          本文标题:2019-03-08 在ubuntu上调试go-ethereum

          本文链接:https://www.haomeiwen.com/subject/misdpqtx.html