Sometimes a program will start to misbehave after it has been running for a while and you would like to know what it is doing. The GDB attach
feature does exactly that. I call it just-in-time debugging. It is available with both native and remote debug sessions.
In the case of remote debugging, you need to find the PID of the process to be debugged and pass it to gdbserver with the --attach
option. For example, if the PID is 109 you would type:
# gdbserver --attach :10000 109 Attached; pid = 109 Listening on port 10000
That forces the process to stop as if it were at a breakpoint, allowing you to start your cross GDB in the normal way and connect to gdbserver.
When you are done you can detach, allowing the program to continue running without the debugger:
(gdb) detach Detaching from program: /home/chris/MELP/helloworld/helloworld, process 109 Ending remote debugging.