[llvm] r309498 - DebugInfo: Provide option for explicitly specifying the name of the DWP file

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 29 18:34:08 PDT 2017


Author: dblaikie
Date: Sat Jul 29 18:34:08 2017
New Revision: 309498

URL: http://llvm.org/viewvc/llvm-project?rev=309498&view=rev
Log:
DebugInfo: Provide option for explicitly specifying the name of the DWP file

If you've archived the DWP file somewhere it's probably useful to be
able to just tell llvm-symbolizer where it is when you're symbolizing
stack traces from the binary.

This only provides a mechanism for specifying a single DWP file, good if
you're symbolizing a program with a single DWP file, but it's likely if
the program is dynamically linked that you might have a DWP for each
dynamic library - in which case this feature won't help (at least as
it's surfaced in llvm-symbolizer for now) - in theory it could be
extended to specify a collection of DWP files that could all be
consulted for split CU hash resolution.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h
    llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
    llvm/trunk/test/DebugInfo/llvm-symbolizer.test
    llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=309498&r1=309497&r2=309498&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h Sat Jul 29 18:34:08 2017
@@ -102,10 +102,13 @@ class DWARFContext : public DIContext {
 
 protected:
   std::unique_ptr<const DWARFObject> DObj;
+  std::string DWPName;
 
 public:
-  DWARFContext(std::unique_ptr<const DWARFObject> DObj)
-      : DIContext(CK_DWARF), DObj(std::move(DObj)) {}
+  DWARFContext(std::unique_ptr<const DWARFObject> DObj,
+               std::string DWPName = "")
+      : DIContext(CK_DWARF), DObj(std::move(DObj)),
+        DWPName(std::move(DWPName)) {}
   DWARFContext(DWARFContext &) = delete;
   DWARFContext &operator=(DWARFContext &) = delete;
 
@@ -245,7 +248,8 @@ public:
   static ErrorPolicy defaultErrorHandler(Error E);
   static std::unique_ptr<DWARFContext>
   create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
-         function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler);
+         function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler,
+         std::string DWPName = "");
 
   static std::unique_ptr<DWARFContext>
   create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,

Modified: llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h?rev=309498&r1=309497&r2=309498&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h Sat Jul 29 18:34:08 2017
@@ -58,9 +58,11 @@ public:
   }
 
   Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
-                                     uint64_t ModuleOffset);
+                                     uint64_t ModuleOffset,
+                                     StringRef DWPName = "");
   Expected<DIInliningInfo> symbolizeInlinedCode(const std::string &ModuleName,
-                                                uint64_t ModuleOffset);
+                                                uint64_t ModuleOffset,
+                                                StringRef DWPName = "");
   Expected<DIGlobal> symbolizeData(const std::string &ModuleName,
                                    uint64_t ModuleOffset);
   void flush();
@@ -79,7 +81,7 @@ private:
   /// only reported once. Subsequent calls to get module info for a module that
   /// failed to load will return nullptr.
   Expected<SymbolizableModule *>
