Reading a DWARF File on Mac OSX

Can someone help me write a program that can read DWARF files and gives me the file name, line number and function name.

+6
dwarf
source share
3 answers

The specifications for DWARF-2 and DWARF-3 are 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 it or use this library to read your DWARF files (it reads DWARF-2 and DWARF-3), or you can take a look at the source code to decide how to write your own set of libraries / functions for the job.

+4
source share

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

Alternatively, as suggested above, you can use libdwarf. This is a good job at smoothing out the low-level complexities of DWARF and allows you to focus on getting data.

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

  • Moving all compilation units with dwarf_srclines ()
  • use dwarf_srclines () for each cu
  • use dwarf_lineaddr () for each entry in the array returned from dwarf_srclines ()
  • Remember to use dwarf_dealloc () in the right places.
+1
source share

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

-5
source share

All Articles