tags:

views:

228

answers:

3

Hi All, Can anybody help me writing a program which can read DWARF files and gives me the file name, line number and function name details. Thanks in advance -A

A: 

What's a DWARF file? Perhaps DWARF files define functions as function (xxx) like many languages do. In that case, I suggest using grep -n -R "function.*(" /dwarf/*.DWARF

easel
+2  A: 

The specification for DWARF-2 & DWARF-3 is here:

http://dwarfstd.org/dwarf-2.0.0.pdf

http://dwarfstd.org/Dwarf3.pdf

There is a decent library for reading DWARF files here:

http://reality.sgiweb.org/davea/dwarf.html

You can either get and use that library to read your DWARF files (it reads DWARF-2 and DWARF-3) or you can take a look at the source code to puzzle out how to write your own set of libraries/functions to do the job.

Jason Coco
+1  A: 

You could have a look at avr-readelf in binutils. The display_debug_lines() function in binutils/dwarf.c does the job of decoding the DWARF linenumber information.

Also, as suggested above, you could use libdwarf. This does a nice job of hiding the low-level complexities of DWARF and lets you focus on getting the data out.

After setting up libdwarf with an elfdescriptor and getting a Dwarf_Debug struct, you can do the following:

  1. Traverse all compilation units with dwarf_srclines()
  2. use dwarf_srclines() on each cu
  3. use dwarf_lineaddr() on each entry in the array returned from dwarf_srclines()
  4. remember to use dwarf_dealloc() in the right places.
Torleif