Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP1:Update
gdb
gdb-symtab-resolve-deferred-entries-inter-shard...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File gdb-symtab-resolve-deferred-entries-inter-shard-case.patch of Package gdb
From 7464f06e1a7ccf4c5908e563e4cf684744919dac Mon Sep 17 00:00:00 2001 From: Tom de Vries <tdevries@suse.de> Date: Tue, 22 Aug 2023 14:24:42 +0200 Subject: [PATCH 05/11] [gdb/symtab] Resolve deferred entries, inter-shard case Generically solve the case of inter-CU dependencies, including inter-shard dependencies: - mark deferred entries in new data structure m_deferred, - return &parent_map::deferred in find_parent for deferred entries, - defer all intra-CU dependencies that depend on deferred entries, - defer all inter-CU dependencies (note that two subsequent patches implement optimizations to deal with this more optimally), - move m_die_range_map and m_deferred_dies to cooked_index_shard, and - move handle_deferred_dies to the cooked_index, where it is called in the constructor, and update it to handle the intra-shard case. Handling units from the .debug_info section alongside units from the .debug_types section requires us to extend form_addr to take is_debug_types into account. Tested on x86_64-linux. PR symtab/30846 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30846 --- gdb/dwarf2/cooked-index.c | 77 +++++++++++++++++++++++ gdb/dwarf2/cooked-index.h | 105 ++++++++++++++++++++++++++++++- gdb/dwarf2/read.c | 128 ++++++++++++++++++++++---------------- 3 files changed, 254 insertions(+), 56 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 2b7f9054fe5..4a0ccc78c5d 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -200,6 +200,12 @@ cooked_index_entry::write_scope (struct obstack *storage, /* See cooked-index.h. */ +cooked_index_entry parent_map::deferred((sect_offset)0, (dwarf_tag)0, + (cooked_index_flag)0, nullptr, + nullptr, nullptr); + +/* See cooked-index.h. */ + const cooked_index_entry * cooked_index::add (sect_offset die_offset, enum dwarf_tag tag, cooked_index_flag flags, const char *name, @@ -402,6 +408,8 @@ cooked_index::find (const std::string &name, bool completing) cooked_index_vector::cooked_index_vector (vec_type &&vec) : m_vector (std::move (vec)) { + handle_deferred_entries (); + for (auto &idx : m_vector) idx->finalize (); } @@ -467,6 +475,75 @@ cooked_index_vector::get_main () const return result; } +/* See cooked-index.h. */ + +const cooked_index_entry * +cooked_index::resolve_deferred_entry + (const deferred_entry &de, const cooked_index_entry *parent_entry) +{ + reset_parent_deferred (parent_map::form_addr (de.die_offset, de.per_cu_2->is_dwz, + de.per_cu_2->is_debug_types)); + return add (de.die_offset, de.tag, de.flags, de.name, + parent_entry, de.per_cu); +} + +/* See cooked-index.h. */ + +const cooked_index_entry * +cooked_index_vector::find_parent_deferred_entry + (const cooked_index::deferred_entry &entry) const +{ + const cooked_index_entry *parent_entry = nullptr; + for (auto &parent_map_shard : m_vector) + { + auto res = parent_map_shard->find_parent (entry.spec_offset); + if (res != nullptr) + { + parent_entry = res; + break; + } + } + + return parent_entry; +} + +/* See cooked-index.h. */ + +void +cooked_index_vector::handle_deferred_entries () +{ + bool changed; + bool deferred; + do + { + deferred = false; + changed = false; + for (auto &shard : m_vector) + for (auto it = shard->m_deferred_entries->begin (); + it != shard->m_deferred_entries->end (); ) + { + const cooked_index_entry *parent_entry + = find_parent_deferred_entry (*it); + if (parent_entry == &parent_map::deferred) + { + deferred = true; + it++; + continue; + } + shard->resolve_deferred_entry (*it, parent_entry); + it = shard->m_deferred_entries->erase (it); + changed = true; + } + } + while (changed && deferred); + + for (auto &shard : m_vector) + { + shard->m_die_range_map.reset (nullptr); + shard->m_deferred_entries.reset (nullptr); + } +} + void _initialize_cooked_index (); void _initialize_cooked_index () diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index f4abc7a974e..a06d99532ed 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -34,6 +34,7 @@ #include "dwarf2/mapped-index.h" #include "dwarf2/tag.h" #include "gdbsupport/range-chain.h" +#include <unordered_set> struct dwarf2_per_cu_data; @@ -236,19 +237,29 @@ struct cooked_index_entry : public allocate_on_obstack class parent_map { public: + /* A dummy cooked_index_entry to mark that computing the parent has been + deferred. */ + static cooked_index_entry deferred; + /* A helper function to turn a section offset into an address that can be used in a parent_map. */ - static CORE_ADDR form_addr (sect_offset offset, bool is_dwz) + static CORE_ADDR form_addr (sect_offset offset, bool is_dwz, + bool is_debug_types) { CORE_ADDR value = to_underlying (offset); if (is_dwz) value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1); + if (is_debug_types) + value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 2); return value; } /* Find the parent of DIE LOOKUP. */ const cooked_index_entry *find_parent (CORE_ADDR lookup) const { + if (m_deferred.find (lookup) != m_deferred.end ()) + return &parent_map::deferred; + const void *obj = m_parent_map.find (lookup); return static_cast<const cooked_index_entry *> (obj); } @@ -259,12 +270,28 @@ class parent_map { /* Calling set_empty with nullptr is currently not allowed. */ if (parent_entry != nullptr) - m_parent_map.set_empty (start, end, (void *)parent_entry); + { + gdb_assert (parent_entry != &parent_map::deferred); + m_parent_map.set_empty (start, end, (void *)parent_entry); + } + } + + void set_parent_deferred (CORE_ADDR addr) + { + m_deferred.emplace (addr); + } + + void reset_parent_deferred (CORE_ADDR addr) + { + m_deferred.erase (addr); } private: /* An addrmap that maps from section offsets to cooked_index_entry *. */ addrmap_mutable m_parent_map; + + /* DIEs that are deffered. */ + std::unordered_set<CORE_ADDR> m_deferred; }; class cooked_index_vector; @@ -279,9 +306,14 @@ class cooked_index_vector; class cooked_index { public: - cooked_index () = default; DISABLE_COPY_AND_ASSIGN (cooked_index); + cooked_index () + { + m_die_range_map.reset (new parent_map); + m_deferred_entries.reset (new std::vector<deferred_entry>); + } + /* Create a new cooked_index_entry and register it with this object. Entries are owned by this object. The new item is returned. */ const cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag, @@ -325,6 +357,52 @@ class cooked_index for completion, will be returned. */ range find (const std::string &name, bool completing); + /* Find the parent of DIE LOOKUP. */ + const cooked_index_entry * + find_parent (CORE_ADDR lookup) const + { + return m_die_range_map->find_parent (lookup); + } + + /* Set the parent of DIES in range [START, END] to PARENT_ENTRY. */ + void set_parent (CORE_ADDR start, CORE_ADDR end, + const cooked_index_entry *parent_entry) + { + m_die_range_map->set_parent (start, end, parent_entry); + } + + void set_parent_deferred (CORE_ADDR addr) + { + m_die_range_map->set_parent_deferred (addr); + } + + void reset_parent_deferred (CORE_ADDR addr) + { + m_die_range_map->reset_parent_deferred (addr); + } + + /* A single deferred entry. See m_deferred_entries. */ + struct deferred_entry + { + sect_offset die_offset; + const char *name; + CORE_ADDR spec_offset; + dwarf_tag tag; + cooked_index_flag flags; + dwarf2_per_cu_data *per_cu; + dwarf2_per_cu_data *per_cu_2; + }; + + /* Defer creating a cooked_index_entry corresponding to DEFERRED. */ + void defer_entry (deferred_entry de) + { + m_deferred_entries->push_back (de); + } + + /* Variant of add that takes a deferred_entry as parameter. */ + const cooked_index_entry *resolve_deferred_entry + (const deferred_entry &entry, const cooked_index_entry *parent_entry); + private: /* Return the entry that is believed to represent the program's @@ -382,6 +460,20 @@ class cooked_index that the 'get' method is never called on this future, only 'wait'. */ gdb::future<void> m_future; + + /* An addrmap that maps from section offsets (see the form_addr + method) to newly-created entries. See m_deferred_entries to + understand this. */ + std::unique_ptr<parent_map> m_die_range_map; + + /* The generated DWARF can sometimes have the declaration for a + method in a class (or perhaps namespace) scope, with the + definition appearing outside this scope... just one of the many + bad things about DWARF. In order to handle this situation, we + defer certain entries until the end of scanning, at which point + we'll know the containing context of all the DIEs that we might + have scanned. This vector stores these deferred entries. */ + std::unique_ptr<std::vector<deferred_entry>> m_deferred_entries; }; /* The main index of DIEs. The parallel DIE indexers create @@ -459,6 +551,13 @@ class cooked_index_vector : public dwarf_scanner_base private: + /* Find the parent corresponding to deferred entry ENTRY. */ + const cooked_index_entry *find_parent_deferred_entry + (const cooked_index::deferred_entry &entry) const; + + /* Create cooked_index_entries for the deferred entries. */ + void handle_deferred_entries (); + /* The vector of cooked_index objects. This is stored because the entries are stored on the obstacks in those objects. */ vec_type m_vector; diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ff5be8e7dc5..41fa8affcd0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -6672,6 +6672,31 @@ class cooked_index_storage return &m_addrmap; } + /* Find the parent of DIE LOOKUP. */ + const cooked_index_entry *find_parent (CORE_ADDR lookup) + { + return m_index->find_parent (lookup); + } + + /* Set the parent of DIES in range [START, END] to PARENT_ENTRY. */ + void set_parent (CORE_ADDR start, CORE_ADDR end, + const cooked_index_entry *parent_entry) + { + m_index->set_parent (start, end, parent_entry); + } + + /* Set the parent of DIE at ADDR as deferred. */ + void set_parent_deferred (CORE_ADDR addr) + { + m_index->set_parent_deferred (addr); + } + + /* Defer creating a cooked_index_entry corresponding to deferred_entry DE. */ + void defer_entry (cooked_index::deferred_entry de) + { + m_index->defer_entry (de); + } + private: /* Hash function for a cutu_reader. */ @@ -6794,59 +6819,26 @@ class cooked_indexer /* Find the parent of DIE LOOKUP. */ const cooked_index_entry *find_parent (CORE_ADDR lookup) const { - return m_die_range_map.find_parent (lookup); + return m_index_storage->find_parent (lookup); } /* Set the parent of DIES in range [START, END] to PARENT_ENTRY. */ void set_parent (CORE_ADDR start, CORE_ADDR end, const cooked_index_entry *parent_entry) { - m_die_range_map.set_parent (start, end, parent_entry); + m_index_storage->set_parent (start, end, parent_entry); } - /* A single deferred entry. */ - struct deferred_entry - { - sect_offset die_offset; - const char *name; - CORE_ADDR spec_offset; - dwarf_tag tag; - cooked_index_flag flags; - }; - - /* The generated DWARF can sometimes have the declaration for a - method in a class (or perhaps namespace) scope, with the - definition appearing outside this scope... just one of the many - bad things about DWARF. In order to handle this situation, we - defer certain entries until the end of scanning, at which point - we'll know the containing context of all the DIEs that we might - have scanned. This vector stores these deferred entries. */ - std::vector<deferred_entry> m_deferred_entries; - - /* Defer creating a cooked_index_entry corresponding to deferred_entry DE. */ - void defer_entry (const deferred_entry &de) + /* Set the parent of DIE at ADDR as deferred. */ + void set_parent_deferred (CORE_ADDR addr) { - m_deferred_entries.push_back (de); + m_index_storage->set_parent_deferred (addr); } - /* Create a cooked_index_entry corresponding to deferred_entry DE with - parent PARENT_ENTRY. */ - const cooked_index_entry *resolve_deferred_entry - (const deferred_entry &de, const cooked_index_entry *parent_entry) - { - return m_index_storage->add (de.die_offset, de.tag, de.flags, de.name, - parent_entry, m_per_cu); - } - - /* Create cooked_index_entries for the deferred entries. */ - void handle_deferred_entries () + /* Defer creating a cooked_index_entry corresponding to deferred_entry DE. */ + void defer_entry (const cooked_index::deferred_entry &de) { - for (const auto &entry : m_deferred_entries) - { - const cooked_index_entry *parent_entry - = find_parent (entry.spec_offset); - resolve_deferred_entry (entry, parent_entry); - } + m_index_storage->defer_entry (de); } }; @@ -18346,13 +18338,36 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, if (*parent_entry == nullptr) { + gdb_assert (reader->cu->per_cu->is_debug_types + == new_reader->cu->per_cu->is_debug_types); CORE_ADDR addr - = parent_map::form_addr (origin_offset, origin_is_dwz); - if (new_reader->cu == reader->cu - && new_info_ptr > watermark_ptr) - *maybe_defer = addr; + = parent_map::form_addr (origin_offset, origin_is_dwz, + reader->cu->per_cu->is_debug_types); + if (new_reader->cu == reader->cu) + { + /* Intra-CU case. */ + if (new_info_ptr > watermark_ptr) + { + /* Defer because origin is not read yet. */ + *maybe_defer = addr; + } + else + { + auto tmp = find_parent (addr); + if (tmp == &parent_map::deferred) + { + /* Defer because origin is deferred. */ + *maybe_defer = addr; + } + else + *parent_entry = tmp; + } + } else - *parent_entry = find_parent (addr); + { + /* Inter-CU case. */ + *maybe_defer = addr; + } } unsigned int bytes_read; @@ -18475,10 +18490,12 @@ cooked_indexer::recurse (cutu_reader *reader, limit the range to the children of parent_entry. */ CORE_ADDR start = parent_map::form_addr (parent_entry->die_offset + 1, - reader->cu->per_cu->is_dwz); + reader->cu->per_cu->is_dwz, + reader->cu->per_cu->is_debug_types); CORE_ADDR end = parent_map::form_addr (sect_offset (info_ptr - 1 - reader->buffer), - reader->cu->per_cu->is_dwz); + reader->cu->per_cu->is_dwz, + reader->cu->per_cu->is_debug_types); set_parent (start, end, parent_entry); } @@ -18545,9 +18562,16 @@ cooked_indexer::index_dies (cutu_reader *reader, if (name != nullptr) { if (defer != 0) - defer_entry ({ - this_die, name, defer, abbrev->tag, flags - }); + { + CORE_ADDR addr + = parent_map::form_addr (this_die, reader->cu->per_cu->is_dwz, + reader->cu->per_cu->is_debug_types); + set_parent_deferred (addr); + defer_entry ({ + this_die, name, defer, abbrev->tag, flags, m_per_cu, + reader->cu->per_cu + }); + } else this_entry = m_index_storage->add (this_die, abbrev->tag, flags, name, this_parent_entry, @@ -18649,8 +18673,6 @@ cooked_indexer::make_index (cutu_reader *reader) if (!reader->comp_unit_die->has_children) return; index_dies (reader, reader->info_ptr, nullptr, false); - - handle_deferred_entries (); } /* An implementation of quick_symbol_functions for the cooked DWARF -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor