[dsymutil] Add DebugMapObject::lookupObjectAddress()
authorFrederic Riss <friss@apple.com>
Fri, 13 Feb 2015 23:18:16 +0000 (23:18 +0000)
committerFrederic Riss <friss@apple.com>
Fri, 13 Feb 2015 23:18:16 +0000 (23:18 +0000)
It turns out the debug map will be interogated both by name and
by object file address. Add the latter capability.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229177 91177308-0d34-0410-b5e6-96231b3b80d8

tools/dsymutil/DebugMap.cpp
tools/dsymutil/DebugMap.h

index ca7ae80ee8f651654427e909c40ed3137c423732..c04b2fe89f6d0dcc2bcc62022da11b18deb71628 100644 (file)
@@ -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<SymbolMapping>::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 {
index bafc1678b11ade79a33c590f1d8babc4b9bb743e..ff2b27e74eb2fba4d9f6851a4313f384bb29bed7 100644 (file)
@@ -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<SymbolMapping> 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<SymbolMapping> Symbols;
+  DenseMap<uint64_t, DebugMapEntry *> AddressToMapping;
 };
 }
 }