diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2025-03-14 00:32:48 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2025-03-14 12:23:40 -0400 |
commit | 4fca47b93866f96db4723cc5f8570a66df9a7127 (patch) | |
tree | 422358f108aa153aea78865a4f361c53d6ce6d7e /gdb | |
parent | 0bb9d85fc7f86fe5bde091b68facbd72b005c286 (diff) | |
download | binutils-4fca47b93866f96db4723cc5f8570a66df9a7127.zip binutils-4fca47b93866f96db4723cc5f8570a66df9a7127.tar.gz binutils-4fca47b93866f96db4723cc5f8570a66df9a7127.tar.bz2 |
gdb/dwarf: change cutu_reader::read_die_and_siblings to cutu_reader::read_all_dies
After construction of a cutu_reader, only the top-level DIE has been
read in memory. If the caller wants to access the full DIE tree, it
does:
reader.top_level_die ()->child
= reader.read_die_and_siblings (reader.top_level_die ());
I don't really like this poking into cutu_reader's data structures from
the outside, I would prefer if that work was done by cutu_reader.
Rename the read_die_and_siblings method to read_all_dies, and do that
work inside cutu_reader.
I also moved these operations inside the read_all_dies method:
gdb_assert (cu->die_hash.empty ());
cu->die_hash.reserve (cu->header.get_length_without_initial () / 12);
...
cu->dies = reader.top_level_die ();
The rationale for this is that read_all_dies (and the functions it
calls) is responsible for filling the die_hash set. So I think it makes
sense for it to do the reserve.
It is also cutu_reader's job, currently, to create and fill the fields
of dwarf2_cu. So I think it makes sense for it to set cu->dies, after
having read the DIEs in memory.
Change-Id: I088c2e0b367db7d1f67e8c9e2d5b0d61165292fc
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/dwarf2/read.c | 49 | ||||
-rw-r--r-- | gdb/dwarf2/read.h | 3 |
2 files changed, 17 insertions, 35 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index cfd5efe..d656fbd 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4400,18 +4400,7 @@ load_full_comp_unit (dwarf2_per_cu *this_cu, if (reader.is_dummy ()) return; - struct dwarf2_cu *cu = reader.cu (); - - gdb_assert (cu->die_hash.empty ()); - cu->die_hash.reserve (cu->header.get_length_without_initial () / 12); - - if (reader.top_level_die ()->has_children) - reader.top_level_die ()->child - = reader.read_die_and_siblings (reader.top_level_die ()); - - cu->dies = reader.top_level_die (); - /* comp_unit_die is not stored in die_hash, no need. */ - + reader.read_all_dies (); reader.keep (); } @@ -14577,16 +14566,21 @@ cutu_reader::read_die_and_siblings_1 (die_info *parent) } } -/* Read a die, all of its descendents, and all of its siblings; set - all of the fields of all of the dies correctly. Arguments are as - in read_die_and_children. - This the main entry point for reading a DIE and all its children. */ +/* See read.h. */ -die_info * -cutu_reader::read_die_and_siblings (die_info *parent) +void +cutu_reader::read_all_dies () { const gdb_byte *begin_info_ptr = m_info_ptr; - struct die_info *die = this->read_die_and_siblings_1 (parent); + + if (m_top_level_die->has_children) + { + gdb_assert (m_cu->die_hash.empty ()); + m_cu->die_hash.reserve (m_cu->header.get_length_without_initial () / 12); + m_top_level_die->child = this->read_die_and_siblings_1 (m_top_level_die); + } + + m_cu->dies = m_top_level_die; if (dwarf_die_debug) { @@ -14594,10 +14588,8 @@ cutu_reader::read_die_and_siblings (die_info *parent) m_die_section->get_name (), begin_info_ptr - m_die_section->buffer, bfd_get_filename (m_abfd)); - die->dump (dwarf_die_debug); + m_top_level_die->child->dump (dwarf_die_debug); } - - return die; } /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS @@ -19109,18 +19101,7 @@ read_signatured_type (signatured_type *sig_type, if (!reader.is_dummy ()) { - struct dwarf2_cu *cu = reader.cu (); - - gdb_assert (cu->die_hash.empty ()); - cu->die_hash.reserve (cu->header.get_length_without_initial () / 12); - - if (reader.top_level_die ()->has_children) - reader.top_level_die ()->child - = reader.read_die_and_siblings (reader.top_level_die ()); - - cu->dies = reader.top_level_die (); - /* comp_unit_die is not stored in die_hash, no need. */ - + reader.read_all_dies (); reader.keep (); } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 3f99b39..29dcf18 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -952,7 +952,8 @@ public: return std::move (m_abbrev_table_holder); } - die_info *read_die_and_siblings (die_info *parent); + /* Read all DIES of the debug info section in memory. */ + void read_all_dies (); const gdb_byte *read_attribute (attribute *attr, const attr_abbrev *abbrev, const gdb_byte *info_ptr, |