Say I am writing and compiling a program with user alice. The program is then run by user bob on the same machine, but from a location that alice cannot access.
alice@localhost:/home/alice$ g++ helloworld.cpp -o helloworld -g
bob@localhost:/home/bob$ cp ../alice/helloworld .
bob@localhost:/home/bob$ ./helloworld
Now, alice wants to debug what bob is doing. Out of the box, this is not possible:
alice@localhost:/home/alice$ pidof helloworld
1234
alice@localhost:/home/alice$ gdb
[...]
(gdb) attach <pidof helloworld>
Attaching to process 1234
ptrace: Operation not permitted.
What should Alice do?
Remote debugging
Alice and Bob should use remote debugging. Bob starts gdbserver with specifying the port (in this example port 2345) …
a) to run the program
or
b) to connect to the running process (in this case with the example PID 133245)
And Alice connects to it:
Remote debugging with absolute paths
This works in this simple case. However, some more sophistication is required when Bob uses absolute paths for his shared libraries:
Now, alice can’t find the shared library:
To solve this, Alice creates a virtual root folder with links to its on binaries:
And is now able to debug with all symbols loaded:
As an alternative with reasonable new GDB versions Alice connects with
and by default GDB will load all the necessary symbols from the server.