From 946ead3f1f4d6a46c481a6dfe1578fa49afcf1a8 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 22 Aug 2023 13:17:47 +0200 Subject: [PATCH] [gdb/symtab] Factor out m_die_range_map usage Factor out usage of cooked_indexer::m_die_range_map into new class parent_map with member functions find_parent and set_parent. Tested on x86_64-linux. --- gdb/dwarf2/cooked-index.h | 51 +++++++++++++++++++++++++++++++++ gdb/dwarf2/read.c | 60 +++++++++++++++++++++------------------ 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 5675ea68bb8..47bc48ea459 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -239,6 +239,57 @@ struct cooked_index_entry : public allocate_on_obstack bool for_name) const; }; +class parent_map +{ +public: + + /* A DIE address as formed by form_addr, defining a tuple + . */ + typedef CORE_ADDR die_addr; + + /* Find the parent of DIE LOOKUP. */ + const cooked_index_entry *find_parent (die_addr lookup) const + { + const void *obj = m_parent_map.find (lookup); + return static_cast (obj); + } + + /* Find the parent of DIE . */ + const cooked_index_entry *find_parent (sect_offset offset, bool is_dwz) const + { + return find_parent (form_addr (offset, is_dwz)); + } + + /* Set the parent of DIES in range [START, END] to PARENT_ENTRY. */ + void set_parent (die_addr start, die_addr end, + const cooked_index_entry *parent_entry) + { + m_parent_map.set_empty (start, end, (void *)parent_entry); + } + + /* Set the parent of DIES in range <[START, END], IS_DWZ> to PARENT_ENTRY. */ + void set_parent (sect_offset start, sect_offset end, bool is_dwz, + const cooked_index_entry *parent_entry) + { + set_parent (form_addr (start, is_dwz), form_addr (end, is_dwz), + parent_entry); + } + + /* A helper function to turn a tuple into a die_addr. */ + static die_addr form_addr (sect_offset offset, bool is_dwz) + { + CORE_ADDR value = to_underlying (offset); + if (is_dwz) + value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1); + return value; + } + +private: + + /* An addrmap that maps from section offsets to cooked_index_entry *. */ + addrmap_mutable m_parent_map; +}; + class cooked_index; /* An index of interesting DIEs. This is "cooked", in contrast to a diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 9311666a832..926feab8a7a 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4552,16 +4552,6 @@ class cooked_indexer private: - /* A helper function to turn a section offset into an address that - can be used in an addrmap. */ - CORE_ADDR form_addr (sect_offset offset, bool is_dwz) - { - CORE_ADDR value = to_underlying (offset); - if (is_dwz) - value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1); - return value; - } - /* A helper function to scan the PC bounds of READER and record them in the storage's addrmap. */ void check_bounds (cutu_reader *reader); @@ -4599,7 +4589,7 @@ class cooked_indexer cooked_index_flag *flags, sect_offset *sibling_offset, const cooked_index_entry **parent_entry, - CORE_ADDR *maybe_defer, + parent_map::die_addr *maybe_defer, bool for_specification); /* Handle DW_TAG_imported_unit, by scanning the DIE to find @@ -4629,14 +4619,34 @@ class cooked_indexer /* An addrmap that maps from section offsets (see the form_addr method) to newly-created entries. See m_deferred_entries to understand this. */ - addrmap_mutable m_die_range_map; + parent_map m_die_range_map; + + /* Find the parent of DIE . */ + const cooked_index_entry *find_parent (sect_offset offset, bool is_dwz) const + { + return m_die_range_map.find_parent (offset, is_dwz); + } + + /* Find the parent of DIE LOOKUP. */ + const cooked_index_entry *find_parent (parent_map::die_addr lookup) const + { + return m_die_range_map.find_parent (lookup); + } + + /* Set the parent of DIES in range <[START, END], IS_DWZ> to + PARENT_ENTRY. */ + void set_parent (sect_offset start, sect_offset end, bool is_dwz, + const cooked_index_entry *parent_entry) + { + m_die_range_map.set_parent (start, end, is_dwz, parent_entry); + } /* A single deferred entry. */ struct deferred_entry { sect_offset die_offset; const char *name; - CORE_ADDR spec_offset; + parent_map::die_addr spec_offset; dwarf_tag tag; cooked_index_flag flags; }; @@ -16009,7 +16019,7 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, cooked_index_flag *flags, sect_offset *sibling_offset, const cooked_index_entry **parent_entry, - CORE_ADDR *maybe_defer, + parent_map::die_addr *maybe_defer, bool for_specification) { bool origin_is_dwz = false; @@ -16182,13 +16192,9 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, if (new_reader->cu == reader->cu && new_info_ptr > watermark_ptr && *parent_entry == nullptr) - *maybe_defer = form_addr (origin_offset, origin_is_dwz); + *maybe_defer = parent_map::form_addr (origin_offset, origin_is_dwz); else if (*parent_entry == nullptr) - { - CORE_ADDR lookup = form_addr (origin_offset, origin_is_dwz); - void *obj = m_die_range_map.find (lookup); - *parent_entry = static_cast (obj); - } + *parent_entry = find_parent (origin_offset, origin_is_dwz); unsigned int bytes_read; const abbrev_info *new_abbrev = peek_die_abbrev (*new_reader, @@ -16305,11 +16311,10 @@ cooked_indexer::recurse (cutu_reader *reader, { /* Both start and end are inclusive, so use both "+ 1" and "- 1" to limit the range to the children of parent_entry. */ - CORE_ADDR start = form_addr (parent_entry->die_offset + 1, - reader->cu->per_cu->is_dwz); - CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer), - reader->cu->per_cu->is_dwz); - m_die_range_map.set_empty (start, end, (void *) parent_entry); + set_parent (parent_entry->die_offset + 1, + sect_offset (info_ptr - 1 - reader->buffer), + reader->cu->per_cu->is_dwz, + parent_entry); } return info_ptr; @@ -16351,7 +16356,7 @@ cooked_indexer::index_dies (cutu_reader *reader, const char *name = nullptr; const char *linkage_name = nullptr; - CORE_ADDR defer = 0; + parent_map::die_addr defer = 0; cooked_index_flag flags = IS_STATIC; sect_offset sibling {}; const cooked_index_entry *this_parent_entry = parent_entry; @@ -16482,8 +16487,7 @@ cooked_indexer::make_index (cutu_reader *reader) for (const auto &entry : m_deferred_entries) { - void *obj = m_die_range_map.find (entry.spec_offset); - cooked_index_entry *parent = static_cast (obj); + const cooked_index_entry *parent = find_parent (entry.spec_offset); m_index_storage->add (entry.die_offset, entry.tag, entry.flags, entry.name, parent, m_per_cu); } base-commit: 53302c2d33c26909cc8446819f6677076ba48ca9 -- 2.35.3