]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Print split DWARF CU version, unit type and id
authorMark Wielaard <mark@klomp.org>
Sat, 21 Mar 2026 22:56:58 +0000 (23:56 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 24 Mar 2026 09:43:38 +0000 (10:43 +0100)
When printing the split units we reused the version, unit type and id
found in the skeleton unit. The version and id really should match,
but the unit type shouldn't. We could hard code the expected values,
but it is better to look them up explicitly. One testcase needed
updating to show the correct split_compile unit type.

* src/readelf.c (print_debug_units): Call dwarf_cu_die and
dwarf_cu_info to explicitly fetch split_version,
split_unit_type and split_unit_id.
* tests/run-readelf-loc.sh: Adjust Unit type.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/readelf.c
tests/run-readelf-loc.sh

index 719c5602ee691c071371f585b35c9efa6899f1a5..6d4cde9f59c5a1d34be11fa784202054a69f6fb6 100644 (file)
@@ -8853,9 +8853,19 @@ print_debug_units (Dwfl_Module *dwflmod,
       else
        {
          Dwarf_CU *split_cu = subdie.cu;
-         dwarf_cu_die (split_cu, &result, NULL, &abbroffset,
+         Dwarf_Half split_version; /* Should be the same version as skel.  */
+         dwarf_cu_die (split_cu, &result, &split_version, &abbroffset,
                        &addrsize, &offsize, &unit_id, &subdie_off);
          Dwarf_Off offset = cu->start;
+         uint8_t split_unit_type; /* Should be DW_UT_split_compile. */
+         uint64_t split_unit_id; /* Should be the same as id.  */
+         if (dwarf_cu_info (split_cu, NULL, &split_unit_type, NULL, NULL,
+                            &split_unit_id, NULL, NULL) != 0)
+           {
+             /* Really shouldn't happen unless split_cu is NULL.  */
+             split_unit_type = DW_UT_split_compile;
+             split_unit_id = unit_id;
+           }
 
          if (!silent)
            {
@@ -8865,15 +8875,15 @@ print_debug_units (Dwfl_Module *dwflmod,
                                ", Abbreviation section offset: %" PRIu64
                                ", Address size: %" PRIu8
                                ", Offset size: %" PRIu8 "\n"),
-                      (uint64_t) offset, version, abbroffset,
+                      (uint64_t) offset, split_version, abbroffset,
                       addrsize, offsize);
              fprintf (out, _(" Unit type: %s (%" PRIu8 ")"),
-                      dwarf_unit_name (unit_type), unit_type);
-             fprintf (out, ", Unit id: 0x%.16" PRIx64 "", unit_id);
+                      dwarf_unit_name (split_unit_type), split_unit_type);
+             fprintf (out, ", Unit id: 0x%.16" PRIx64 "", split_unit_id);
              fprintf (out, "\n");
            }
 
-         unit_type = DW_UT_split_compile;
+         unit_type = split_unit_type;
          is_split = true;
          level = 0;
          dies[0] = subdie;
index 8594b540bfa8d8bbece2fe4004587af9dae519ab..17c3e02ae181789994dc10213ec12229bb4396a0 100755 (executable)
@@ -926,7 +926,7 @@ DWARF section [28] '.debug_info' at offset 0x330:
            GNU_ranges_base      (sec_offset) 0
  Split compilation unit at offset 0:
  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
- Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b
+ Unit type: split_compile (5), Unit id: 0x3d909d7bd0e69c0b
  {     b}  compile_unit         abbrev: 1
            producer             (GNU_str_index) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -O2"
            language             (data1) C99 (12)