working with debug symbols

Nick Clifton nickc@redhat.com
Wed May 19 11:18:00 GMT 2010


Hi Nikos,

> I am working on a project where, ideally, we would like to be able to
> say for every byte in the .text section of an (ELF or PE) executable,
> whether or not it is part of an instruction or not (i.e. whether it's
> code or data). The executables will be compiled with gcc and debugging
> information. At which granularity can we extract this information from
> the debug symbols?

It depends upon the architecture that you are examining.  For example it 
would normally be reasonable to assume that every byte inside a function 
is part of an instruction, and so given a function's start address and 
its length you can make reasonable estimates as to the location of every 
instruction byte.  But if the compiler for the target architecture 
places constant pools inside functions then the assumption does not hold.

> However, a way to tag each address as
> code or data would be even better.

Have you looked at the ARM port's use of mapping symbols ?  The compiler 
inserts these into the assembler output to indicate a change between 
data and instructions (and between different types of instructions) and 
then tools like the debugger can look for these special symbols to 
determine the nature of any given byte.

> Finally, will any of these break if
> the debug symbols are stored outside the executable?

That should not matter, provided that whatever tool you are creating is 
able to follow the information in the .gnu_debug_link section to the 
external debug information.

Cheers
   Nick



More information about the Binutils mailing list