tags:

views:

99

answers:

2

Hi All!

I've been trying to make GNU gdb 6.5-14 to use the source code embedded on the object file when debugging, instead of scanning some directories for it.

The main reason is that I develop for an embedded platform and I cross compile, which means that all the source is in my computer.

I read about the -ggdb3 flag, that includes a lot of extra info, including the source code. So I started compiling with that flag.

Doing a objdump -S src/lib/libfoo.so indeed prints out all the source code with the assembly code intermixed with the source code, so I'm guessing that it does indeed contain that info.

The only thing is that GDB does not print it, unless I run from a nfs mounted version of my workspace that contains the source.

Does anyone know how can I instruct gdb to look in the object file for code instead of relying on external files?

+1  A: 

Your guess about what -ggdb3 does is totally incorrect; the object files do not contain the source. You can prove that by running 'strings -a libfoo.so'.

Your best bet is to learn how to use remote debugging -- you can then use GDB from host (which has access to all the sources); with an added advantage that you need much less memory on target. See gdbserver in "info gdb".

Employed Russian
+1  A: 

Employed Russian is correct -- gcc never embeds source code in object files.

What it does do (with any -g setting) is add paths to where the source file can be found.

GDB can use these paths to find the source files. And if you happen to set up the exact same paths on your embedded file system as the paths where you keep your source code on the host system, you can trick gdb into finding them.

Michael Snyder