3

How do you attach a gdb to a bitcoind daemon. I wish to step through the functions. Here is what i have tried.

gdb --args bitcoind -regtest -daemon

This however exists when the daemon starts. So i tried attaching via the pid after the fork.

gdb -p 841
(gdb) file /usr/local/bin/bitcoind
Reading symbols from /usr/local/bin/bitcoind...done.
(gdb) b sendtoaddress
Breakpoint 1 at 0x4b4d34: file wallet/rpcwallet.cpp, line 379.    
r
starting program...    

This however does not work , when i invoke a transaction using the bitcoin-cli client. Is there anything i am missing. I have used --enable debug on configure.

Thanks.

  • Try gdb /path/to/bitcoind and then attach 841. However, what OS are you on? Some don't allow normal users to attach debuggers to running processes; you would have to be root. Don't use r when attaching to a running process; that starts it over. – Nate Eldredge Feb 18 '17 at 22:59
  • @NateEldredge : Cheers, it worked when i was root. Strangely ,i had to hit n on the console for the trace to begin. Apologies for ninja, trying a few things. – Bobo Feb 18 '17 at 23:07
  • It isn't strange. Using attach (or -p) simply stops the process wherever it is and lets you inspect its state (e.g. where, print, ...), set breakpoints, modify its memory if you wish. When you want the process to do any further execution you have to issue an appropriate command (n,s,c). – Nate Eldredge Feb 18 '17 at 23:09
0

As Nate Eldrige commented:

Try gdb /path/to/bitcoind and then attach 841. However, what OS are you on? Some don't allow normal users to attach debuggers to running processes; you would have to be root. Don't use r when attaching to a running process; that starts it over

Using attach (or -p) simply stops the process wherever it is and lets you inspect its state (e.g. where, print, ...), set breakpoints, modify its memory if you wish. When you want the process to do any further execution you have to issue an appropriate command (n,s,c).

0

If you are on MacOS this document might be useful from Fabian Jahr. He recommends using lldb rather than gdb if you are on MacOS.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.