-  getOrCreateModuleInfo(const std::string &ModuleName);
+  getOrCreateModuleInfo(const std::string &ModuleName, StringRef DWPName = "");
 
   ObjectFile *lookUpDsymFile(const std::string &Path,
                              const MachOObjectFile *ExeObj,

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=309498&r1=309497&r2=309498&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Sat Jul 29 18:34:08 2017
@@ -792,11 +792,13 @@ DWARFContext::getDWOContext(StringRef Ab
     return std::shared_ptr<DWARFContext>(std::move(S), Ctxt);
   }
 
-  SmallString<128> DWPName;
   Expected<OwningBinary<ObjectFile>> Obj = [&] {
     if (!CheckedForDWP) {
-      (DObj->getFileName() + ".dwp").toVector(DWPName);
-      auto Obj = object::ObjectFile::createObjectFile(DWPName);
+      SmallString<128> DWPName;
+      auto Obj = object::ObjectFile::createObjectFile(
+          this->DWPName.empty()
+              ? (DObj->getFileName() + ".dwp").toStringRef(DWPName)
+              : StringRef(this->DWPName));
       if (Obj) {
         Entry = &DWP;
         return Obj;
@@ -1252,9 +1254,10 @@ public:
 
 std::unique_ptr<DWARFContext>
 DWARFContext::create(const object::ObjectFile &Obj, const LoadedObjectInfo *L,
-                     function_ref<ErrorPolicy(Error)> HandleError) {
+                     function_ref<ErrorPolicy(Error)> HandleError,
+                     std::string DWPName) {
   auto DObj = llvm::make_unique<DWARFObjInMemory>(Obj, L, HandleError);
-  return llvm::make_unique<DWARFContext>(std::move(DObj));
+  return llvm::make_unique<DWARFContext>(std::move(DObj), std::move(DWPName));
 }
 
 std::unique_ptr<DWARFContext>
@@ -1262,5 +1265,5 @@ DWARFContext::create(const StringMap<std
                      uint8_t AddrSize, bool isLittleEndian) {
   auto DObj =
       llvm::make_unique<DWARFObjInMemory>(Sections, AddrSize, isLittleEndian);
-  return llvm::make_unique<DWARFContext>(std::move(DObj));
+  return llvm::make_unique<DWARFContext>(std::move(DObj), "");
 }

Modified: llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp?rev=309498&r1=309497&r2=309498&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp Sat Jul 29 18:34:08 2017
@@ -53,10 +53,11 @@
 namespace llvm {
 namespace symbolize {
 
-Expected<DILineInfo> LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
-                                                  uint64_t ModuleOffset) {
+Expected<DILineInfo>
+LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
+                              uint64_t ModuleOffset, StringRef DWPName) {
   SymbolizableModule *Info;
-  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
+  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName, DWPName))
     Info = InfoOrErr.get();
   else
     return InfoOrErr.takeError();
@@ -80,9 +81,9 @@ Expected<DILineInfo> LLVMSymbolizer::sym
 
 Expected<DIInliningInfo>
 LLVMSymbolizer::symbolizeInlinedCode(const std::string &ModuleName,
-                                     uint64_t ModuleOffset) {
+                                     uint64_t ModuleOffset, StringRef DWPName) {
   SymbolizableModule *Info;
-  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName))
+  if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName, DWPName))
     Info = InfoOrErr.get();
   else
     return InfoOrErr.takeError();
@@ -364,7 +365,8 @@ LLVMSymbolizer::getOrCreateObject(const
 }
 
 Expected<SymbolizableModule *>
-LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
+LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName,
+                                      StringRef DWPName) {
   const auto &I = Modules.find(ModuleName);
   if (I != Modules.end()) {
     return I->second.get();
@@ -409,7 +411,8 @@ LLVMSymbolizer::getOrCreateModuleInfo(co
     }
   }
   if (!Context)
-    Context = DWARFContext::create(*Objects.second);
+    Context = DWARFContext::create(*Objects.second, nullptr,
+                                   DWARFContext::defaultErrorHandler, DWPName);
   assert(Context);
   auto InfoOrErr =
       SymbolizableObjectFile::create(Objects.first, std::move(Context));

Modified: llvm/trunk/test/DebugInfo/llvm-symbolizer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/llvm-symbolizer.test?rev=309498&r1=309497&r2=309498&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/llvm-symbolizer.test (original)
+++ llvm/trunk/test/DebugInfo/llvm-symbolizer.test Sat Jul 29 18:34:08 2017
@@ -50,6 +50,11 @@ RUN: echo "%p/Inputs/split-dwarf-test 0x
 RUN: llvm-symbolizer --functions=linkage --inlining --demangle=false \
 RUN:    --default-arch=i386 < %t.input | FileCheck --check-prefix=SPLIT --check-prefix=NODWO %s
 
+RUN: cp %p/Inputs/split-dwarf-dwp.o %T/split-dwarf-dwp-different-name.o
+RUN: echo "%T/split-dwarf-dwp-different-name.o 0x4" > %t.input
+RUN: llvm-symbolizer --functions=linkage --inlining --demangle=false \
+RUN:    --default-arch=i386 --dwp=%p/Inputs/split-dwarf-dwp.o.dwp < %t.input | FileCheck --check-prefix=DWP %s
+
 CHECK:       main
 CHECK-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16
 
@@ -151,10 +156,10 @@ CHECK-NEXT: split-dwarf-addr-object-relo
 CHECK-NEXT: f3
 CHECK-NEXT: split-dwarf-addr-object-relocation.cpp:6:0
 
-CHECK:      f2
-CHECK-NEXT: split-dwarf-dwp.cpp:3:3
-CHECK-NEXT: f3
-CHECK-NEXT: split-dwarf-dwp.cpp:6:0
+DWP:      f2
+DWP-NEXT: split-dwarf-dwp.cpp:3:3
+DWP-NEXT: f3
+DWP-NEXT: split-dwarf-dwp.cpp:6:0
 
 RUN: echo "unexisting-file 0x1234" > %t.input2
 RUN: llvm-symbolizer < %t.input2 2>&1 | FileCheck %s --check-prefix=MISSING-FILE

Modified: llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp?rev=309498&r1=309497&r2=309498&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp Sat Jul 29 18:34:08 2017
@@ -69,6 +69,10 @@ ClBinaryName("obj", cl::init(""),
              cl::desc("Path to object file to be symbolized (if not provided, "
                       "object file should be specified for each input line)"));
 
+static cl::opt<std::string>
+    ClDwpName("dwp", cl::init(""),
+              cl::desc("Path to DWP file to be use for any split CUs"));
+
 static cl::list<std::string>
 ClDsymHint("dsym-hint", cl::ZeroOrMore,
            cl::desc("Path to .dSYM bundles to search for debug info for the "
@@ -191,11 +195,13 @@ int main(int argc, char **argv) {
       auto ResOrErr = Symbolizer.symbolizeData(ModuleName, ModuleOffset);
       Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get());
     } else if (ClPrintInlining) {
-      auto ResOrErr = Symbolizer.symbolizeInlinedCode(ModuleName, ModuleOffset);
+      auto ResOrErr =
+          Symbolizer.symbolizeInlinedCode(ModuleName, ModuleOffset, ClDwpName);
       Printer << (error(ResOrErr) ? DIInliningInfo()
                                              : ResOrErr.get());
     } else {
-      auto ResOrErr = Symbolizer.symbolizeCode(ModuleName, ModuleOffset);
+      auto ResOrErr =
+          Symbolizer.symbolizeCode(ModuleName, ModuleOffset, ClDwpName);
       Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get());
     }
     outs() << "\n";




More information about the llvm-commits mailing list