This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: BFD for stack trace


On 12 Apr 2000, Ian Lance Taylor wrote:

>    The BFD documentation, as we all know, if far, far from
>    complete.  Specifically, there is no information on
>    how to access the debugging symbols from a object
>    file.  I am using Linux/egcs-1.1.1 (g++).
> 
> BFD does not really support debugging information in its full glory.
> The basic argument is that it is too difficult to handle all the
> various debugging formats in a way that is both generic and efficient.
> gdb reads debugging information efficiently.  The binutils (e.g.,
> objdump --debugging) read debugging information generically.

Then how does gdb get its information?  I know this is not the gdb 
list, but if anyone could comment, it would be helpful.

>    1. Read in the object file and get the address range
>       for every function - where it starts and ends.
> 
> I suppose the only way to do this using BFD is to call
> bfd_find_nearest_line on each address.  You will be safe enough if you
> increment the address by four each time.  You can save time by
> skipping ahead by bigger numbers; if you are still in the same
> function, you are OK, otherwise you have to go back and find out where
> the function changes.

Ok, but bfd_find_nearest_line is not documented.  What's the interface?
What does it return?

> When using ELF, you can generally read the symbol table and look for
> BSF_FUNCTION symbols.  This won't be quite right if you have constant
> data in the .text section, but when using ELF constant data is usually
> put in the .rodata section anyhow.

But AFAIK, the symbols (asymbol) only contain the starting address,
not the end.  I've been fudging things by sorting the symbols and
assuming functions appear in the text segment right after each other.
It seems to work weel enough for what I need, but it's ugly.

>    2. Given a program counter, figure out the source file
>       and line number corresponding to the PC.
> 
> Call bfd_find_nearest_line.
> 
>    3. Read that source file and print the relavent lines.
> 
> Not really a BFD function.  bfd_find_nearest_line will give you the
> name of the source file.  You may need some sort of directory search
> path.

I know it's not a BFD function, but I wanted to be complete.  :)
I really need 1 and 2 to do 3.

                                  -Dave

--

"Some little people have music in them, but Fats, he was all music,
 and you know how big he was."  --  James P. Johnson


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]