<p>As Nate Eldrige commented:</p>
<blockquote>
<p>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</p>
<p>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).</p>
</blockquote>

CC BY-SA 4.0
2018-08-17T14:54:05.773Z
2018-08-17T14:54:05.773Z
2020-06-16T11:10:03.350Z
RedGrittyBrick
<p>If you are on MacOS this <a href="https://github.com/fjahr/debugging_bitcoin" rel="nofollow noreferrer">document</a> might be useful from Fabian Jahr. He recommends using lldb rather than gdb if you are on MacOS.</p>

CC BY-SA 4.0
2020-08-21T12:46:09.260Z
2020-08-21T12:46:09.260Z
Michael Folkson
<p>How do you attach a gdb to a bitcoind daemon. I wish to step through the functions. Here is what i have tried.</p>

<pre><code>gdb --args bitcoind -regtest -daemon
</code></pre>

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

<pre><code>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...    
</code></pre>

<p>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.</p>

<p>Thanks.</p>

CC BY-SA 3.0
2017-02-18T22:59:32.057Z
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
CC BY-SA 3.0
2017-02-18T23:07:20.107Z
@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
CC BY-SA 3.0
2017-02-18T23:09:40.567Z
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
<bitcoind><bitcoin-core-development><debugging>
Debugging bitcoind
Bobo
# Debugging bitcoind

(Asked by: username_0 on 2017-02-18)

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.

**Tags:** bitcoind, bitcoin-core-development, debugging

> **Comments:**
> **username_1**: 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.  
> **username_0**: @username_1 : 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.  
> **username_1**: 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`).  

---

## 2 answers

### Answer by username_2 on 2018-08-17. Score: 1

As username_1 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).


---

### Answer by username_3 on 2020-08-21. Score: 0

If you are on MacOS this [document](https://github.com/fjahr/debugging_bitcoin) might be useful from Fabian Jahr. He recommends using lldb rather than gdb if you are on MacOS.


---

