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.
llvm-svn: 309498
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index 18908ae..272f91c 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -102,10 +102,13 @@
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 @@
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,
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
index d98d49b..6480aef 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h
@@ -58,9 +58,11 @@
}
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 @@
/// 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,
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 67f39ec..aeb1dea 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -792,11 +792,13 @@
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 @@
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 @@
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), "");
}
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 1d8b432..7aa55e7 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -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<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 @@
}
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 @@
}
}
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));
diff --git a/llvm/test/DebugInfo/llvm-symbolizer.test b/llvm/test/DebugInfo/llvm-symbolizer.test
index bcad37c..342c1a9e 100644
--- a/llvm/test/DebugInfo/llvm-symbolizer.test
+++ b/llvm/test/DebugInfo/llvm-symbolizer.test
@@ -50,6 +50,11 @@
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: 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
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index c9e0cc2..b51ec51 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -69,6 +69,10 @@
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 @@
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";