bool RelativeAddresses : 1;
std::string DefaultArch;
std::vector<std::string> DsymHints;
+ std::string FallbackDebugPath;
Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
bool UseSymbolTable = true, bool Demangle = true,
- bool RelativeAddresses = false, std::string DefaultArch = "")
+ bool RelativeAddresses = false, std::string DefaultArch = "",
+ std::string FallbackDebugPath = "")
: PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
Demangle(Demangle), RelativeAddresses(RelativeAddresses),
- DefaultArch(std::move(DefaultArch)) {}
+ DefaultArch(std::move(DefaultArch)),
+ FallbackDebugPath(std::move(FallbackDebugPath)) {}
};
LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
bool findDebugBinary(const std::string &OrigPath,
const std::string &DebuglinkName, uint32_t CRCHash,
+ const std::string &FallbackDebugPath,
std::string &Result) {
SmallString<16> OrigDir(OrigPath);
llvm::sys::path::remove_filename(OrigDir);
SmallString<16> DebugPath = OrigDir;
- // Try /path/to/original_binary/debuglink_name
+ // Try relative/path/to/original_binary/debuglink_name
llvm::sys::path::append(DebugPath, DebuglinkName);
if (checkFileCRC(DebugPath, CRCHash)) {
Result = DebugPath.str();
return true;
}
- // Try /path/to/original_binary/.debug/debuglink_name
+ // Try relative/path/to/original_binary/.debug/debuglink_name
DebugPath = OrigDir;
llvm::sys::path::append(DebugPath, ".debug", DebuglinkName);
if (checkFileCRC(DebugPath, CRCHash)) {
Result = DebugPath.str();
return true;
}
+ // Make the path absolute so that lookups will go to
+ // "/usr/lib/debug/full/path/to/debug", not
+ // "/usr/lib/debug/to/debug"
+ llvm::sys::fs::make_absolute(OrigDir);
+ if (!FallbackDebugPath.empty()) {
+ // Try <FallbackDebugPath>/absolute/path/to/original_binary/debuglink_name
+ DebugPath = FallbackDebugPath;
+ } else {
#if defined(__NetBSD__)
- // Try /usr/libdata/debug/path/to/original_binary/debuglink_name
- DebugPath = "/usr/libdata/debug";
+ // Try /usr/libdata/debug/absolute/path/to/original_binary/debuglink_name
+ DebugPath = "/usr/libdata/debug";
#else
- // Try /usr/lib/debug/path/to/original_binary/debuglink_name
- DebugPath = "/usr/lib/debug";
+ // Try /usr/lib/debug/absolute/path/to/original_binary/debuglink_name
+ DebugPath = "/usr/lib/debug";
#endif
+ }
llvm::sys::path::append(DebugPath, llvm::sys::path::relative_path(OrigDir),
DebuglinkName);
if (checkFileCRC(DebugPath, CRCHash)) {
std::string DebugBinaryPath;
if (!getGNUDebuglinkContents(Obj, DebuglinkName, CRCHash))
return nullptr;
- if (!findDebugBinary(Path, DebuglinkName, CRCHash, DebugBinaryPath))
+ if (!findDebugBinary(Path, DebuglinkName, CRCHash, Opts.FallbackDebugPath,
+ DebugBinaryPath))
return nullptr;
auto DbgObjOrErr = getOrCreateObject(DebugBinaryPath, ArchName);
if (!DbgObjOrErr) {
--- /dev/null
+# REQUIRES: shell
+# Ensures that .debuglink can fallback to a separate location. This is normally
+# /usr/lib/debug (or /usr/libdata/debug for NetBSD), but can be configured on
+# the command line (mainly for testing).
+
+RUN: rm -rf %t/foo %t/bar
+RUN: mkdir -p %t/foo %t/bar/%t/foo
+
+RUN: cp %p/Inputs/dwarfdump-test.elf-x86-64.debuglink %t/foo
+
+RUN: llvm-symbolizer --obj=%t/foo/dwarfdump-test.elf-x86-64.debuglink 0x40113f \
+RUN: --fallback-debug-path=%t/bar | FileCheck %s --check-prefix=UNKNOWN
+
+UNKNOWN: main
+UNKNOWN-NEXT: ??:0:0
+
+RUN: cp %p/Inputs/dwarfdump-test.elf-x86-64 %t/bar/%t/foo
+RUN: llvm-symbolizer --obj=%t/foo/dwarfdump-test.elf-x86-64.debuglink 0x40113f \
+RUN: --fallback-debug-path=%t/bar | FileCheck %s --check-prefix=FOUND
+
+FOUND: main
+FOUND-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16
cl::desc("<input addresses>..."),
cl::ZeroOrMore);
+static cl::opt<std::string>
+ ClFallbackDebugPath("fallback-debug-path", cl::init(""),
+ cl::desc("Fallback path for debug binaries."));
+
template<typename T>
static bool error(Expected<T> &ResOrErr) {
if (ResOrErr)
ClDemangle = !ClNoDemangle;
LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable, ClDemangle,
- ClUseRelativeAddress, ClDefaultArch);
+ ClUseRelativeAddress, ClDefaultArch,
+ ClFallbackDebugPath);
for (const auto &hint : ClDsymHint) {
if (sys::path::extension(hint) == ".dSYM") {