Hi, we have an in-house-tool that is similar to the dwarfdump program that comes with David Anderson's libdwarf, except that its output format is tailored towards our specific needs. Currently our tool uses David Anderson's libdwarf, and the libelf from http://www.mr511.de/software/english.html, but I wanted to get it to work with the libraries from the BSD ELF Tool Chain.
The program works just like dwarfdump. In very rough terms, the following function is applied to each die: pretty_print(die): print name of die for each attribute of die: print name and value of attribute for each sibling of die: pretty_print(sibling) This works nicely for most attributes, except that with the BSD ELF Tool Chain libelf and libdwarf dwarf_formstring(attribute_list[i], &name, &error) ALWAYS returns the attribute name that is the very first entry in the .debug_str section. The result is that ONE bogus attribute name is printed for ALL occurrences of DW_AT_producer, DW_AT_name, and DW_AT_comp_dir. I did some debugging and compared the bytes as they are interpreted by the libdwarf functions with the bytes as they are stored in the input file. I found that the indices into .debug_str are all correct in the object file, but at the point where they are parsed by the libdwarf routines, all indices are zeros. I found that the BSD ELF Tool Chain libelf/libdwarf apply relocations to .debug_str, whereas the other libelf/libdwarf combination does not do this. Indeed this strange behavior can be disabled by calling dwarf_set_reloc_application(false) prior to dwarf_init(...). This works around the issue. I strongly suspect that this is a bug. Best regards, Paul ps: Overall I'm very happy with your code, I found a few issues and sent a patch to Kai Wang in a private mail. Porting our program was quite easy. I had to change a few macros that are used in format strings. In David Anderson's libdwarf, dwarf_formref and dwarf_global_formref sometimes indicate an invalid attribute form with DW_DLE_BAD_REF_FORM, while your libdwarf always uses DW_DLE_ATTR_FORM_BAD. Keep up the good work! Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928 ------------------------------------------------------------------------------ _______________________________________________ Elftoolchain-developers mailing list Elftoolchain-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/elftoolchain-developers