From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5FD6C385841C for ; Tue, 14 Feb 2023 19:55:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FD6C385841C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com Received: from smarchi-efficios.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id BE3841E110; Tue, 14 Feb 2023 14:55:58 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 1/3] gdb/dwarf2: move some things to read.h Date: Tue, 14 Feb 2023 14:55:56 -0500 Message-Id: <20230214195558.341695-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3497.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Simon Marchi New in v2: - do not move offset_view - move read_addrmap_from_aranges and create_cu_from_index_list in this patch, instead of in subsequent patches - fix formatting of declarations, add extern keyword The following 2 patches move .gdb_index and .debug_names reading code to their own file. Prepare this by exposing some things used by that code to read.h. Change-Id: If8ef135758a2ff0ab3b765cc92596da8189f3bbd --- gdb/dwarf2/read.c | 175 ++++----------------------------------------- gdb/dwarf2/read.h | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+), 160 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e750c1c094aa..96e907b1d79b 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -920,9 +920,6 @@ static const char *read_indirect_string (dwarf2_per_objfile *per_objfile, bfd *, const gdb_byte *, const struct comp_unit_head *, unsigned int *); -static const char *read_indirect_string_at_offset - (dwarf2_per_objfile *per_objfile, LONGEST str_offset); - static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, const gdb_byte *, unsigned int *); @@ -1279,8 +1276,6 @@ static const char *compute_include_file_name const file_and_directory &cu_info, std::string &name_holder); -static htab_up allocate_signatured_type_table (); - static htab_up allocate_dwo_unit_table (); static struct dwo_unit *lookup_dwo_unit_in_dwp @@ -1372,75 +1367,6 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs) && ofs_lhs->offset_in_dwz == ofs_rhs->offset_in_dwz); } - - -/* An iterator for all_units that is based on index. This - approach makes it possible to iterate over all_units safely, - when some caller in the loop may add new units. */ - -class all_units_iterator -{ -public: - - all_units_iterator (dwarf2_per_bfd *per_bfd, bool start) - : m_per_bfd (per_bfd), - m_index (start ? 0 : per_bfd->all_units.size ()) - { - } - - all_units_iterator &operator++ () - { - ++m_index; - return *this; - } - - dwarf2_per_cu_data *operator* () const - { - return m_per_bfd->get_cu (m_index); - } - - bool operator== (const all_units_iterator &other) const - { - return m_index == other.m_index; - } - - - bool operator!= (const all_units_iterator &other) const - { - return m_index != other.m_index; - } - -private: - - dwarf2_per_bfd *m_per_bfd; - size_t m_index; -}; - -/* A range adapter for the all_units_iterator. */ -class all_units_range -{ -public: - - all_units_range (dwarf2_per_bfd *per_bfd) - : m_per_bfd (per_bfd) - { - } - - all_units_iterator begin () - { - return all_units_iterator (m_per_bfd, true); - } - - all_units_iterator end () - { - return all_units_iterator (m_per_bfd, false); - } - -private: - - dwarf2_per_bfd *m_per_bfd; -}; - /* See declaration. */ dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names, @@ -1803,50 +1729,6 @@ struct quick_file_names const char **real_names; }; -struct dwarf2_base_index_functions : public quick_symbol_functions -{ - bool has_symbols (struct objfile *objfile) override; - - bool has_unexpanded_symtabs (struct objfile *objfile) override; - - struct symtab *find_last_source_symtab (struct objfile *objfile) override; - - void forget_cached_source_info (struct objfile *objfile) override; - - enum language lookup_global_symbol_language (struct objfile *objfile, - const char *name, - domain_enum domain, - bool *symbol_found_p) override - { - *symbol_found_p = false; - return language_unknown; - } - - void print_stats (struct objfile *objfile, bool print_bcache) override; - - void expand_all_symtabs (struct objfile *objfile) override; - - /* A helper function that finds the per-cu object from an "adjusted" - PC -- a PC with the base text offset removed. */ - virtual dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd, - CORE_ADDR adjusted_pc); - - struct compunit_symtab *find_pc_sect_compunit_symtab - (struct objfile *objfile, struct bound_minimal_symbol msymbol, - CORE_ADDR pc, struct obj_section *section, int warn_if_readin) - override final; - - struct compunit_symtab *find_compunit_symtab_by_address - (struct objfile *objfile, CORE_ADDR address) override - { - return nullptr; - } - - void map_symbol_filenames (struct objfile *objfile, - gdb::function_view fun, - bool need_fullname) override; -}; - /* With OBJF_READNOW, the DWARF reader expands all CUs immediately. It's handy in this case to have an empty implementation of the quick symbol functions, to avoid special cases in the rest of the @@ -1987,9 +1869,9 @@ eq_file_name_entry (const void *a, const void *b) return eq_stmt_list_entry (&ea->hash, &eb->hash); } -/* Create a quick_file_names hash table. */ +/* See read.h. */ -static htab_up +htab_up create_quick_file_names_table (unsigned int nr_initial_entries) { return htab_up (htab_create_alloc (nr_initial_entries, @@ -2106,7 +1988,7 @@ dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature) /* Return a new dwarf2_per_cu_data allocated on the per-bfd obstack, and constructed with the specified field values. */ -static dwarf2_per_cu_data_up +dwarf2_per_cu_data_up create_cu_from_index_list (dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, int is_dwz, @@ -2311,7 +2193,7 @@ create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile, to populate given addrmap. Returns true on success, false on failure. */ -static bool +bool read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section, addrmap *mutable_map) @@ -2621,8 +2503,6 @@ to use the section anyway."), return 1; } -static void finalize_all_units (dwarf2_per_bfd *per_bfd); - /* Callback types for dwarf2_read_gdb_index. */ typedef gdb::function_view @@ -3117,21 +2997,6 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile) } } -static bool -dw2_expand_symtabs_matching_symbol - (mapped_index_base &index, - const lookup_name_info &lookup_name_in, - gdb::function_view symbol_matcher, - gdb::function_view match_callback, - dwarf2_per_objfile *per_objfile); - -static bool -dw2_expand_symtabs_matching_one - (dwarf2_per_cu_data *per_cu, - dwarf2_per_objfile *per_objfile, - gdb::function_view file_matcher, - gdb::function_view expansion_notify); - void dwarf2_gdb_index::expand_matching_symbols (struct objfile *objfile, @@ -3394,14 +3259,9 @@ mapped_index_base::build_name_components (dwarf2_per_objfile *per_objfile) name_comp_compare); } -/* Helper for dw2_expand_symtabs_matching that works with a - mapped_index_base instead of the containing objfile. This is split - to a separate function in order to be able to unit test the - name_components matching using a mock mapped_index_base. For each - symbol name that matches, calls MATCH_CALLBACK, passing it the - symbol's index in the mapped_index_base symbol table. */ +/* See read.h. */ -static bool +bool dw2_expand_symtabs_matching_symbol (mapped_index_base &index, const lookup_name_info &lookup_name_in, @@ -3954,12 +3814,9 @@ run_test () #endif /* GDB_SELF_TEST */ -/* If FILE_MATCHER is NULL or if PER_CU has - dwarf2_per_cu_quick_data::MARK set (see - dw_expand_symtabs_matching_file_matcher), expand the CU and call - EXPANSION_NOTIFY on it. */ +/* See read.h. */ -static bool +bool dw2_expand_symtabs_matching_one (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, @@ -4081,11 +3938,9 @@ dw2_expand_marked_cus return true; } -/* If FILE_MATCHER is non-NULL, set all the - dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE - that match FILE_MATCHER. */ +/* See read.h. */ -static void +void dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile *per_objfile, gdb::function_view file_matcher) @@ -5522,9 +5377,9 @@ eq_signatured_type (const void *item_lhs, const void *item_rhs) return lhs->signature == rhs->signature; } -/* Allocate a hash table for signatured types. */ +/* See read.h. */ -static htab_up +htab_up allocate_signatured_type_table () { return htab_up (htab_create_alloc (41, @@ -7245,7 +7100,7 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile, /* Initialize the views on all_units. */ -static void +void finalize_all_units (dwarf2_per_bfd *per_bfd) { size_t nr_tus = per_bfd->tu_stats.nr_tus; @@ -19342,9 +19197,9 @@ read_attribute (const struct die_reader_specs *reader, abbrev->implicit_const, info_ptr); } -/* Return pointer to string at .debug_str offset STR_OFFSET. */ +/* See read.h. */ -static const char * +const char * read_indirect_string_at_offset (dwarf2_per_objfile *per_objfile, LONGEST str_offset) { diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 8045a57563f9..0e6853ea2f49 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -558,6 +558,73 @@ struct dwarf2_per_bfd struct addrmap *index_addrmap = nullptr; }; +/* An iterator for all_units that is based on index. This + approach makes it possible to iterate over all_units safely, + when some caller in the loop may add new units. */ + +class all_units_iterator +{ +public: + + all_units_iterator (dwarf2_per_bfd *per_bfd, bool start) + : m_per_bfd (per_bfd), + m_index (start ? 0 : per_bfd->all_units.size ()) + { + } + + all_units_iterator &operator++ () + { + ++m_index; + return *this; + } + + dwarf2_per_cu_data *operator* () const + { + return m_per_bfd->get_cu (m_index); + } + + bool operator== (const all_units_iterator &other) const + { + return m_index == other.m_index; + } + + + bool operator!= (const all_units_iterator &other) const + { + return m_index != other.m_index; + } + +private: + + dwarf2_per_bfd *m_per_bfd; + size_t m_index; +}; + +/* A range adapter for the all_units_iterator. */ +class all_units_range +{ +public: + + all_units_range (dwarf2_per_bfd *per_bfd) + : m_per_bfd (per_bfd) + { + } + + all_units_iterator begin () + { + return all_units_iterator (m_per_bfd, true); + } + + all_units_iterator end () + { + return all_units_iterator (m_per_bfd, false); + } + +private: + + dwarf2_per_bfd *m_per_bfd; +}; + /* This is the per-objfile data associated with a type_unit_group. */ struct type_unit_group_unshareable @@ -764,4 +831,115 @@ extern void dwarf2_get_section_info (struct objfile *, /* Return true if the producer of the inferior is clang. */ extern bool producer_is_clang (struct dwarf2_cu *cu); +/* Interface for DWARF indexing methods. */ + +struct dwarf2_base_index_functions : public quick_symbol_functions +{ + bool has_symbols (struct objfile *objfile) override; + + bool has_unexpanded_symtabs (struct objfile *objfile) override; + + struct symtab *find_last_source_symtab (struct objfile *objfile) override; + + void forget_cached_source_info (struct objfile *objfile) override; + + enum language lookup_global_symbol_language (struct objfile *objfile, + const char *name, + domain_enum domain, + bool *symbol_found_p) override + { + *symbol_found_p = false; + return language_unknown; + } + + void print_stats (struct objfile *objfile, bool print_bcache) override; + + void expand_all_symtabs (struct objfile *objfile) override; + + /* A helper function that finds the per-cu object from an "adjusted" + PC -- a PC with the base text offset removed. */ + virtual dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd, + CORE_ADDR adjusted_pc); + + struct compunit_symtab *find_pc_sect_compunit_symtab + (struct objfile *objfile, struct bound_minimal_symbol msymbol, + CORE_ADDR pc, struct obj_section *section, int warn_if_readin) + override final; + + struct compunit_symtab *find_compunit_symtab_by_address + (struct objfile *objfile, CORE_ADDR address) override + { + return nullptr; + } + + void map_symbol_filenames (struct objfile *objfile, + gdb::function_view fun, + bool need_fullname) override; +}; + +/* If FILE_MATCHER is NULL or if PER_CU has + dwarf2_per_cu_quick_data::MARK set (see + dw_expand_symtabs_matching_file_matcher), expand the CU and call + EXPANSION_NOTIFY on it. */ + +extern bool dw2_expand_symtabs_matching_one + (dwarf2_per_cu_data *per_cu, + dwarf2_per_objfile *per_objfile, + gdb::function_view file_matcher, + gdb::function_view expansion_notify); + +/* Helper for dw2_expand_symtabs_matching that works with a + mapped_index_base instead of the containing objfile. This is split + to a separate function in order to be able to unit test the + name_components matching using a mock mapped_index_base. For each + symbol name that matches, calls MATCH_CALLBACK, passing it the + symbol's index in the mapped_index_base symbol table. */ + +extern bool dw2_expand_symtabs_matching_symbol + (mapped_index_base &index, + const lookup_name_info &lookup_name_in, + gdb::function_view symbol_matcher, + gdb::function_view match_callback, + dwarf2_per_objfile *per_objfile); + +/* If FILE_MATCHER is non-NULL, set all the + dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE + that match FILE_MATCHER. */ + +extern void dw_expand_symtabs_matching_file_matcher + (dwarf2_per_objfile *per_objfile, + gdb::function_view file_matcher); + +/* Return pointer to string at .debug_str offset STR_OFFSET. */ + +extern const char *read_indirect_string_at_offset + (dwarf2_per_objfile *per_objfile, LONGEST str_offset); + +/* Allocate a hash table for signatured types. */ + +extern htab_up allocate_signatured_type_table (); + +/* Return a new dwarf2_per_cu_data allocated on the per-bfd + obstack, and constructed with the specified field values. */ + +extern dwarf2_per_cu_data_up create_cu_from_index_list + (dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, + int is_dwz, sect_offset sect_off, ULONGEST length); + +/* Initialize the views on all_units. */ + +extern void finalize_all_units (dwarf2_per_bfd *per_bfd); + +/* Create a quick_file_names hash table. */ + +extern htab_up create_quick_file_names_table (unsigned int nr_initial_entries); + +/* Read the address map data from DWARF-5 .debug_aranges, and use it + to populate given addrmap. Returns true on success, false on + failure. */ + +extern bool read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, + dwarf2_section_info *section, + addrmap *mutable_map); + #endif /* DWARF2READ_H */ -- 2.39.1