Hi Mark,
On Mon, Mar 23, 2026 at 11:27 AM Mark Wielaard <[email protected]> wrote:
>
> 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 <[email protected]>
LGTM.
Aaron
> ---
> src/readelf.c | 20 +++++++++++++++-----
> tests/run-readelf-loc.sh | 2 +-
> 2 files changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/src/readelf.c b/src/readelf.c
> index 719c5602ee69..6d4cde9f59c5 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -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;
> diff --git a/tests/run-readelf-loc.sh b/tests/run-readelf-loc.sh
> index 8594b540bfa8..17c3e02ae181 100755
> --- a/tests/run-readelf-loc.sh
> +++ b/tests/run-readelf-loc.sh
> @@ -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)
> --
> 2.53.0
>