From: Simon Marchi Date: Wed, 27 May 2020 15:14:11 +0000 (-0400) Subject: Make mapped_debug_names independent of objfile X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fcf23d5b654b0fc05e99c445ebd471221a290cf4;p=binutils-gdb.git Make mapped_debug_names independent of objfile mapped_debug_names currently has a dwarf2_per_objfile field. Since we want it to become objfile-independent, this field must be removed. This patch removes it, and then arranges for all methods that needed it to accept a dwarf2_per_objfile parameter. This trickles down at various places, like the dw2_debug_names_iterator type. Ultimately, the objfile only seems to be needed because we might need to read a string from the string section. For that, we might need to read in the section, and if it's a relocatable section, the objfile is needed in order to do the relocation. This pattern happens often (that we to pass an objfile only because a section might be read). I think it's a bit ugly, but I don't have a good alternative right now. gdb/ChangeLog: * dwarf2/read.c (struct mapped_index_base) : Add per_objfile parameter. (struct mapped_index) : Likewise. (struct mapped_debug_names): Remove constructor. : Remove field. : Add per_objfile parameter. (mapped_index_base::find_name_components_bounds, mapped_index_base::build_name_components, dw2_expand_symtabs_matching_symbol): Likewise. (class mock_mapped_index) : Likewise. (check_match): Likewise. (check_find_bounds_finds): Likewise. (test_mapped_index_find_name_component_bounds): Update. (CHECK_MATCH): Update. (dw2_expand_symtabs_matching): Update. (class dw2_debug_names_iterator) : Add per_objfile parameter. : Likewise. : New field. (mapped_debug_names::namei_to_name): Add dwarf2_per_objfile parameter. (dw2_debug_names_iterator::find_vec_in_debug_names): Likewise. (dw2_debug_names_iterator::next): Update. (dw2_debug_names_lookup_symbol): Update. (dw2_debug_names_expand_symtabs_for_function): Update. (dw2_debug_names_map_matching_symbols): Update. (dw2_debug_names_expand_symtabs_matching): Update. (dwarf2_read_debug_names): Update. Change-Id: I00ee0d939390d353442675c7d400a261307c57a1 --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 990844b3959..a7f989ec718 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,35 @@ +2020-05-27 Simon Marchi + + * dwarf2/read.c (struct mapped_index_base) : + Add per_objfile parameter. + (struct mapped_index) : Likewise. + (struct mapped_debug_names): Remove constructor. + : Remove field. + : Add per_objfile parameter. + (mapped_index_base::find_name_components_bounds, + mapped_index_base::build_name_components, + dw2_expand_symtabs_matching_symbol): Likewise. + (class mock_mapped_index) : Likewise. + (check_match): Likewise. + (check_find_bounds_finds): Likewise. + (test_mapped_index_find_name_component_bounds): Update. + (CHECK_MATCH): Update. + (dw2_expand_symtabs_matching): Update. + (class dw2_debug_names_iterator) : Add + per_objfile parameter. + : Likewise. + : New field. + (mapped_debug_names::namei_to_name): Add dwarf2_per_objfile + parameter. + (dw2_debug_names_iterator::find_vec_in_debug_names): Likewise. + (dw2_debug_names_iterator::next): Update. + (dw2_debug_names_lookup_symbol): Update. + (dw2_debug_names_expand_symtabs_for_function): Update. + (dw2_debug_names_map_matching_symbols): Update. + (dw2_debug_names_expand_symtabs_matching): Update. + (dwarf2_read_debug_names): Update. + 2020-05-27 Simon Marchi * dwarf2/read.h (struct dwarf2_cu): Forward-declare. diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 6319d4b2859..df15068269c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -164,7 +164,8 @@ struct mapped_index_base virtual size_t symbol_name_count () const = 0; /* Get the name of the symbol at IDX in the symbol table. */ - virtual const char *symbol_name_at (offset_type idx) const = 0; + virtual const char *symbol_name_at + (offset_type idx, dwarf2_per_objfile *per_objfile) const = 0; /* Return whether the name at IDX in the symbol table should be ignored. */ @@ -175,7 +176,7 @@ struct mapped_index_base /* Build the symbol name component sorted vector, if we haven't yet. */ - void build_name_components (); + void build_name_components (dwarf2_per_objfile *per_objfile); /* Returns the lower (inclusive) and upper (exclusive) bounds of the possible matches for LN_NO_PARAMS in the name component @@ -183,7 +184,8 @@ struct mapped_index_base std::pair::const_iterator, std::vector::const_iterator> find_name_components_bounds (const lookup_name_info &ln_no_params, - enum language lang) const; + enum language lang, + dwarf2_per_objfile *per_objfile) const; /* Prevent deleting/destroying via a base class pointer. */ protected: @@ -221,7 +223,8 @@ struct mapped_index final : public mapped_index_base /* Convenience method to get at the name of the symbol at IDX in the symbol table. */ - const char *symbol_name_at (offset_type idx) const override + const char *symbol_name_at + (offset_type idx, dwarf2_per_objfile *per_objfile) const override { return this->constant_pool + MAYBE_SWAP (this->symbol_table[idx].name); } size_t symbol_name_count () const override @@ -232,11 +235,6 @@ struct mapped_index final : public mapped_index_base Uninitialized map has CU_COUNT 0. */ struct mapped_debug_names final : public mapped_index_base { - mapped_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile_) - : dwarf2_per_objfile (dwarf2_per_objfile_) - {} - - struct dwarf2_per_objfile *dwarf2_per_objfile; bfd_endian dwarf5_byte_order; bool dwarf5_is_dwarf64; bool augmentation_is_gdb; @@ -268,13 +266,15 @@ struct mapped_debug_names final : public mapped_index_base std::unordered_map abbrev_map; - const char *namei_to_name (uint32_t namei) const; + const char *namei_to_name + (uint32_t namei, dwarf2_per_objfile *per_objfile) const; /* Implementation of the mapped_index_base virtual interface, for the name_components cache. */ - const char *symbol_name_at (offset_type idx) const override - { return namei_to_name (idx); } + const char *symbol_name_at + (offset_type idx, dwarf2_per_objfile *per_objfile) const override + { return namei_to_name (idx, per_objfile); } size_t symbol_name_count () const override { return this->name_count; } @@ -3691,7 +3691,8 @@ dw2_expand_symtabs_matching_symbol const lookup_name_info &lookup_name_in, gdb::function_view symbol_matcher, enum search_domain kind, - gdb::function_view match_callback); + gdb::function_view match_callback, + dwarf2_per_objfile *per_objfile); static void dw2_expand_symtabs_matching_one @@ -3741,7 +3742,7 @@ dw2_map_matching_symbols dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile, nullptr, nullptr); return true; - }); + }, dwarf2_per_objfile); } else { @@ -3840,7 +3841,8 @@ make_sort_after_prefix_name (const char *search_name) std::pair::const_iterator, std::vector::const_iterator> mapped_index_base::find_name_components_bounds - (const lookup_name_info &lookup_name_without_params, language lang) const + (const lookup_name_info &lookup_name_without_params, language lang, + dwarf2_per_objfile *per_objfile) const { auto *name_cmp = this->name_components_casing == case_sensitive_on ? strcmp : strcasecmp; @@ -3853,7 +3855,7 @@ mapped_index_base::find_name_components_bounds auto lookup_compare_lower = [&] (const name_component &elem, const char *name) { - const char *elem_qualified = this->symbol_name_at (elem.idx); + const char *elem_qualified = this->symbol_name_at (elem.idx, per_objfile); const char *elem_name = elem_qualified + elem.name_offset; return name_cmp (elem_name, name) < 0; }; @@ -3863,7 +3865,7 @@ mapped_index_base::find_name_components_bounds auto lookup_compare_upper = [&] (const char *name, const name_component &elem) { - const char *elem_qualified = this->symbol_name_at (elem.idx); + const char *elem_qualified = this->symbol_name_at (elem.idx, per_objfile); const char *elem_name = elem_qualified + elem.name_offset; return name_cmp (name, elem_name) < 0; }; @@ -3912,7 +3914,7 @@ mapped_index_base::find_name_components_bounds /* See declaration. */ void -mapped_index_base::build_name_components () +mapped_index_base::build_name_components (dwarf2_per_objfile *per_objfile) { if (!this->name_components.empty ()) return; @@ -3930,7 +3932,7 @@ mapped_index_base::build_name_components () if (this->symbol_name_slot_invalid (idx)) continue; - const char *name = this->symbol_name_at (idx); + const char *name = this->symbol_name_at (idx, per_objfile); /* Add each name component to the name component table. */ unsigned int previous_len = 0; @@ -3968,8 +3970,10 @@ mapped_index_base::build_name_components () auto name_comp_compare = [&] (const name_component &left, const name_component &right) { - const char *left_qualified = this->symbol_name_at (left.idx); - const char *right_qualified = this->symbol_name_at (right.idx); + const char *left_qualified + = this->symbol_name_at (left.idx, per_objfile); + const char *right_qualified + = this->symbol_name_at (right.idx, per_objfile); const char *left_name = left_qualified + left.name_offset; const char *right_name = right_qualified + right.name_offset; @@ -3995,14 +3999,15 @@ dw2_expand_symtabs_matching_symbol const lookup_name_info &lookup_name_in, gdb::function_view symbol_matcher, enum search_domain kind, - gdb::function_view match_callback) + gdb::function_view match_callback, + dwarf2_per_objfile *per_objfile) { lookup_name_info lookup_name_without_params = lookup_name_in.make_ignore_params (); /* Build the symbol name component sorted vector, if we haven't yet. */ - index.build_name_components (); + index.build_name_components (per_objfile); /* The same symbol may appear more than once in the range though. E.g., if we're looking for symbols that complete "w", and we have @@ -4052,14 +4057,15 @@ dw2_expand_symtabs_matching_symbol auto bounds = index.find_name_components_bounds (lookup_name_without_params, - lang_e); + lang_e, per_objfile); /* Now for each symbol name in range, check to see if we have a name match, and if so, call the MATCH_CALLBACK callback. */ for (; bounds.first != bounds.second; ++bounds.first) { - const char *qualified = index.symbol_name_at (bounds.first->idx); + const char *qualified + = index.symbol_name_at (bounds.first->idx, per_objfile); if (!name_matcher (qualified, lookup_name_without_params, NULL) || (symbol_matcher != NULL && !symbol_matcher (qualified))) @@ -4112,7 +4118,8 @@ public: } /* Get the name of the symbol at IDX in the symbol table. */ - const char *symbol_name_at (offset_type idx) const override + const char *symbol_name_at + (offset_type idx, dwarf2_per_objfile *per_objfile) const override { return m_symbol_table[idx]; } @@ -4142,7 +4149,8 @@ check_match (const char *file, int line, mock_mapped_index &mock_index, const char *name, symbol_name_match_type match_type, bool completion_mode, - std::initializer_list expected_list) + std::initializer_list expected_list, + dwarf2_per_objfile *per_objfile) { lookup_name_info lookup_name (name, match_type, completion_mode); @@ -4167,14 +4175,14 @@ check_match (const char *file, int line, NULL, ALL_DOMAIN, [&] (offset_type idx) { - const char *matched_name = mock_index.symbol_name_at (idx); + const char *matched_name = mock_index.symbol_name_at (idx, per_objfile); const char *expected_str = expected_it == expected_end ? NULL : *expected_it++; if (expected_str == NULL || strcmp (expected_str, matched_name) != 0) mismatch (expected_str, matched_name); return true; - }); + }, per_objfile); const char *expected_str = expected_it == expected_end ? NULL : *expected_it++; @@ -4235,13 +4243,15 @@ static const char *test_symbols[] = { static bool check_find_bounds_finds (mapped_index_base &index, const char *search_name, - gdb::array_view expected_syms) + gdb::array_view expected_syms, + dwarf2_per_objfile *per_objfile) { lookup_name_info lookup_name (search_name, symbol_name_match_type::FULL, true); auto bounds = index.find_name_components_bounds (lookup_name, - language_cplus); + language_cplus, + per_objfile); size_t distance = std::distance (bounds.first, bounds.second); if (distance != expected_syms.size ()) @@ -4250,7 +4260,7 @@ check_find_bounds_finds (mapped_index_base &index, for (size_t exp_elem = 0; exp_elem < distance; exp_elem++) { auto nc_elem = bounds.first + exp_elem; - const char *qualified = index.symbol_name_at (nc_elem->idx); + const char *qualified = index.symbol_name_at (nc_elem->idx, per_objfile); if (strcmp (qualified, expected_syms[exp_elem]) != 0) return false; } @@ -4266,7 +4276,7 @@ test_mapped_index_find_name_component_bounds () { mock_mapped_index mock_index (test_symbols); - mock_index.build_name_components (); + mock_index.build_name_components (NULL /* per_objfile */); /* Test the lower-level mapped_index::find_name_component_bounds method in completion mode. */ @@ -4276,8 +4286,9 @@ test_mapped_index_find_name_component_bounds () "t1_func1", }; - SELF_CHECK (check_find_bounds_finds (mock_index, - "t1_func", expected_syms)); + SELF_CHECK (check_find_bounds_finds + (mock_index, "t1_func", expected_syms, + NULL /* per_objfile */)); } /* Check that the increment-last-char in the name matching algorithm @@ -4287,14 +4298,15 @@ test_mapped_index_find_name_component_bounds () "\377", "\377\377123", }; - SELF_CHECK (check_find_bounds_finds (mock_index, - "\377", expected_syms1)); + SELF_CHECK (check_find_bounds_finds + (mock_index, "\377", expected_syms1, NULL /* per_objfile */)); static const char *expected_syms2[] = { "\377\377123", }; - SELF_CHECK (check_find_bounds_finds (mock_index, - "\377\377", expected_syms2)); + SELF_CHECK (check_find_bounds_finds + (mock_index, "\377\377", expected_syms2, + NULL /* per_objfile */)); } } @@ -4320,7 +4332,7 @@ test_dw2_expand_symtabs_matching_symbol () any_mismatch |= !check_match (__FILE__, __LINE__, \ mock_index, \ NAME, MATCH_TYPE, COMPLETION_MODE, \ - EXPECTED_LIST) + EXPECTED_LIST, NULL) /* Identity checks. */ for (const char *sym : test_symbols) @@ -4743,7 +4755,7 @@ dw2_expand_symtabs_matching dw2_expand_marked_cus (dwarf2_per_objfile, idx, file_matcher, expansion_notify, kind); return true; - }); + }, dwarf2_per_objfile); } /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific @@ -5170,9 +5182,8 @@ create_cus_from_debug_names (dwarf2_per_bfd *per_bfd, static bool dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile) { - std::unique_ptr map - (new mapped_debug_names (dwarf2_per_objfile)); - mapped_debug_names dwz_map (dwarf2_per_objfile); + std::unique_ptr map (new mapped_debug_names); + mapped_debug_names dwz_map; struct objfile *objfile = dwarf2_per_objfile->objfile; if (!read_debug_names_from_section (objfile, objfile_name (objfile), @@ -5234,23 +5245,26 @@ public: dw2_debug_names_iterator (const mapped_debug_names &map, gdb::optional block_index, domain_enum domain, - const char *name) + const char *name, dwarf2_per_objfile *per_objfile) : m_map (map), m_block_index (block_index), m_domain (domain), - m_addr (find_vec_in_debug_names (map, name)) + m_addr (find_vec_in_debug_names (map, name, per_objfile)), + m_per_objfile (per_objfile) {} dw2_debug_names_iterator (const mapped_debug_names &map, - search_domain search, uint32_t namei) + search_domain search, uint32_t namei, dwarf2_per_objfile *per_objfile) : m_map (map), m_search (search), - m_addr (find_vec_in_debug_names (map, namei)) + m_addr (find_vec_in_debug_names (map, namei, per_objfile)), + m_per_objfile (per_objfile) {} dw2_debug_names_iterator (const mapped_debug_names &map, block_enum block_index, domain_enum domain, - uint32_t namei) + uint32_t namei, dwarf2_per_objfile *per_objfile) : m_map (map), m_block_index (block_index), m_domain (domain), - m_addr (find_vec_in_debug_names (map, namei)) + m_addr (find_vec_in_debug_names (map, namei, per_objfile)), + m_per_objfile (per_objfile) {} /* Return the next matching CU or NULL if there are no more. */ @@ -5258,9 +5272,9 @@ public: private: static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map, - const char *name); + const char *name, dwarf2_per_objfile *per_objfile); static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map, - uint32_t namei); + uint32_t namei, dwarf2_per_objfile *per_objfile); /* The internalized form of .debug_names. */ const mapped_debug_names &m_map; @@ -5276,10 +5290,13 @@ private: /* The list of CUs from the index entry of the symbol, or NULL if not found. */ const gdb_byte *m_addr; + + dwarf2_per_objfile *m_per_objfile; }; const char * -mapped_debug_names::namei_to_name (uint32_t namei) const +mapped_debug_names::namei_to_name + (uint32_t namei, dwarf2_per_objfile *dwarf2_per_objfile) const { const ULONGEST namei_string_offs = extract_unsigned_integer ((name_table_string_offs_reordered @@ -5296,7 +5313,7 @@ mapped_debug_names::namei_to_name (uint32_t namei) const const gdb_byte * dw2_debug_names_iterator::find_vec_in_debug_names - (const mapped_debug_names &map, const char *name) + (const mapped_debug_names &map, const char *name, dwarf2_per_objfile *per_objfile) { int (*cmp) (const char *, const char *); @@ -5332,7 +5349,7 @@ dw2_debug_names_iterator::find_vec_in_debug_names complaint (_("Wrong .debug_names with name index %u but name_count=%u " "[in module %s]"), namei, map.name_count, - objfile_name (map.dwarf2_per_objfile->objfile)); + objfile_name (per_objfile->objfile)); return NULL; } @@ -5347,7 +5364,7 @@ dw2_debug_names_iterator::find_vec_in_debug_names if (full_hash == namei_full_hash) { - const char *const namei_string = map.namei_to_name (namei); + const char *const namei_string = map.namei_to_name (namei, per_objfile); #if 0 /* An expensive sanity check. */ if (namei_full_hash != dwarf5_djb_hash (namei_string)) @@ -5377,14 +5394,14 @@ dw2_debug_names_iterator::find_vec_in_debug_names const gdb_byte * dw2_debug_names_iterator::find_vec_in_debug_names - (const mapped_debug_names &map, uint32_t namei) + (const mapped_debug_names &map, uint32_t namei, dwarf2_per_objfile *per_objfile) { if (namei >= map.name_count) { complaint (_("Wrong .debug_names with name index %u but name_count=%u " "[in module %s]"), namei, map.name_count, - objfile_name (map.dwarf2_per_objfile->objfile)); + objfile_name (per_objfile->objfile)); return NULL; } @@ -5403,8 +5420,8 @@ dw2_debug_names_iterator::next () if (m_addr == NULL) return NULL; - struct dwarf2_per_objfile *dwarf2_per_objfile = m_map.dwarf2_per_objfile; - struct objfile *objfile = dwarf2_per_objfile->objfile; + dwarf2_per_bfd *per_bfd = m_per_objfile->per_bfd; + struct objfile *objfile = m_per_objfile->objfile; bfd *const abfd = objfile->obfd; again: @@ -5467,33 +5484,33 @@ dw2_debug_names_iterator::next () { case DW_IDX_compile_unit: /* Don't crash on bad data. */ - if (ull >= dwarf2_per_objfile->per_bfd->all_comp_units.size ()) + if (ull >= m_per_objfile->per_bfd->all_comp_units.size ()) { complaint (_(".debug_names entry has bad CU index %s" " [in module %s]"), pulongest (ull), - objfile_name (dwarf2_per_objfile->objfile)); + objfile_name (objfile)); continue; } - per_cu = dwarf2_per_objfile->per_bfd->get_cutu (ull); + per_cu = per_bfd->get_cutu (ull); break; case DW_IDX_type_unit: /* Don't crash on bad data. */ - if (ull >= dwarf2_per_objfile->per_bfd->all_type_units.size ()) + if (ull >= per_bfd->all_type_units.size ()) { complaint (_(".debug_names entry has bad TU index %s" " [in module %s]"), pulongest (ull), - objfile_name (dwarf2_per_objfile->objfile)); + objfile_name (objfile)); continue; } - per_cu = &dwarf2_per_objfile->per_bfd->get_tu (ull)->per_cu; + per_cu = &per_bfd->get_tu (ull)->per_cu; break; case DW_IDX_die_offset: /* In a per-CU index (as opposed to a per-module index), index entries without CU attribute implicitly refer to the single CU. */ if (per_cu == NULL) - per_cu = dwarf2_per_objfile->per_bfd->get_cu (0); + per_cu = per_bfd->get_cu (0); break; case DW_IDX_GNU_internal: if (!m_map.augmentation_is_gdb) @@ -5509,7 +5526,7 @@ dw2_debug_names_iterator::next () } /* Skip if already read in. */ - if (dwarf2_per_objfile->symtab_set_p (per_cu)) + if (m_per_objfile->symtab_set_p (per_cu)) goto again; /* Check static vs global. */ @@ -5634,7 +5651,8 @@ dw2_debug_names_lookup_symbol (struct objfile *objfile, block_enum block_index, } const auto &map = *mapp; - dw2_debug_names_iterator iter (map, block_index, domain, name); + dw2_debug_names_iterator iter (map, block_index, domain, name, + dwarf2_per_objfile); struct compunit_symtab *stab_best = NULL; struct dwarf2_per_cu_data *per_cu; @@ -5698,7 +5716,8 @@ dw2_debug_names_expand_symtabs_for_function (struct objfile *objfile, { const mapped_debug_names &map = *dwarf2_per_objfile->per_bfd->debug_names_table; - dw2_debug_names_iterator iter (map, {}, VAR_DOMAIN, func_name); + dw2_debug_names_iterator iter (map, {}, VAR_DOMAIN, func_name, + dwarf2_per_objfile); struct dwarf2_per_cu_data *per_cu; while ((per_cu = iter.next ()) != NULL) @@ -5737,14 +5756,15 @@ dw2_debug_names_map_matching_symbols { /* The name was matched, now expand corresponding CUs that were marked. */ - dw2_debug_names_iterator iter (map, block_kind, domain, namei); + dw2_debug_names_iterator iter (map, block_kind, domain, namei, + dwarf2_per_objfile); struct dwarf2_per_cu_data *per_cu; while ((per_cu = iter.next ()) != NULL) dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile, nullptr, nullptr); return true; - }); + }, dwarf2_per_objfile); /* It's a shame we couldn't do this inside the dw2_expand_symtabs_matching_symbol callback, but that skips CUs @@ -5802,14 +5822,14 @@ dw2_debug_names_expand_symtabs_matching { /* The name was matched, now expand corresponding CUs that were marked. */ - dw2_debug_names_iterator iter (map, kind, namei); + dw2_debug_names_iterator iter (map, kind, namei, dwarf2_per_objfile); struct dwarf2_per_cu_data *per_cu; while ((per_cu = iter.next ()) != NULL) dw2_expand_symtabs_matching_one (per_cu, dwarf2_per_objfile, file_matcher, expansion_notify); return true; - }); + }, dwarf2_per_objfile); } const struct quick_symbol_functions dwarf2_debug_names_functions =