PDBs on Linux
On Windows, debugger symbols aren’t stored side-by-side with the executable data in the same file. They’re stored in a .pdb file (short for “program database”). This is especially great if you distribute your program to end-users, but still want to be able to debug any crashes. Just keep the .pdb file somewhere save, and any crash log you get send can easily translated back into source locations.
On Linux, debug symbols are traditionally stored inside the executable, and stripped (using strip(1)) before distributing. This takes away the possibility to debug any crash, send to you from the stripped executable.
Today I discovered a neat little trick to create something resembling PDBs on Linux, by making use of objcopy(1). In our example, I already have compiled an executable a.out, which I want to distribute to my users:
As we can see, the executable, with debug symbols, has a size of 30k.
Now we extract the debug symbols into another file, using objcopy(1):
As we can now see, our debug symbols are extracted and removed from a.out:
If we now want to debug a.out, however, gdb(1) is telling us it’s missing debug information:
)
We need to attach the .pdb symbols to a.out. This can be achieved by making use of GNUs .gnu_debuglink directives:
To confirm it’s working, we start gdb(1), to see whether it can now pick up any symbols:
Lovely! Our a.out can now be distributed & debugged with external symbols.
Summary