I have a constraint where I only have/want gdbserver on a little BeagleBone Black that I have. Basically, some process is crashing on it and I'd like to debug with gdb on my host machine.
I want the workflow to be like:
How would I do this?
You can start gdbserver without specifying an executable, so long as you start in "multi" mode, so
$ gdbserver --multi :54321
The 54321
you'd replace with whatever port you actually want to use.
On the GDB side you need to connect using the extended-remote
protocol, like:
(gdb) target extended-remote hostname:54321
Again, replace hostname
with the host gdbserver is running on, and 54321
with the port number used to start gdbserver.
Now, you need to tell gdbserver what executable to start, this is done from the GDB side with:
(gdb) set remote exec-file /path/to/exec
Note, /path/to/exec
is the path on the REMOTE machine, not on the local machine (where GDB is running), this might mean you need to deploy the exec to the remote first.
Next you need to tell GDB which executable you're debugging, it sucks we need to tell GDB the same thing twice, but it is what it is right now, so:
(gdb) file /local/path/to/exec
This path is the path on the local machine, the one where GDB is running. At this point you are free to set breakpoints as needed, just as you would in a native debugging session. When ready you can run
as you'd expect.
A slight adjustment to the above would be to tell GDB that it needs to fetch the file from the remote machine. You should be able to do:
(gdb) file target:/path/to/exec
Notice the target:
prefix, this tell GDB to go look on the remote machine, and /path/to/exec
here is the path on the REMOTE machine. However, I'd usually prefer to copy the file locally myself and then point GDB to the file on the local machine. GDB's copying from remote machines is horribly slow, and the caching is (I think) non-existent, so if you restart your GDB session, or load another executable for any reason, GDB will re-download the file. But in a pinch using target:
paths can help for a quick issue.