From: Simon Marchi Date: Fri, 14 Mar 2025 04:32:53 +0000 (-0400) Subject: gdb/dwarf: assume that source_cu->dies is always set in follow_die_offset X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc41f577884bb346028b037da16d6d3613ede3d2;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: assume that source_cu->dies is always set in follow_die_offset After staring at the code for a while, I got convinced that it's not possible for cu->dies to be nullptr in follow_die_offset. It might be a leftover from the psymtab days. In most cases, we see that the dwarf2_cu passedas `*ref_cu` has been obtained by doing: per_objfile->get_cu (per_cu); The only way for a dwarf2_cu to end up in the per_objfile like this is through load_full_comp_unit or read_signatured_type. Both of these functions call `reader.read_all_dies ()` (which loads the DIEs in memory and assigns dwarf2_cu::dies) before transferring the newly created dwarf2_cu to the per_objfile. So any dwarf2_cu obtained through per_objfile->get_cu (per_cu) ... will have its DIEs set. The only case today I'm aware of of a dwarf2_cu without DIEs is in the cooked indexer. It creates a cutu_reader, but does not call read_all_dies. Instead, it gets the info_ptr from the cutu_reader and reads the DIEs from the section buffer directly, on its own. But this is an entirely different code path that doesn't assign dwarf2_cu objects to per_objfile. So, remove the code path in follow_die_offset that tests for `source_cu->dies == NULL`. I added an assert at the top of the function to verify that `source_cu->dies` is always non-nullptr, as a way to test my hypothesis. We could probably get rid of it, but I left it there because it doesn't cost much to have it. Change-Id: I97f269f092128800850aa5e64eda7032c2edec60 Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index f42253b532e..649fe69a509 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -18482,7 +18482,8 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz, dwarf2_cu *target_cu = source_cu; dwarf2_per_objfile *per_objfile = source_cu->per_objfile; - gdb_assert (source_cu->per_cu != NULL); + gdb_assert (source_cu->per_cu != nullptr); + gdb_assert (source_cu->dies != nullptr); dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, " "source CU contains target offset: %d", @@ -18529,12 +18530,6 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz, sect_offset_str (sect_off), objfile_name (per_objfile->objfile)); } - else if (source_cu->dies == NULL) - { - /* We're loading full DIEs during partial symbol reading. */ - load_full_comp_unit (source_cu->per_cu, per_objfile, source_cu, false, - language_minimal); - } *ref_cu = target_cu;