Skip to content

Commit

Permalink
gdb/dwarf: pass is_dwz to dwarf2_per_cu constructor
Browse files Browse the repository at this point in the history
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 <tom@tromey.com>
  • Loading branch information
simark committed Mar 4, 2025
1 parent 66195fe commit 6625c32
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
10 changes: 5 additions & 5 deletions gdb/dwarf2/read-gdb-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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 ());
Expand Down
39 changes: 21 additions & 18 deletions gdb/dwarf2/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<signatured_type> (this, section, sect_off,
length, signature);
auto result
= std::make_unique<signatured_type> (this, section, sect_off, length,
is_dwz, signature);
result->index = all_units.size ();
tu_stats.nr_tus++;
return result;
Expand Down Expand Up @@ -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 ());
Expand Down Expand Up @@ -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 ());
Expand All @@ -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). */
Expand Down Expand Up @@ -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, &section, sect_off, 0);
dwarf2_per_cu per_cu (per_bfd, &section, sect_off, 0 /* length */,
false /* is_dwz */);
cutu_reader reader (&per_cu, per_objfile, language_minimal,
cu, &dwo_file);

Expand Down Expand Up @@ -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<dwarf2_per_bfd *> (&dummy_per_bfd);
auto section = reinterpret_cast<dwarf2_section_info *> (&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<dwarf2_per_cu_up> units;
units.push_back (std::move (one));
units.push_back (std::move (two));
Expand Down
12 changes: 7 additions & 5 deletions gdb/dwarf2/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -375,9 +375,9 @@ struct dwarf2_per_cu
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;
Expand Down Expand Up @@ -515,14 +515,16 @@ 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
is allocated on the dwarf2_per_bfd obstack. */
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
Expand Down

0 comments on commit 6625c32

Please sign in to comment.