davea42 / libdwarf-code

Contains source for libdwarf, a library for reading DWARF2 and later DWARF. Contains source to create dwarfdump, a program which prints DWARF2 and later DWARF in readable format. Has a very limited DWARF writer set of functions in libdwarfp (producer library). Builds using GNU configure, meson, or cmake.
Other
173 stars 69 forks source link

Failed to parse dwarf file generated on Mac sequoia #269

Closed myzhan closed 6 days ago

myzhan commented 1 week ago

OS: Mac sequoia on Mac M3 Compiler: Apple clang version 16.0.0 (clang-1600.0.26.4) Target: arm64-apple-darwin24.1.0 libdwarf version: 0.11.0 (installed by homebrew)

dwarf_srclines_b returns an error. DW_DLE_ATTR_FORM_SIZE_BAD: An Attribute value (offset into .debug_str_offsets) is impossibly large. Corrupt Dwarf.

ret = dwarf_srclines_b(cu_die, nullptr, &table_count, &line_context, &err);
if (ret != DW_DLV_OK)
{
    printf("dwarf_srclines_b: %s\n", dwarf_errmsg(err));
}

dwarfdump is ok.

$ dwarfdump lua.dSYM/Contents/Resources/DWARF/lua | head -n 100
lua.dSYM/Contents/Resources/DWARF/lua:  file format Mach-O arm64

.debug_info contents:
0x00000000: Compile Unit: length = 0x00001cfe, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00001d02)

File to reproduce. lua.dSYM.zip

davea42 commented 1 week ago

Puzzling contents in the zip. 'file' says ._lua.dSYM is AppleDouble encoded Macintosh file

and I don't really know what that means. It's not just an apple universal binary (those the library knows about).

I see wikipedia has some comments about this (that lack clarity, IMO).

To put this another way: There is nothing in the zip file that is longer than 219 bytes. Way too short to be any sort of executable or .dSYM.

What you reference above is not in the zip file.

davea42 commented 1 week ago

Ah. No, I find lua is 740K. Overlooked it before.

davea42 commented 1 week ago

.debug_aranges From the .dSYM named lua: ERROR: dwarf_offdie_b() gets a return of error finding the compilation-unit DIE for arange number 0 and that should never happen. fails. Major error

dwarfdump ERROR: printing the aranges section had a problem.: DW_DLE_MISSING_NEEDED_DEBUG_ADDR_SECTION(257). Attempting to continue.

Yet .debug_addr is present. Odd.

davea42 commented 1 week ago

Oh. This is the first DWARF5 macos file I've seen, it names sections new to DWARF5 and the library did not expect them. So I added the translations and will try that now.

davea42 commented 1 week ago

Pushed to github. Seems to work ok now.

Adding __debug_names .debug_names on the assumption Apple might generate that section.

myzhan commented 1 week ago

Now, I think there is a related issue.

https://github.com/ianlancetaylor/libbacktrace/issues/136

davea42 commented 1 week ago

Not just related, but the same. I believe libbacktrace uses libdwarf and I fixed this in libdwarf yesterday.

davea42 commented 6 days ago

I believe this is fixed. If not reopen or create a new Issue and attach a (small-ish if possible) testcase. Thanks for advising us of the problem.