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 70 forks source link

clang++18: ERROR: print .debug_names section failed: DW_DLE_READ_LITTLEENDIAN_ERROR Read would end past the end of section. #261

Closed PolarNettles closed 2 months ago

PolarNettles commented 2 months ago

With the fix for https://github.com/davea42/libdwarf-code/issues/260 I am now hitting this error. It looks like it happens when the last entry of .debug_names specifies a DW_IDX_parent.

ubu@xxx:~/libdwarf-0.11.0/src/bin/dwarfdump$ llvm-dwarfdump --debug-names cpp_test.o
cpp_test.o:     file format elf64-x86-64

.debug_names contents:
Name Index @ 0x0 {
...
  Bucket 8 [
    Name 9 {
      Hash: 0x7C9400EA
      String: 0x000000ef "afoo"
      Entry @ 0x138 {
        Abbrev: 0x1738
        Tag: DW_TAG_subprogram
        DW_IDX_die_offset: 0x00000071
        DW_IDX_parent: 0x0000002a
      }
    }
  ]
}

Reproduction steps:

ubu@xxx:~/libdwarf-0.11.0/src/bin/dwarfdump$ ./dwarfdump --print-debug-names cpp_test.o
...
./dwarfdump ERROR:  print .debug_names section failed:  DW_DLE_READ_LITTLEENDIAN_ERROR Read would end past the end of section. Attempting to continue.

cpp_test.zip

davea42 commented 2 months ago

Reading DW_FORM_ref4 from a .debug_names table we were double-counting the 4 bytes read. oops. Running a full regression test now. Also, for a debug_names FORM_ref1 we were not checking for past-end.. Fixed.

davea42 commented 2 months ago

I am updating the dwarfdump --print-debug-names format today so it looks better. Nothing changing in the library. Regression tests have run just fine, though I am rerunning now.

davea42 commented 2 months ago

The feature, I learned today from the person who implemented it in clang, is to distinguish two cases for the code reading the .debug_names section:

1, Absence of DW_IDX_parent means the producer did not generate a parent.

  1. DW_IDX_parent with DW_FORM_flag_present means means the parent is not indexed though it was generated.
davea42 commented 2 months ago

dwarfdump now reports this. I think this can be closed.