-
Notifications
You must be signed in to change notification settings - Fork 38.7k
qa: Facilitate debugging bitcoind inside functional tests #31723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31723. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Can you explain more? If you want to run under a debugger, then why not just start |
Clarified PR description text and added example usage. But I'm curious to hear other ways of doing the same thing if there are any. |
|
I think if you want to debug the start-up sequence specifically, it may be easier to do it outside the tests? Then anything else, if needed, can happen without patching Bitcoin Core source code itself. |
This is not about debugging the start-up sequence specifically, but rather debugging from an early stage. Maybe one has set 5 breakpoints, some of which are hit during bitcoind init, and some which are hit by re-running a Python test which calls a set of RPCs. |
|
Ideally we wouldn't be adding debug code, to production binaries, to facilitate using an IDE. Can you configure your IDE to do something like the equivalent of using |
Agree it should not be in production binaries, should be
I've never seen something like that in an IDE/editor, but I'll have a look, might exist a debugger console which allows that kind of thing. This PR does however allow for attaching to a specific node instance of bitcoind if a Python tests runs several nodes at once. (I'm considering changing the index to refer to how many bitcoind-launches one has done, some tests just relaunch node 0 a bunch of times, and one might be interested in debugging it on the 3rd execution Edit: this is now implemented). |
7d181da to
7dd8609
Compare
|
Added tentative |
7dd8609 to
a1da3bf
Compare
|
I'd still say it is easier to debug the init sequence separately than to start a new build with a new build flag for the edge case where someone wants to debug both in an IDE and also the init sequence , but no strong opinion. |
|
fanquake:
The only debugging console I get with the IDE states "No Active Debug Session" when I try to input commands. :( maflcko:
Maybe part of this is down to me not getting used to using a Python debugger, breaking in Python at appropriate times and then attaching a C++ debugger to the new process. Being able to specify which bitcoind-executions one wants to debug still seems like a smoother workflow when testing the same scenario repeatedly. I recently used a version of this PR when digging into #31734. Being able to step through the code (with a panel for inspecting local variables and watches), as the Python test framework is issuing RPCs, in the safety of one's IDE, is nice. Knowing that bitcoind has not passed through one's breakpoints (unless there's some rare static initialization going on) helps build certainty about what unfamiliar code is involved in. Granted, using |
a1da3bf to
191dfc4
Compare
8c99eab to
56439ef
Compare
hodlinator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest push adds a functional test and breaks apart commits somewhat.
CMakeLists.txt
Outdated
| @@ -120,6 +120,7 @@ cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TE | |||
| option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF) | |||
| option(WERROR "Treat compiler warnings as errors." OFF) | |||
| option(WITH_CCACHE "Attempt to use ccache for compiling." ON) | |||
| option(WAIT_FOR_DEBUGGER "Support for waiting during startup for debugger to be attached." OFF) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me there's a silent, implied, "Enables ..." or "Provides ..." at the beginning of the description for these options that would get repetitive if spelled out, which may make "support" more natural.
Note that simply enabling the option does not pause startup, one also has to start with -waitfordebugger.
Curious to hear what other reviewers think.
e785b47 to
d1a50b1
Compare
d1a50b1 to
57df47a
Compare
57df47a to
9d1de2e
Compare
|
Latest push adds 9d1de2e8b3c73edc44bb3f7578ec96c2b91c2dd8 to support modifying a functional test to make a specific node (re)start trigger attaching of a debugger. This may be a more natural alternative when humans read through functional test code and want to select a specific node instance to debug. (It also removes a header which caused a build failure on Alpine/musl, and adds helpful details in 2 commit messages). There has been some feedback to see if we could avoid changing the functional test framework and move most of this feature to /contrib/, so I might try to figure out alternative approaches. |
9d1de2e to
f352bd9
Compare
fb9d0e6 to
f021644
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
Changes compared to f352bd9d246b20579b9b4ccec366bb694df5e051:
|
Verifies that debugging bitcoind is not allowed by default on Linux, at least in sane environments.
Makes bitcoind spin during startup, waiting for a debugger to be attached. Once a debugger is detected, execution will continue.
Useful for debugging one or several bitcoind nodes running in the context of a functional test. You can run a test with -ldebug once first to get output with run#s to see which you are interested in.
Enables automated attaching of debuggers.
The special identifier "$PID$" is substituted by the actual bitcoind process id number.
Attaching with LLDB in Tmux pane:
$ ./build/test/functional/feature_loadblock.py --debug_runs 2 --debug_cmd "tmux split-window -h lldb -p \$PID\$"
Attaching with Sublime Text Debugger:
$ ./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\$\\\"}}\""
Enables tweaking functional tests to start debugging a specific node run/execution.
f021644 to
42db717
Compare
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.Set breakpoints in the C++ code in your editor/IDE/debugger.
Start a Python functional test with a debugger command such as:
-o continueto the LLDB args to have the debugger continue automatically):--debug_cmd ...\$PID\$..., instead have the test framework log which bitcoind PID you should manually attach to: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-ldebugand examining the log to see which run index is the one we want to debug:Alternative usage
Tweak functional test code to specify
wait_for_debuggerwhen (re)starting a node: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