aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2024-01-09 12:49:16 -0700
committerTom Tromey <tom@tromey.com>2024-01-09 20:10:06 -0700
commit7e287afdbd62309658908a9a72f78e58281a05e7 (patch)
tree42855be62c8165a77448c15c9ab17aed8cf57c95 /gdb
parent1ae0d437f72c86970f3dbdaed5cff070f3fed904 (diff)
downloadgdb-7e287afdbd62309658908a9a72f78e58281a05e7.zip
gdb-7e287afdbd62309658908a9a72f78e58281a05e7.tar.gz
gdb-7e287afdbd62309658908a9a72f78e58281a05e7.tar.bz2
Fix ASAN failure in DWO code
Simon pointed out that my recent change to the DWO code caused a failure in ASAN testing. The bug here was I updated the code to use a different search type in the hash table; but then did not change the search code to use htab_find_slot_with_hash. Note that this bug would not be possible with my type-safe hash table series, hint, hint. Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/dwarf2/read.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e055371..ca4dda5 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7783,16 +7783,24 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
and DWP files (a file with the DWOs packaged up into one file), we treat
DWP files as having a collection of virtual DWO files. */
+/* A helper function to hash two file names. This is a separate
+ function because the hash table uses a search with a different
+ type. The second file may be NULL. */
+
+static hashval_t
+hash_two_files (const char *one, const char *two)
+{
+ hashval_t hash = htab_hash_string (one);
+ if (two != nullptr)
+ hash += htab_hash_string (two);
+ return hash;
+}
+
static hashval_t
hash_dwo_file (const void *item)
{
const struct dwo_file *dwo_file = (const struct dwo_file *) item;
- hashval_t hash;
-
- hash = htab_hash_string (dwo_file->dwo_name.c_str ());
- if (dwo_file->comp_dir != NULL)
- hash += htab_hash_string (dwo_file->comp_dir);
- return hash;
+ return hash_two_files (dwo_file->dwo_name.c_str (), dwo_file->comp_dir);
}
/* This is used when looking up entries in the DWO hash table. */
@@ -7803,6 +7811,12 @@ struct dwo_file_search
const char *dwo_name;
/* Compilation directory to look for. */
const char *comp_dir;
+
+ /* Return a hash value compatible with the table. */
+ hashval_t hash () const
+ {
+ return hash_two_files (dwo_name, comp_dir);
+ }
};
static int
@@ -7846,8 +7860,9 @@ lookup_dwo_file_slot (dwarf2_per_objfile *per_objfile,
find_entry.dwo_name = dwo_name;
find_entry.comp_dir = comp_dir;
- slot = htab_find_slot (per_objfile->per_bfd->dwo_files.get (), &find_entry,
- INSERT);
+ slot = htab_find_slot_with_hash (per_objfile->per_bfd->dwo_files.get (),
+ &find_entry, find_entry.hash (),
+ INSERT);
return slot;
}