Hi Guest

More contents, please log on!

Bitmere.com 区块链技术 Content

VS code 调试 bitcoin core

华胥
56 0 0
使用 VS code 调试代码相比原生的gdb调试代码会带来一些好处:
更方便的监测变量值变化更方便的翻阅当前执行代码所在文件

就是设置会稍微麻烦一些。
步骤 1:安装调试插件
VS code 默认只支持 node.js 语言的调试,其他语言的调试需要安装插件。

搜索 C++,安装插件。不过要注意的是,插件本身并不具备编译、调试的能力,需要另外使用软件进行编译、调试[1]。

步骤2:配置
调试前需要手动配置launch.json文件指定调试入口,点击 Open Configurations开始配置:

配置VS code配置文件:
  1. {
  2.     // Use IntelliSense to learn about possible attributes.
  3.     // Hover to view descriptions of existing attributes.
  4.     // For more information, visit: <a href="https://go.microsoft.com/fwlink/?linkid=830387" target="_blank">https://go.microsoft.com/fwlink/?linkid=830387</a>
  5.     "version": "0.2.0",
  6.     "configurations": [
  7.         {
  8.             "name": "(gdb) Launch",
  9.             "type": "cppdbg",
  10.             "request": "launch",
  11.             "program": "${workspaceFolder}/src/bitcoind",
  12.             "args": ["-regtest"],
  13.             "stopAtEntry": false,
  14.             "cwd": "${workspaceFolder}",
  15.             "environment": [],
  16.             "externalConsole": true,
  17.             "MIMode": "gdb",
  18.             "setupCommands": [
  19.                 {
  20.                     "description": "Enable pretty-printing for gdb",
  21.                     "text": "-enable-pretty-printing",
  22.                     "ignoreFailures": true
  23.                 }
  24.             ]
  25.         }
  26.     ]
  27. }
Copy the Code

配置文件的路径为 ./vscode/launch.json
json文件中各个参数的含义:
program:程序编译后得到的可执行文件,即调试的入口args:可执行文件的参数,以上图中指定-regtest为例name: 配置的名称,在左侧调试框可以选择使用哪个配置

步骤 3:编译
调试前需要先将程序编译到上述设置的指定位置,可以在命令行启动编译。也可以通过配置.vscode/tasks.json文件设置任务,在 VS code 内启动编译程序[2][3].
bitcoin core 的编译命令[4],注意添加给 configure 添加参数 --enable-debug[5]:
    cd bitcoin/
    ./autogen.sh
    ./configure --disable-wallet --without-gui --without-miniupnpc --enable-debug
    make check
由于在 macOS 环境下编译失败,在 Debian 环境下编译成功了,下面以 Debian 环境示范。
步骤四:开始调试
点击行号左侧设置断点:

点击左侧调试工具栏的“开始”按钮,或者按 F5 快捷键,开始调试:

点击屏幕上方的 step into 运行下一步:


20190526更新:
macOS 环境下编译成功了,只是执行失败了。原因是vscode 调试时会在 shell 运行命令:
arch -arch x86_64 '/Users/yushengzhou/.vscode/extensions/ms-vscode.cpptools-0.23.1/debugAdapters/lldb/bin/lldb-launcher' --unix-socket=/tmp/61Ab3Q --arch=x86_64 --working-dir '/Users/yushengzhou/code/bitcoin' --disable-aslr --  '/Users/yushengzhou/code/bitcoin/src/bitcoind' '' ; echo Process exited with status $? ; exit
这个用的是 bash 的语法,而我默认用的是 shell 是 fish。因为语法的不兼容而造成运行失败,只需要将 shell 换成 bash 即可。


BitMere.com is Information release platform,just provides information storage space services.
The opinions expressed are solely those of the author,Does not constitute advice, please treat with caution.
You have to log in before you can reply Login | 立即注册

Points Rules

Write the first review

华胥 初中生
  • Follow

    0

  • Following

    0

  • Articles

    13

Promoted