[llvm] r229177 - [dsymutil] Add DebugMapObject::lookupObjectAddress()

Frederic Riss friss at apple.com
Fri Feb 13 15:18:16 PST 2015


Author: friss
Date: Fri Feb 13 17:18:16 2015
New Revision: 229177

URL: http://llvm.org/viewvc/llvm-project?rev=229177&view=rev
Log:
[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.

Modified:
    llvm/trunk/tools/dsymutil/DebugMap.cpp
    llvm/trunk/tools/dsymutil/DebugMap.h

Modified: llvm/trunk/tools/dsymutil/DebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.cpp?rev=229177&r1=229176&r2=229177&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.cpp (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.cpp Fri Feb 13 17:18:16 2015
@@ -26,6 +26,9 @@ bool DebugMapObject::addSymbol(StringRef
                                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::addDebugMapObj
   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 {

Modified: llvm/trunk/tools/dsymutil/DebugMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.h?rev=229177&r1=229176&r2=229177&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.h (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.h Fri Feb 13 17:18:16 2015
@@ -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;
 };
 }
 }





More information about the llvm-commits mailing list