Facilitates debugging specific instances of bitcoind in the context of Python tests, inside of an editor/IDE/debugger.
Makes bitcoind spin during startup, waiting for a debugger to be attached, so that breakpoints during process init can be debugged.
Example usage
-
Generate build files with
-DENABLE_WAIT_FOR_DEBUGGER=ON& build.0cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_WAIT_FOR_DEBUGGER=ON && cmake --build build -j$(nproc) -
Set breakpoints in the C++ code in your editor/IDE/debugger.
-
Start a Python functional test with a debugger command such as:
- LLDB inside a Tmux pane (append
-o continueto the LLDB args to have the debugger continue automatically):0./build/test/functional/feature_loadblock.py --debug_runs 2 --debug_cmd "tmux split-window -h lldb -p \$PID\$" - Sublime Text Debugger, allows a running session to attach:
0./build/test/functional/feature_loadblock.py --debug_runs 2 --debug_cmd "subl --command \"debugger {\\\"action\\\": \\\"start\\\", \\\"configuration\\\": {\\\"name\\\": \\\"foo\\\", \\\"type\\\": \\\"lldb\\\", \\\"request\\\": \\\"attach\\\", \\\"program\\\": \\\"dummyprogram\\\", \\\"pid\\\": \\\"\$PID\$\\\"}}\"" - Don’t specify
--debug_cmd ...\$PID\$..., instead have the test framework log which bitcoind PID you should manually attach to:0./build/test/functional/feature_loadblock.py --debug_runs 2
- LLDB inside a Tmux pane (append
-
Experience how debugger hits breakpoints as the functional test executes RPCs.
Using -debug_runs <RUN_INDEX> often requires doing a dry-run of a functional test with -ldebug and examining the log to see which run index is the one we want to debug:
02025-...Z TestFramework.node0 (DEBUG): bitcoind started (run [#1](/bitcoin-bitcoin/1/), node [#0](/bitcoin-bitcoin/0/)), waiting for RPC to come up
Alternative usage
Tweak functional test code to specify wait_for_debugger when (re)starting a node:
0- self.restart_node(0)
1+ self.restart_node(0, wait_for_debugger=True)
While it can be messy to modify files while moving between commits, and cumbersome inside of loops, it might be more straightforward than -debug_runs <RUN_INDEX> in a given case.
Needed before merge
- Testing on Mac to confirm -waitfordebugger on the C++ side behaves as expected.