From: Simon Marchi Date: Mon, 3 Mar 2025 21:35:37 +0000 (-0500) Subject: gdb/dwarf: pass is_dwz to dwarf2_per_cu constructor X-Git-Tag: binutils-2_45~1393 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6625c32600b8175f2d7222db761670a4d3315863;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: pass is_dwz to dwarf2_per_cu constructor It is always known at construction time whether a dwarf2_per_cu is built to represent a unit from a dwz file or not, so pass that information through the constructor. Change-Id: I278c1894ed606451aad02e830085190bb724c473 Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c index e513e80ffce..f6c73d0c98a 100644 --- a/gdb/dwarf2/read-gdb-index.c +++ b/gdb/dwarf2/read-gdb-index.c @@ -1324,10 +1324,10 @@ create_cus_from_gdb_index_list (dwarf2_per_bfd *per_bfd, ULONGEST length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE); cu_list += 2 * 8; - dwarf2_per_cu_up per_cu = per_bfd->allocate_per_cu (section, sect_off, length); - per_cu->is_dwz = is_dwz; - - per_bfd->all_units.push_back (std::move (per_cu)); + per_bfd->all_units.emplace_back (per_bfd->allocate_per_cu (section, + sect_off, + length, + is_dwz)); } } @@ -1378,7 +1378,7 @@ create_signatured_type_table_from_gdb_index (presumably) set by a cutu_reader when it gets expanded later. */ signatured_type_up sig_type = per_bfd->allocate_signatured_type (section, sect_off, 0 /* length */, - signature); + false /* is_dwz */, signature); sig_type->type_offset_in_tu = type_offset_in_tu; sig_types_hash.emplace (sig_type.get ()); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a10659039bc..6080dca6ea6 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1818,10 +1818,11 @@ dw2_instantiate_symtab (dwarf2_per_cu *per_cu, dwarf2_per_objfile *per_objfile, dwarf2_per_cu_up dwarf2_per_bfd::allocate_per_cu (dwarf2_section_info *section, - sect_offset sect_off, unsigned int length) + sect_offset sect_off, unsigned int length, + bool is_dwz) { dwarf2_per_cu_up result (new dwarf2_per_cu (this, section, sect_off, - length)); + length, is_dwz)); result->index = all_units.size (); return result; } @@ -1832,10 +1833,12 @@ signatured_type_up dwarf2_per_bfd::allocate_signatured_type (dwarf2_section_info *section, sect_offset sect_off, unsigned int length, + bool is_dwz, ULONGEST signature) { - auto result = std::make_unique (this, section, sect_off, - length, signature); + auto result + = std::make_unique (this, section, sect_off, length, + is_dwz, signature); result->index = all_units.size (); tu_stats.nr_tus++; return result; @@ -2678,7 +2681,8 @@ add_type_unit (dwarf2_per_bfd *per_bfd, dwarf2_section_info *section, ++per_bfd->tu_stats.nr_all_type_units_reallocs; signatured_type_up sig_type_holder - = per_bfd->allocate_signatured_type (section, sect_off, length, sig); + = per_bfd->allocate_signatured_type (section, sect_off, length, + false /* is_dwz */, sig); signatured_type *sig_type = sig_type_holder.get (); per_bfd->all_units.emplace_back (sig_type_holder.release ()); @@ -4268,11 +4272,11 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile, /* Save the compilation unit for later lookup. */ if (cu_header.unit_type != DW_UT_type) this_cu - = per_objfile->per_bfd->allocate_per_cu (section, sect_off, length); + = per_objfile->per_bfd->allocate_per_cu (section, sect_off, length, is_dwz); else { auto sig_type = per_objfile->per_bfd->allocate_signatured_type - (section, sect_off, length, cu_header.signature); + (section, sect_off, length, is_dwz, cu_header.signature); signatured_type *sig_ptr = sig_type.get (); sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu; this_cu.reset (sig_type.release ()); @@ -4287,7 +4291,6 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile, hex_string (sig_ptr->signature)); } - this_cu->is_dwz = is_dwz; /* Init this asap, to avoid a data race in the set_version in cutu_reader::cutu_reader (which may be run in parallel for the cooked index case). */ @@ -7046,7 +7049,8 @@ create_cus_hash_table (dwarf2_per_objfile *per_objfile, sect_offset sect_off = (sect_offset) (info_ptr - section.buffer); /* The length of the CU gets set by the cutu_reader just below. */ - dwarf2_per_cu per_cu (per_bfd, §ion, sect_off, 0); + dwarf2_per_cu per_cu (per_bfd, §ion, sect_off, 0 /* length */, + false /* is_dwz */); cutu_reader reader (&per_cu, per_objfile, language_minimal, cu, &dwo_file); @@ -20902,31 +20906,30 @@ run_test () char dummy_section; const auto create_dummy_per_cu = [&] (sect_offset sect_off, - unsigned int length) + unsigned int length, + bool is_dwz) { auto per_bfd = reinterpret_cast (&dummy_per_bfd); auto section = reinterpret_cast (&dummy_section); return dwarf2_per_cu_up (new dwarf2_per_cu (per_bfd, section, sect_off, - length)); + length, is_dwz)); }; /* Units in the main file. */ - dwarf2_per_cu_up one = create_dummy_per_cu (sect_offset (0), 5); + dwarf2_per_cu_up one = create_dummy_per_cu (sect_offset (0), 5, false); dwarf2_per_cu *one_ptr = one.get (); - dwarf2_per_cu_up two = create_dummy_per_cu (sect_offset (one->length ()), 7); + dwarf2_per_cu_up two + = create_dummy_per_cu (sect_offset (one->length ()), 7, false); dwarf2_per_cu *two_ptr = two.get (); /* Units in the supplementary (dwz) file. */ - dwarf2_per_cu_up three = create_dummy_per_cu (sect_offset (0), 5); + dwarf2_per_cu_up three = create_dummy_per_cu (sect_offset (0), 5, true); dwarf2_per_cu *three_ptr = three.get (); dwarf2_per_cu_up four - = create_dummy_per_cu (sect_offset (three->length ()), 7); + = create_dummy_per_cu (sect_offset (three->length ()), 7, true); dwarf2_per_cu *four_ptr = four.get (); - three->is_dwz = 1; - four->is_dwz = 1; - std::vector units; units.push_back (std::move (one)); units.push_back (std::move (two)); diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 612f575510c..f8047c2f15a 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -97,11 +97,11 @@ struct dwarf2_per_cu /* LENGTH is the length of the unit. If the value is 0, it means it is not known, and may be set later using the set_length method. */ dwarf2_per_cu (dwarf2_per_bfd *per_bfd, dwarf2_section_info *section, - sect_offset sect_off, unsigned int length) + sect_offset sect_off, unsigned int length, bool is_dwz) : sect_off (sect_off), m_length (length), is_debug_types (false), - is_dwz (false), + is_dwz (is_dwz), reading_dwo_directly (false), tu_read (false), lto_artificial (false), @@ -375,9 +375,9 @@ public: struct signatured_type : public dwarf2_per_cu { signatured_type (dwarf2_per_bfd *per_bfd, dwarf2_section_info *section, - sect_offset sect_off, unsigned int length, + sect_offset sect_off, unsigned int length, bool is_dwz, ULONGEST signature) - : dwarf2_per_cu (per_bfd, section, sect_off, length), + : dwarf2_per_cu (per_bfd, section, sect_off, length, is_dwz), signature (signature) { this->is_debug_types = true; @@ -515,7 +515,8 @@ struct dwarf2_per_bfd has its "index" field set properly. The object is allocated on the dwarf2_per_bfd obstack. */ dwarf2_per_cu_up allocate_per_cu (dwarf2_section_info *section, - sect_offset sect_off, unsigned int length); + sect_offset sect_off, unsigned int length, + bool is_dwz); /* A convenience function to allocate a signatured_type. The returned object has its "index" field set properly. The object @@ -523,6 +524,7 @@ struct dwarf2_per_bfd signatured_type_up allocate_signatured_type (dwarf2_section_info *section, sect_offset sect_off, unsigned int length, + bool is_dwz, ULONGEST signature); /* Map all the DWARF section data needed when scanning