4 ms·
"Anyway my impression is that DWARF is a large and complicated standard (and possibly the libraries people use to generate DWARF are subtly incompatible?), but
by DannyBee 10y ago
"Anyway my impression is that DWARF is a large and complicated standard (and possibly the libraries people use to generate DWARF are subtly incompatible?), but it's what we have, so that's what we work with!"
Having written at least 4 complete DWARF readers and writers (GCC's location list support, GDB's expression evaluator, the thing that became google breakpad's debuginfo reader etc), it's really not that bad.
In fact, compared to pretty much any other debug format, it's wonderful. All of the forms are consistent, and outside of the index tables, and a few places where backwards compatibility was needed (ie the world moved from 32 bit to 64 bit, but before that, DWARF supported 64 bit sized debug info on 32 bit processors), the encoding is sane.
libdwarf, on the other hand, is ... not so much.
I love david a, and (AFAIK) he's been working on DWARF since SGI was at 1600 amphitheatre parkway, and keeping libdwarf up to date. It's one of those open source projects nobody ever realizes has been around 20 years and that someone has kept it working great (see ftp://ftp.sgi.com/sgi/dev/davea/objectinfo.html)
However, libdwarf is just not a pleasant interface to work with, IMHO.
It's also memory intensive.
If you just want a reader, the thing that made it into breakpad is probably a good reference (others may have better ones, i've thankfully been out of the debug info game for years):
https://chromium.googlesource.com/breakpad/breakpad/+/master/src/common/dwarf/ https://chromium.googlesource.com/breakpad/breakpad/+/master...
It's mostly a callback interface, and has a function info reader meant as a demonstration
It should work without trouble outside of breakpad (when it was contributed, I made it portable to be able to just compile standalone. it doesn't look like much has changed).
it does not support DWARF4/5, but nobody should need to care.
It also has no expression evaluator but i have a bunch of them if someone needs them :)
- seesomesense 10y agoThank you. Most informative !
- alschwalm 10y agoNice writeup! I've done some work with libdwarf and I agree that it isn't very pleasant. Do you have any suggestions for better interfaces that support writing?
- DannyBee 10y agoHow much of a writer do you want? Just something that writes DIE's? Or do you need line info, accelerator tables, etc?
- alschwalm 10y agoI think just DIE's would be sufficient, definitely don't need accelerator table stuff. I've actually considered looking more at the LLVM dwarf writing components. Do you have any experience with that?