From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 43EAB3858C74 for ; Mon, 13 Feb 2023 14:56:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43EAB3858C74 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 31DEu2I1024843 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 09:56:07 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 31DEu2I1024843 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1676300167; bh=QiIfVXMou1tT3CCz0OiljEH5owsGPKHTkcPBTT4bbCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPIj1Ffhmh2ASxlgUxL7PX2fr2AyyXqiNTgQIVzIcvPXpL0ye/cqee7CdHgpgb/AU pt5WuEdgj1601Pi6G/vqJWa89GAcQJ4xxQBzV8O9TMNpn+/VwuhJ9ltZ8rxLZ4fZob U8vt52BaIDIQjRLYxpqkrvVdJmfALNaNno0nrC4c= Received: from simark.localdomain (unknown [217.28.27.60]) (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 5F12E1E221; Mon, 13 Feb 2023 09:56:02 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/4] gdb/dwarf2: move some things to read.h Date: Mon, 13 Feb 2023 09:55:57 -0500 Message-Id: <20230213145559.46676-3-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230213145559.46676-1-simon.marchi@polymtl.ca> References: <20230213145559.46676-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 13 Feb 2023 14:56:02 +0000 X-Spam-Status: No, score=-3189.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,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: 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 | 211 +++------------------------------------------- gdb/dwarf2/read.h | 206 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+), 198 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d504be58e676..74856ce4a456 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -158,46 +158,6 @@ static int dwarf2_loclist_block_index; /* Size of .debug_rnglists section header for 64-bit DWARF format. */ #define RNGLIST_HEADER_SIZE64 20 -/* This is a view into the index that converts from bytes to an - offset_type, and allows indexing. Unaligned bytes are specifically - allowed here, and handled via unpacking. */ - -class offset_view -{ -public: - offset_view () = default; - - explicit offset_view (gdb::array_view bytes) - : m_bytes (bytes) - { - } - - /* Extract the INDEXth offset_type from the array. */ - offset_type operator[] (size_t index) const - { - const gdb_byte *bytes = &m_bytes[index * sizeof (offset_type)]; - return (offset_type) extract_unsigned_integer (bytes, - sizeof (offset_type), - BFD_ENDIAN_LITTLE); - } - - /* Return the number of offset_types in this array. */ - size_t size () const - { - return m_bytes.size () / sizeof (offset_type); - } - - /* Return true if this view is empty. */ - bool empty () const - { - return m_bytes.empty (); - } - -private: - /* The underlying bytes. */ - gdb::array_view m_bytes; -}; - /* A description of .gdb_index index. The file format is described in a comment by the code that writes the index. */ @@ -920,9 +880,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 +1236,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 +1327,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 +1689,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 +1829,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, @@ -2621,8 +2463,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 +2957,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 +3219,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 +3774,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 +3898,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 +5337,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 +7060,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 +19157,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..476905c23737 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,143 @@ 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. */ + +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. */ + +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. */ + +void +dw_expand_symtabs_matching_file_matcher + (dwarf2_per_objfile *per_objfile, + gdb::function_view file_matcher); + +/* This is a view into the index that converts from bytes to an + offset_type, and allows indexing. Unaligned bytes are specifically + allowed here, and handled via unpacking. */ + +class offset_view +{ +public: + offset_view () = default; + + explicit offset_view (gdb::array_view bytes) + : m_bytes (bytes) + { + } + + /* Extract the INDEXth offset_type from the array. */ + offset_type operator[] (size_t index) const + { + const gdb_byte *bytes = &m_bytes[index * sizeof (offset_type)]; + return (offset_type) extract_unsigned_integer (bytes, + sizeof (offset_type), + BFD_ENDIAN_LITTLE); + } + + /* Return the number of offset_types in this array. */ + size_t size () const + { + return m_bytes.size () / sizeof (offset_type); + } + + /* Return true if this view is empty. */ + bool empty () const + { + return m_bytes.empty (); + } + +private: + /* The underlying bytes. */ + gdb::array_view m_bytes; +}; + +/* Return pointer to string at .debug_str offset STR_OFFSET. */ + +const char *read_indirect_string_at_offset + (dwarf2_per_objfile *per_objfile, LONGEST str_offset); + +/* Allocate a hash table for signatured types. */ + +htab_up allocate_signatured_type_table (); + +/* Initialize the views on all_units. */ + +void finalize_all_units (dwarf2_per_bfd *per_bfd); + +/* Create a quick_file_names hash table. */ + +htab_up create_quick_file_names_table (unsigned int nr_initial_entries); + #endif /* DWARF2READ_H */ -- 2.39.1