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


   Date: Wed, 12 Apr 2000 09:36:03 -0500 (EST)
   From: David Greene <greened@eecs.umich.edu>

   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.

So this information is generally not documented in part because there
isn't really anything to document.

   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.

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.

   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.

Ian

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