From 1595c5d37d2e254da83a9e898469903beb5928a0 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Fri, 13 Feb 2015 23:18:16 +0000 Subject: [PATCH] [dsymutil] Add DebugMapObject::lookupObjectAddress() It turns out the debug map will be interogated both by name and by object file address. Add the latter capability. llvm-svn: 229177 --- llvm/tools/dsymutil/DebugMap.cpp | 15 +++++++++++++-- llvm/tools/dsymutil/DebugMap.h | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/llvm/tools/dsymutil/DebugMap.cpp b/llvm/tools/dsymutil/DebugMap.cpp index ca7ae80..c04b2fe 100644 --- a/llvm/tools/dsymutil/DebugMap.cpp +++ b/llvm/tools/dsymutil/DebugMap.cpp @@ -26,6 +26,9 @@ bool DebugMapObject::addSymbol(StringRef Name, uint64_t ObjectAddress, uint64_t LinkedAddress) { auto InsertResult = Symbols.insert( std::make_pair(Name, SymbolMapping(ObjectAddress, LinkedAddress))); + + if (InsertResult.second) + AddressToMapping[ObjectAddress] = &*InsertResult.first; return InsertResult.second; } @@ -58,12 +61,20 @@ DebugMapObject &DebugMap::addDebugMapObject(StringRef ObjectFilePath) { return *Objects.back(); } -const DebugMapObject::SymbolMapping * +const DebugMapObject::DebugMapEntry * DebugMapObject::lookupSymbol(StringRef SymbolName) const { StringMap::const_iterator Sym = Symbols.find(SymbolName); if (Sym == Symbols.end()) return nullptr; - return &Sym->getValue(); + return &*Sym; +} + +const DebugMapObject::DebugMapEntry * +DebugMapObject::lookupObjectAddress(uint64_t Address) const { + auto Mapping = AddressToMapping.find(Address); + if (Mapping == AddressToMapping.end()) + return nullptr; + return Mapping->getSecond(); } void DebugMap::print(raw_ostream &OS) const { diff --git a/llvm/tools/dsymutil/DebugMap.h b/llvm/tools/dsymutil/DebugMap.h index bafc167..ff2b27e 100644 --- a/llvm/tools/dsymutil/DebugMap.h +++ b/llvm/tools/dsymutil/DebugMap.h @@ -21,6 +21,7 @@ #ifndef LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H #define LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/iterator_range.h" @@ -104,6 +105,8 @@ public: : ObjectAddress(ObjectAddress), BinaryAddress(BinaryAddress) {} }; + typedef StringMapEntry DebugMapEntry; + /// \brief Adds a symbol mapping to this DebugMapObject. /// \returns false if the symbol was already registered. The request /// is discarded in this case. @@ -112,7 +115,11 @@ public: /// \brief Lookup a symbol mapping. /// \returns null if the symbol isn't found. - const SymbolMapping *lookupSymbol(StringRef SymbolName) const; + const DebugMapEntry *lookupSymbol(StringRef SymbolName) const; + + /// \brief Lookup an objectfile address. + /// \returns null if the address isn't found. + const DebugMapEntry *lookupObjectAddress(uint64_t Address) const; llvm::StringRef getObjectFilename() const { return Filename; } @@ -127,6 +134,7 @@ private: std::string Filename; StringMap Symbols; + DenseMap AddressToMapping; }; } } -- 2.7.4