diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c56c129d0b1..e841fdaab5e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2021-06-16 Tom de Vries + + PR symtab/26327 + * dwarf2/cu.h (dwarf2_cu::ancestor): Remove. + (dwarf2_cu::get_builder): Declare and move ... + * dwarf2/cu.c (dwarf2_cu::get_builder): ... here. Use sym_cu instead + of ancestor. Assert return value is non-null. + * dwarf2/read.c (read_file_scope): Set per_objfile->sym_cu. + (follow_die_offset, follow_die_sig_1): Remove setting of ancestor. + (dwarf2_per_objfile): Add sym_cu field. + 2021-06-15 Alan Modra * testsuite/lib/gdb.exp (exec_is_pie): Match new PIE readelf output. diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 1031ed3aa00..bc3f26dc28f 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -138,3 +138,18 @@ dwarf2_cu::add_dependence (struct dwarf2_per_cu_data *ref_per_cu) if (*slot == nullptr) *slot = ref_per_cu; } + +/* See dwarf2/cu.h. */ + +buildsym_compunit * +dwarf2_cu::get_builder () +{ + /* If this CU has a builder associated with it, use that. */ + if (m_builder != nullptr) + return m_builder.get (); + + if (per_objfile->sym_cu != nullptr) + return per_objfile->sym_cu->m_builder.get (); + + gdb_assert_not_reached (""); +} diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index b4a5b08d5a6..fe606f3eab7 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -272,23 +272,8 @@ public: struct partial_die_info *find_partial_die (sect_offset sect_off); - /* If this CU was inherited by another CU (via specification, - abstract_origin, etc), this is the ancestor CU. */ - dwarf2_cu *ancestor; - /* Get the buildsym_compunit for this CU. */ - buildsym_compunit *get_builder () - { - /* If this CU has a builder associated with it, use that. */ - if (m_builder != nullptr) - return m_builder.get (); - - /* Otherwise, search ancestors for a valid builder. */ - if (ancestor != nullptr) - return ancestor->get_builder (); - - return nullptr; - } + buildsym_compunit *get_builder (); }; #endif /* GDB_DWARF2_CU_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 96009f1418f..07bc08fba14 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -10521,6 +10521,10 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) cu->start_symtab (fnd.name, fnd.comp_dir, lowpc); + gdb_assert (per_objfile->sym_cu == nullptr); + scoped_restore restore_sym_cu + = make_scoped_restore (&per_objfile->sym_cu, cu); + /* Decode line number information if present. We do this before processing child DIEs, so that the line header table is available for DW_AT_decl_file. */ @@ -10536,6 +10540,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) child_die = child_die->sibling; } } + per_objfile->sym_cu = nullptr; /* Decode macro information, if present. Dwarf 2 macro information refers to information in the line number info statement program @@ -23114,9 +23119,6 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz, *ref_cu = target_cu; temp_die.sect_off = sect_off; - if (target_cu != cu) - target_cu->ancestor = cu; - return (struct die_info *) htab_find_with_hash (target_cu->die_hash, &temp_die, to_underlying (sect_off)); @@ -23469,7 +23471,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, struct dwarf2_cu **ref_cu) { struct die_info temp_die; - struct dwarf2_cu *sig_cu, *cu = *ref_cu; + struct dwarf2_cu *sig_cu; struct die_info *die; dwarf2_per_objfile *per_objfile = (*ref_cu)->per_objfile; @@ -23505,9 +23507,6 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type, } *ref_cu = sig_cu; - if (sig_cu != cu) - sig_cu->ancestor = cu; - return die; } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index ae1608fa822..ee454ad300a 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -579,6 +579,9 @@ struct dwarf2_per_objfile /* Table containing line_header indexed by offset and offset_in_dwz. */ htab_up line_header_hash; + /* The CU containing the m_builder in scope. */ + dwarf2_cu *sym_cu = nullptr; + private: /* Hold the corresponding compunit_symtab for each CU or TU. This is indexed by dwarf2_per_cu_data::index. A NULL value means