Replace HashStringUsingDJB with llvm::djbHash
Summary:
The llvm function is equivalent to this one. Where possible I tried to
replace const char* with llvm::StringRef to avoid extra strlen
computations. In most places, I was able to track the c string back to
the ConstString it was created from.
I also create a test that verifies we are able to lookup names with
unicode characters, as a bug in the llvm compiler (it accidentally used
a different hash function) meant this was not working until recently.
This also removes the unused ExportTable class.
Reviewers: aprantl, davide
Subscribers: JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D43596
llvm-svn: 325927
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
index cb1e5c1..629ae8b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp
@@ -379,7 +379,8 @@
DWARFMappedHash::MemoryTable::Result
DWARFMappedHash::MemoryTable::GetHashDataForName(
- const char *name, lldb::offset_t *hash_data_offset_ptr, Pair &pair) const {
+ llvm::StringRef name, lldb::offset_t *hash_data_offset_ptr,
+ Pair &pair) const {
pair.key = m_data.GetU32(hash_data_offset_ptr);
pair.value.clear();
@@ -406,7 +407,7 @@
// data to parse at least "count" HashData entries.
// First make sure the entire C string matches...
- const bool match = strcmp(name, strp_cstr) == 0;
+ const bool match = name == strp_cstr;
if (!match && m_header.header_data.HashDataHasFixedByteSize()) {
// If the string doesn't match and we have fixed size data,
@@ -573,9 +574,9 @@
return die_info_array.size();
}
-size_t DWARFMappedHash::MemoryTable::FindByName(const char *name,
+size_t DWARFMappedHash::MemoryTable::FindByName(llvm::StringRef name,
DIEArray &die_offsets) {
- if (!name || !name[0])
+ if (name.empty())
return 0;
DIEInfoArray die_info_array;
@@ -584,7 +585,7 @@
return die_info_array.size();
}
-size_t DWARFMappedHash::MemoryTable::FindByNameAndTag(const char *name,
+size_t DWARFMappedHash::MemoryTable::FindByNameAndTag(llvm::StringRef name,
const dw_tag_t tag,
DIEArray &die_offsets) {
DIEInfoArray die_info_array;
@@ -594,8 +595,8 @@
}
size_t DWARFMappedHash::MemoryTable::FindByNameAndTagAndQualifiedNameHash(
- const char *name, const dw_tag_t tag, const uint32_t qualified_name_hash,
- DIEArray &die_offsets) {
+ llvm::StringRef name, const dw_tag_t tag,
+ const uint32_t qualified_name_hash, DIEArray &die_offsets) {
DIEInfoArray die_info_array;
if (FindByName(name, die_info_array))
DWARFMappedHash::ExtractDIEArray(die_info_array, tag, qualified_name_hash,
@@ -604,7 +605,7 @@
}
size_t DWARFMappedHash::MemoryTable::FindCompleteObjCClassByName(
- const char *name, DIEArray &die_offsets, bool must_be_implementation) {
+ llvm::StringRef name, DIEArray &die_offsets, bool must_be_implementation) {
DIEInfoArray die_info_array;
if (FindByName(name, die_info_array)) {
if (must_be_implementation &&
@@ -628,9 +629,9 @@
return die_offsets.size();
}
-size_t DWARFMappedHash::MemoryTable::FindByName(const char *name,
+size_t DWARFMappedHash::MemoryTable::FindByName(llvm::StringRef name,
DIEInfoArray &die_info_array) {
- if (!name || !name[0])
+ if (name.empty())
return 0;
Pair kv_pair;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
index b38473d..dc2d4ff 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h
@@ -132,17 +132,17 @@
const uint32_t die_offset_end,
DIEInfoArray &die_info_array) const;
- size_t FindByName(const char *name, DIEArray &die_offsets);
+ size_t FindByName(llvm::StringRef name, DIEArray &die_offsets);
- size_t FindByNameAndTag(const char *name, const dw_tag_t tag,
+ size_t FindByNameAndTag(llvm::StringRef name, const dw_tag_t tag,
DIEArray &die_offsets);
- size_t
- FindByNameAndTagAndQualifiedNameHash(const char *name, const dw_tag_t tag,
- const uint32_t qualified_name_hash,
- DIEArray &die_offsets);
+ size_t FindByNameAndTagAndQualifiedNameHash(
+ llvm::StringRef name, const dw_tag_t tag,
+ const uint32_t qualified_name_hash, DIEArray &die_offsets);
- size_t FindCompleteObjCClassByName(const char *name, DIEArray &die_offsets,
+ size_t FindCompleteObjCClassByName(llvm::StringRef name,
+ DIEArray &die_offsets,
bool must_be_implementation);
protected:
@@ -150,9 +150,9 @@
const lldb_private::RegularExpression ®ex,
lldb::offset_t *hash_data_offset_ptr, Pair &pair) const;
- size_t FindByName(const char *name, DIEInfoArray &die_info_array);
+ size_t FindByName(llvm::StringRef name, DIEInfoArray &die_info_array);
- Result GetHashDataForName(const char *name,
+ Result GetHashDataForName(llvm::StringRef name,
lldb::offset_t *hash_data_offset_ptr,
Pair &pair) const override;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 6ef26d8..4a5dd81 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1510,7 +1510,8 @@
method_die_offsets.clear();
if (m_using_apple_tables) {
if (m_apple_objc_ap.get())
- m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
+ m_apple_objc_ap->FindByName(class_name.GetStringRef(),
+ method_die_offsets);
} else {
if (!m_indexed)
Index();
@@ -2183,7 +2184,7 @@
basename))
basename = name_cstr;
- m_apple_names_ap->FindByName(basename.data(), die_offsets);
+ m_apple_names_ap->FindByName(basename, die_offsets);
}
} else {
// Index the DWARF if we haven't already
@@ -2489,8 +2490,6 @@
// Remember how many sc_list are in the list before we search in case
// we are appending the results to a variable list.
- const char *name_cstr = name.GetCString();
-
const uint32_t original_size = sc_list.GetSize();
DWARFDebugInfo *info = DebugInfo();
@@ -2511,7 +2510,8 @@
// want to canonicalize this (strip double spaces, etc. For now, we
// just add all the
// dies that we find by exact match.
- num_matches = m_apple_names_ap->FindByName(name_cstr, die_offsets);
+ num_matches =
+ m_apple_names_ap->FindByName(name.GetStringRef(), die_offsets);
for (uint32_t i = 0; i < num_matches; i++) {
const DIERef &die_ref = die_offsets[i];
DWARFDIE die = info->GetDIE(die_ref);
@@ -2527,7 +2527,7 @@
GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
"the DWARF debug information has been modified (.apple_names "
"accelerator table had bad die 0x%8.8x for '%s')",
- die_ref.die_offset, name_cstr);
+ die_ref.die_offset, name.GetCString());
}
}
}
@@ -2536,7 +2536,8 @@
if (parent_decl_ctx && parent_decl_ctx->IsValid())
return 0; // no selectors in namespaces
- num_matches = m_apple_names_ap->FindByName(name_cstr, die_offsets);
+ num_matches =
+ m_apple_names_ap->FindByName(name.GetStringRef(), die_offsets);
// Now make sure these are actually ObjC methods. In this case we can
// simply look up the name,
// and if it is an ObjC method name, we're good.
@@ -2556,7 +2557,7 @@
GetObjectFile()->GetModule()->ReportError(
"the DWARF debug information has been modified (.apple_names "
"accelerator table had bad die 0x%8.8x for '%s')",
- die_ref.die_offset, name_cstr);
+ die_ref.die_offset, name.GetCString());
}
}
die_offsets.clear();
@@ -2572,7 +2573,8 @@
// FIXME: Arrange the logic above so that we don't calculate the base
// name twice:
- num_matches = m_apple_names_ap->FindByName(name_cstr, die_offsets);
+ num_matches =
+ m_apple_names_ap->FindByName(name.GetStringRef(), die_offsets);
for (uint32_t i = 0; i < num_matches; i++) {
const DIERef &die_ref = die_offsets[i];
@@ -2626,7 +2628,7 @@
GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
"the DWARF debug information has been modified (.apple_names "
"accelerator table had bad die 0x%8.8x for '%s')",
- die_ref.die_offset, name_cstr);
+ die_ref.die_offset, name.GetCString());
}
}
die_offsets.clear();
@@ -2850,8 +2852,7 @@
if (m_using_apple_tables) {
if (m_apple_types_ap.get()) {
- const char *name_cstr = name.GetCString();
- m_apple_types_ap->FindByName(name_cstr, die_offsets);
+ m_apple_types_ap->FindByName(name.GetStringRef(), die_offsets);
}
} else {
if (!m_indexed)
@@ -2944,8 +2945,7 @@
if (m_using_apple_tables) {
if (m_apple_types_ap.get()) {
- const char *name_cstr = name.GetCString();
- m_apple_types_ap->FindByName(name_cstr, die_offsets);
+ m_apple_types_ap->FindByName(name.GetStringRef(), die_offsets);
}
} else {
if (!m_indexed)
@@ -3013,8 +3013,7 @@
// get indexed and make their global DIE index list
if (m_using_apple_tables) {
if (m_apple_namespaces_ap.get()) {
- const char *name_cstr = name.GetCString();
- m_apple_namespaces_ap->FindByName(name_cstr, die_offsets);
+ m_apple_namespaces_ap->FindByName(name.GetStringRef(), die_offsets);
}
} else {
if (!m_indexed)
@@ -3207,9 +3206,8 @@
if (m_using_apple_tables) {
if (m_apple_types_ap.get()) {
- const char *name_cstr = type_name.GetCString();
- m_apple_types_ap->FindCompleteObjCClassByName(name_cstr, die_offsets,
- must_be_implementation);
+ m_apple_types_ap->FindCompleteObjCClassByName(
+ type_name.GetStringRef(), die_offsets, must_be_implementation);
}
} else {
if (!m_indexed)
@@ -3398,21 +3396,21 @@
DWARFMappedHash::eAtomTypeQualNameHash);
if (has_tag && has_qualified_name_hash) {
const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
- const uint32_t qualified_name_hash =
- MappedHash::HashStringUsingDJB(qualified_name);
+ const uint32_t qualified_name_hash = llvm::djbHash(qualified_name);
if (log)
GetObjectFile()->GetModule()->LogMessage(
log, "FindByNameAndTagAndQualifiedNameHash()");
m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash(
- type_name.GetCString(), tag, qualified_name_hash, die_offsets);
+ type_name.GetStringRef(), tag, qualified_name_hash,
+ die_offsets);
} else if (has_tag) {
if (log)
GetObjectFile()->GetModule()->LogMessage(log,
"FindByNameAndTag()");
- m_apple_types_ap->FindByNameAndTag(type_name.GetCString(), tag,
+ m_apple_types_ap->FindByNameAndTag(type_name.GetStringRef(), tag,
die_offsets);
} else {
- m_apple_types_ap->FindByName(type_name.GetCString(), die_offsets);
+ m_apple_types_ap->FindByName(type_name.GetStringRef(), die_offsets);
}
}
} else {
diff --git a/lldb/source/Target/ObjCLanguageRuntime.cpp b/lldb/source/Target/ObjCLanguageRuntime.cpp
index d3cc7c0..e50167d 100644
--- a/lldb/source/Target/ObjCLanguageRuntime.cpp
+++ b/lldb/source/Target/ObjCLanguageRuntime.cpp
@@ -23,6 +23,7 @@
#include "lldb/Utility/Timer.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/DJB.h"
using namespace lldb;
using namespace lldb_private;
@@ -45,8 +46,7 @@
if (isa != 0) {
m_isa_to_descriptor[isa] = descriptor_sp;
// class_name is assumed to be valid
- m_hash_to_isa_map.insert(
- std::make_pair(MappedHash::HashStringUsingDJB(class_name), isa));
+ m_hash_to_isa_map.insert(std::make_pair(llvm::djbHash(class_name), isa));
return true;
}
return false;
@@ -180,8 +180,7 @@
} else {
// Name hashes were provided, so use them to efficiently lookup name to
// isa/descriptor
- const uint32_t name_hash =
- MappedHash::HashStringUsingDJB(name.GetCString());
+ const uint32_t name_hash = llvm::djbHash(name.GetStringRef());
std::pair<HashToISAIterator, HashToISAIterator> range =
m_hash_to_isa_map.equal_range(name_hash);
for (HashToISAIterator range_pos = range.first; range_pos != range.second;