[PATCH v2 08/32] Add new overload of dwarf5_djb_hash
Tom Tromey
tom@tromey.com
Thu Nov 4 18:08:43 GMT 2021
This adds a new overload of dwarf5_djb_hash. This is used in
subsequent patches.
---
gdb/dwarf2/index-common.c | 15 +++++++++++++++
gdb/dwarf2/index-common.h | 4 ++++
2 files changed, 19 insertions(+)
diff --git a/gdb/dwarf2/index-common.c b/gdb/dwarf2/index-common.c
index 1c02730a3fe..4bad82218c2 100644
--- a/gdb/dwarf2/index-common.c
+++ b/gdb/dwarf2/index-common.c
@@ -54,3 +54,18 @@ dwarf5_djb_hash (const char *str_)
hash = hash * 33 + tolower (c);
return hash;
}
+
+/* See dwarf-index-common.h. */
+
+uint32_t
+dwarf5_djb_hash (gdb::string_view str)
+{
+ /* Note: tolower here ignores UTF-8, which isn't fully compliant.
+ See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
+
+ uint32_t hash = 5381;
+ size_t len = str.length ();
+ for (size_t i = 0; i < len; ++i)
+ hash = hash * 33 + tolower (str[i] & 0xff);
+ return hash;
+}
diff --git a/gdb/dwarf2/index-common.h b/gdb/dwarf2/index-common.h
index 86180747533..c800b3a7dea 100644
--- a/gdb/dwarf2/index-common.h
+++ b/gdb/dwarf2/index-common.h
@@ -52,4 +52,8 @@ hashval_t mapped_index_string_hash (int index_version, const void *p);
uint32_t dwarf5_djb_hash (const char *str_);
+/* Symbol name hashing function as specified by DWARF-5. */
+
+uint32_t dwarf5_djb_hash (gdb::string_view str_);
+
#endif /* DWARF_INDEX_COMMON_H */
--
2.31.1
More information about the Gdb-patches
mailing list