[Lldb-commits] [PATCH] D122974: prevent ConstString from calling djbHash() more than once
llunak updated this revision to Diff 431216. llunak added a comment. - add a function for selecting a pool in ConstString - use uint32_t for hash in StringMap API CHANGES SINCE LAST ACTION https://reviews.llvm.org/D122974/new/ https://reviews.llvm.org/D122974 Files: lldb/source/Utility/ConstString.cpp llvm/include/llvm/ADT/StringMap.h llvm/lib/Support/StringMap.cpp Index: llvm/lib/Support/StringMap.cpp === --- llvm/lib/Support/StringMap.cpp +++ llvm/lib/Support/StringMap.cpp @@ -11,7 +11,6 @@ //===--===// #include "llvm/ADT/StringMap.h" -#include "llvm/Support/DJB.h" #include "llvm/Support/MathExtras.h" using namespace llvm; @@ -80,11 +79,14 @@ /// specified bucket will be non-null. Otherwise, it will be null. In either /// case, the FullHashValue field of the bucket will be set to the hash value /// of the string. -unsigned StringMapImpl::LookupBucketFor(StringRef Name) { +unsigned StringMapImpl::LookupBucketFor(StringRef Name, +uint32_t FullHashValue) { +#ifdef EXPENSIVE_CHECKS + assert(FullHashValue == hash(Name)); +#endif // Hash table unallocated so far? if (NumBuckets == 0) init(16); - unsigned FullHashValue = djbHash(Name, 0); unsigned BucketNo = FullHashValue & (NumBuckets - 1); unsigned *HashTable = getHashTable(TheTable, NumBuckets); @@ -136,10 +138,12 @@ /// FindKey - Look up the bucket that contains the specified key. If it exists /// in the map, return the bucket number of the key. Otherwise return -1. /// This does not modify the map. -int StringMapImpl::FindKey(StringRef Key) const { +int StringMapImpl::FindKey(StringRef Key, uint32_t FullHashValue) const { if (NumBuckets == 0) return -1; // Really empty table? - unsigned FullHashValue = djbHash(Key, 0); +#ifdef EXPENSIVE_CHECKS + assert(FullHashValue == hash(Key)); +#endif unsigned BucketNo = FullHashValue & (NumBuckets - 1); unsigned *HashTable = getHashTable(TheTable, NumBuckets); Index: llvm/include/llvm/ADT/StringMap.h === --- llvm/include/llvm/ADT/StringMap.h +++ llvm/include/llvm/ADT/StringMap.h @@ -17,6 +17,7 @@ #include "llvm/ADT/StringMapEntry.h" #include "llvm/ADT/iterator.h" #include "llvm/Support/AllocatorBase.h" +#include "llvm/Support/DJB.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include #include @@ -60,12 +61,20 @@ /// specified bucket will be non-null. Otherwise, it will be null. In either /// case, the FullHashValue field of the bucket will be set to the hash value /// of the string. - unsigned LookupBucketFor(StringRef Key); + unsigned LookupBucketFor(StringRef Key) { +return LookupBucketFor(Key, hash(Key)); + } + + /// Overload that explicitly takes precomputed hash(Key). + unsigned LookupBucketFor(StringRef Key, uint32_t FullHashValue); /// FindKey - Look up the bucket that contains the specified key. If it exists /// in the map, return the bucket number of the key. Otherwise return -1. /// This does not modify the map. - int FindKey(StringRef Key) const; + int FindKey(StringRef Key) const { return FindKey(Key, hash(Key)); } + + /// Overload that explicitly takes precomputed hash(Key). + int FindKey(StringRef Key, uint32_t FullHashValue) const; /// RemoveKey - Remove the specified StringMapEntry from the table, but do not /// delete it. This aborts if the value isn't in the table. @@ -94,6 +103,8 @@ bool empty() const { return NumItems == 0; } unsigned size() const { return NumItems; } + static uint32_t hash(StringRef Key) { return llvm::djbHash(Key, 0); } + void swap(StringMapImpl &Other) { std::swap(TheTable, Other.TheTable); std::swap(NumBuckets, Other.NumBuckets); @@ -215,15 +226,19 @@ StringMapKeyIterator(end())); } - iterator find(StringRef Key) { -int Bucket = FindKey(Key); + iterator find(StringRef Key) { return find(Key, hash(Key)); } + + iterator find(StringRef Key, uint32_t FullHashValue) { +int Bucket = FindKey(Key, FullHashValue); if (Bucket == -1) return end(); return iterator(TheTable + Bucket, true); } - const_iterator find(StringRef Key) const { -int Bucket = FindKey(Key); + const_iterator find(StringRef Key) const { return find(Key, hash(Key)); } + + const_iterator find(StringRef Key, uint32_t FullHashValue) const { +int Bucket = FindKey(Key, FullHashValue); if (Bucket == -1) return end(); return const_iterator(TheTable + Bucket, true); @@ -294,7 +309,13 @@ /// if and only if the insertion takes place, and the iterator component of /// the pair points to the element with key equivalent to the key of the pair. std::pair insert(std::pair KV) { -return try_emplace(KV.first, std::move(KV.second)); +return try_emplace_wi
[Lldb-commits] [lldb] b876c23 - Revert "[lldb] Consider binary as module of last resort"
Author: Muhammad Omair Javaid Date: 2022-05-23T11:19:48+05:00 New Revision: b876c23604c748bd267c1fcb0572845ee61549cc URL: https://github.com/llvm/llvm-project/commit/b876c23604c748bd267c1fcb0572845ee61549cc DIFF: https://github.com/llvm/llvm-project/commit/b876c23604c748bd267c1fcb0572845ee61549cc.diff LOG: Revert "[lldb] Consider binary as module of last resort" This reverts commit a3c3482ceb529206b0ae4e7782e5496da5e0879d. It broke LLDB API test TestBadAddressBreakpoints.py Differential revision: https://reviews.llvm.org/D124731 Added: Modified: lldb/source/Breakpoint/BreakpointResolverAddress.cpp lldb/source/Commands/Options.td Removed: lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py lldb/test/API/commands/breakpoint/set/address-nomodule/inferior.c diff --git a/lldb/source/Breakpoint/BreakpointResolverAddress.cpp b/lldb/source/Breakpoint/BreakpointResolverAddress.cpp index 9b6b6d29cbce8..c173fc0c2a7a6 100644 --- a/lldb/source/Breakpoint/BreakpointResolverAddress.cpp +++ b/lldb/source/Breakpoint/BreakpointResolverAddress.cpp @@ -121,27 +121,16 @@ Searcher::CallbackReturn BreakpointResolverAddress::SearchCallback( if (filter.AddressPasses(m_addr)) { if (breakpoint.GetNumLocations() == 0) { - // If the address is just an offset ... - if (!m_addr.IsSectionOffset()) { -ModuleSP containing_module_sp = nullptr; + // If the address is just an offset, and we're given a module, see if we + // can find the appropriate module loaded in the binary, and fix up + // m_addr to use that. + if (!m_addr.IsSectionOffset() && m_module_filespec) { Target &target = breakpoint.GetTarget(); -if (m_module_filespec) { - // ... and we're given a module, see if we can find the - // appropriate module loaded in the binary, and fix up - // m_addr to use that. - ModuleSpec module_spec(m_module_filespec); - containing_module_sp = - target.GetImages().FindFirstModule(module_spec); -} else { - // ... and we're not given a module, see if the offset is - // somewhere in the executable module. If it is, then we'll - // fix up m_addr to use that. - containing_module_sp = target.GetExecutableModule(); -} -if (containing_module_sp) { +ModuleSpec module_spec(m_module_filespec); +ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec); +if (module_sp) { Address tmp_address; - if (containing_module_sp->ResolveFileAddress(m_addr.GetOffset(), - tmp_address)) + if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address)) m_addr = tmp_address; } } diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index 284437887a0b9..c326f8a320748 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -128,15 +128,13 @@ let Command = "breakpoint set" in { Arg<"AddressOrExpression">, Required, Desc<"Set the breakpoint at the specified address. If the address maps " "uniquely to a particular binary, then the address will be converted to " -"a \"file\" address, so that the breakpoint will track that binary+offset " +"a \"file\"address, so that the breakpoint will track that binary+offset " "no matter where the binary eventually loads. Alternately, if you also " "specify the module - with the -s option - then the address will be " "treated as a file address in that module, and resolved accordingly. " "Again, this will allow lldb to track that offset on subsequent reloads. " "The module need not have been loaded at the time you specify this " -"breakpoint, and will get resolved when the module is loaded. If no " -"module is specified, the binary being debugged is considered as a " -"fallback.">; +"breakpoint, and will get resolved when the module is loaded.">; def breakpoint_set_name : Option<"name", "n">, Group<3>, Arg<"FunctionName">, Completion<"Symbol">, Required, Desc<"Set the breakpoint by function name. Can be repeated multiple times " diff --git a/lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile b/lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile deleted file mode 100644 index 7c82a2dde6c2e..0 --- a/lldb/test/API/commands/breakpoint/set/address-nomodule/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := inferior.c - -include Makefile.rules diff --git a/lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddressNoModule.py b/lldb/test/API/commands/breakpoint/set/address-nomodule/TestBreakpointAddress
[Lldb-commits] [PATCH] D124731: [lldb] Consider binary as module of last resort
omjavaid added a comment. I have reverted this temporarily as It broke LLDB API test TestBadAddressBreakpoints.py Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124731/new/ https://reviews.llvm.org/D124731 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits