diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ada-lang.c | 115 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/scalar_storage.exp | 28 |
3 files changed, 90 insertions, 84 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 9d35440..3f5e707 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -36,7 +36,7 @@ #include "objfiles.h" #include "breakpoint.h" #include "gdbcore.h" -#include "hashtab.h" +#include "gdbsupport/unordered_set.h" #include "gdbsupport/gdb_obstack.h" #include "ada-lang.h" #include "completer.h" @@ -52,6 +52,7 @@ #include "namespace.h" #include "cli/cli-style.h" #include "cli/cli-decode.h" +#include "gdbsupport/string-set.h" #include "value.h" #include "mi/mi-common.h" @@ -349,56 +350,58 @@ struct cache_entry_search { const char *name; domain_search_flags domain; +}; + +/* Hash function for cache entry. */ + +struct cache_entry_hash +{ + using is_transparent = void; + using is_avalanching = void; - hashval_t hash () const + /* This implementation works for both cache_entry and + cache_entry_search. */ + template<typename T> + uint64_t operator() (const T &entry) const noexcept { - /* This must agree with hash_cache_entry, below. */ - return htab_hash_string (name); + return ankerl::unordered_dense::hash<std::string_view> () (entry.name); } }; -/* Hash function for cache_entry. */ +/* Equality function for cache entry. */ -static hashval_t -hash_cache_entry (const void *v) +struct cache_entry_eq { - const cache_entry *entry = (const cache_entry *) v; - return htab_hash_string (entry->name.c_str ()); -} - -/* Equality function for cache_entry. */ + using is_transparent = void; -static int -eq_cache_entry (const void *a, const void *b) -{ - const cache_entry *entrya = (const cache_entry *) a; - const cache_entry_search *entryb = (const cache_entry_search *) b; + /* This implementation works for both cache_entry and + cache_entry_search. */ + template<typename T> + bool operator() (const T &lhs, const cache_entry &rhs) const noexcept + { + return lhs.domain == rhs.domain && lhs.name == rhs.name; + } +}; - return entrya->domain == entryb->domain && entrya->name == entryb->name; -} +using cache_entry_set + = gdb::unordered_set<cache_entry, cache_entry_hash, cache_entry_eq>; /* Key to our per-program-space data. */ -static const registry<program_space>::key<htab, htab_deleter> +static const registry<program_space>::key<cache_entry_set> ada_pspace_data_handle; -/* Return this module's data for the given program space (PSPACE). - If not is found, add a zero'ed one now. - - This function always returns a valid object. */ +/* Return this module's data for the given program space (PSPACE). If + not is found, one is created. This function always returns a valid + object. */ -static htab_t +static cache_entry_set & get_ada_pspace_data (struct program_space *pspace) { - htab_t data = ada_pspace_data_handle.get (pspace); + cache_entry_set *data = ada_pspace_data_handle.get (pspace); if (data == nullptr) - { - data = htab_create_alloc (10, hash_cache_entry, eq_cache_entry, - htab_delete_entry<cache_entry>, - xcalloc, xfree); - ada_pspace_data_handle.set (pspace, data); - } + data = ada_pspace_data_handle.emplace (pspace); - return data; + return *data; } /* Utilities */ @@ -1603,7 +1606,7 @@ ada_decode_tests () storage leak, it should not be significant unless there are massive changes in the set of decoded names in successive versions of a symbol table loaded during a single session. */ -static struct htab *decoded_names_store; +static gdb::string_set decoded_names_store; /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it in the language-specific part of GSYMBOL, if it has not been @@ -1637,13 +1640,7 @@ ada_decode_symbol (const struct general_symbol_info *arg) which case, we put the result on the heap. Since we only decode when needed, we hope this usually does not cause a significant memory leak (FIXME). */ - - char **slot = (char **) htab_find_slot (decoded_names_store, - decoded.c_str (), INSERT); - - if (*slot == NULL) - *slot = xstrdup (decoded.c_str ()); - *resultp = *slot; + *resultp = decoded_names_store.insert (decoded); } } @@ -3950,9 +3947,9 @@ ada_type_match (struct type *ftype, struct type *atype) atype = ada_check_typedef (atype); if (ftype->code () == TYPE_CODE_REF) - ftype = ftype->target_type (); + ftype = ada_check_typedef (ftype->target_type ()); if (atype->code () == TYPE_CODE_REF) - atype = atype->target_type (); + atype = ada_check_typedef (atype->target_type ()); switch (ftype->code ()) { @@ -4695,19 +4692,18 @@ static int lookup_cached_symbol (const char *name, domain_search_flags domain, struct symbol **sym, const struct block **block) { - htab_t tab = get_ada_pspace_data (current_program_space); + cache_entry_set &htab = get_ada_pspace_data (current_program_space); cache_entry_search search; search.name = name; search.domain = domain; - cache_entry *e = (cache_entry *) htab_find_with_hash (tab, &search, - search.hash ()); - if (e == nullptr) + auto iter = htab.find (search); + if (iter == htab.end ()) return 0; if (sym != nullptr) - *sym = e->sym; + *sym = iter->sym; if (block != nullptr) - *block = e->block; + *block = iter->block; return 1; } @@ -4735,21 +4731,8 @@ cache_symbol (const char *name, domain_search_flags domain, return; } - htab_t tab = get_ada_pspace_data (current_program_space); - cache_entry_search search; - search.name = name; - search.domain = domain; - - void **slot = htab_find_slot_with_hash (tab, &search, - search.hash (), INSERT); - - cache_entry *e = new cache_entry; - e->name = name; - e->domain = domain; - e->sym = sym; - e->block = block; - - *slot = e; + cache_entry_set &tab = get_ada_pspace_data (current_program_space); + tab.insert (cache_entry {name, domain, sym, block}); } /* Symbol Lookup */ @@ -14049,10 +14032,6 @@ When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\ DWARF attribute."), NULL, NULL, &maint_set_ada_cmdlist, &maint_show_ada_cmdlist); - decoded_names_store = htab_create_alloc (256, htab_hash_string, - htab_eq_string, - NULL, xcalloc, xfree); - /* The ada-lang observers. */ gdb::observers::new_objfile.attach (ada_new_objfile_observer, "ada-lang"); gdb::observers::all_objfiles_removed.attach (ada_clear_symbol_cache, diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 6e96afe..794c397 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2383,14 +2383,14 @@ read_abbrev_offset (dwarf2_per_objfile *per_objfile, return (sect_offset) read_offset (abfd, info_ptr, offset_size); } -/* A helper for create_debug_types_hash_table. Read types from SECTION +/* A helper for create_dwo_debug_types_hash_table. Read types from SECTION and fill them into DWO_FILE's type unit hash table. It will process only type units, therefore DW_UT_type. */ static void -create_debug_type_hash_table (dwarf2_per_objfile *per_objfile, - dwo_file *dwo_file, dwarf2_section_info *section, - rcuh_kind section_kind) +create_dwo_debug_type_hash_table (dwarf2_per_objfile *per_objfile, + dwo_file *dwo_file, dwarf2_section_info *section, + rcuh_kind section_kind) { struct objfile *objfile = per_objfile->objfile; struct dwarf2_section_info *abbrev_section; @@ -2479,12 +2479,12 @@ create_debug_type_hash_table (dwarf2_per_objfile *per_objfile, Note: This function processes DWO files only, not DWP files. */ static void -create_debug_types_hash_table +create_dwo_debug_types_hash_table (dwarf2_per_objfile *per_objfile, dwo_file *dwo_file, gdb::array_view<dwarf2_section_info> type_sections) { for (dwarf2_section_info §ion : type_sections) - create_debug_type_hash_table (per_objfile, dwo_file, §ion, + create_dwo_debug_type_hash_table (per_objfile, dwo_file, §ion, rcuh_kind::TYPE); } @@ -6308,7 +6308,7 @@ lookup_dwo_file (dwarf2_per_bfd *per_bfd, const char *dwo_name, Note: This function processes DWO files only, not DWP files. */ static void -create_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file) +create_dwo_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file) { dwarf2_per_objfile *per_objfile = cu->per_objfile; struct objfile *objfile = per_objfile->objfile; @@ -6342,6 +6342,12 @@ create_cus_hash_table (dwarf2_cu *cu, dwo_file &dwo_file) if (reader.is_dummy()) continue; + /* DWARF 5 .debug_info.dwo sections may contain some type units. Skip + everything that is not a compile unit. */ + if (const auto ut = reader.cu ()->header.unit_type; + ut != DW_UT_compile && ut != DW_UT_split_compile) + continue; + std::optional<ULONGEST> signature = lookup_dwo_id (reader.cu (), reader.top_level_die ()); if (!signature.has_value ()) @@ -7630,14 +7636,15 @@ open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name, dwarf2_locate_dwo_sections (per_objfile->objfile, dwo_file->dbfd.get (), sec, &dwo_file->sections); - create_cus_hash_table (cu, *dwo_file); + create_dwo_cus_hash_table (cu, *dwo_file); if (cu->header.version < 5) - create_debug_types_hash_table (per_objfile, dwo_file.get (), - dwo_file->sections.types); + create_dwo_debug_types_hash_table (per_objfile, dwo_file.get (), + dwo_file->sections.types); else - create_debug_type_hash_table (per_objfile, dwo_file.get (), - &dwo_file->sections.info, rcuh_kind::COMPILE); + create_dwo_debug_type_hash_table (per_objfile, dwo_file.get (), + &dwo_file->sections.info, + rcuh_kind::COMPILE); dwarf_read_debug_printf ("DWO file found: %s", dwo_name); diff --git a/gdb/testsuite/gdb.ada/scalar_storage.exp b/gdb/testsuite/gdb.ada/scalar_storage.exp index 6b29226..52a85cd 100644 --- a/gdb/testsuite/gdb.ada/scalar_storage.exp +++ b/gdb/testsuite/gdb.ada/scalar_storage.exp @@ -45,10 +45,30 @@ if {![runto "storage.adb:$bp_location"]} { return } -gdb_test "print V_LE" "= \\(value => 126, another_value => 12, color => green\\)" +set re "value => 126, another_value => 12, color => green" # This requires a compiler fix that is in GCC 14. -if { ![gnat_version_compare >= 14] } { - setup_kfail "DW_AT_endianity on enum types" *-*-* +set have_xfail [expr ![gnat_version_compare >= 14]] +set re_color "(red|green|blue|$decimal)" +set re_xfail \ + "value => $decimal, another_value => $decimal, color => $re_color" + +set re_pre [string_to_regexp " = ("] +set re_post [string_to_regexp ")"] +set re $re_pre$re$re_post +set re_xfail $re_pre$re_xfail$re_post + +foreach var { V_LE V_BE } { + gdb_test_multiple "print $var" "" { + -re -wrap $re { + pass $gdb_test_name + } + -re -wrap $re_xfail { + if { $have_xfail } { + xfail $gdb_test_name + } else { + fail $gdb_test_name + } + } + } } -gdb_test "print V_BE" "= \\(value => 126, another_value => 12, color => green\\)" |