diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-08-16 21:02:59 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-08-16 21:02:59 +0000 |
commit | 3ca95b020283db6244cab92ede73c969253b6a31 (patch) | |
tree | d16e791e58694facd8f68d3e2797a1eaa8018afc /contrib/llvm/lib/Support/Signals.cpp | |
parent | 27067774dce3388702a4cf744d7096c6fb71b688 (diff) | |
parent | c3aee98e721333f265a88d6bf348e6e468f027d4 (diff) |
Notes
Diffstat (limited to 'contrib/llvm/lib/Support/Signals.cpp')
-rw-r--r-- | contrib/llvm/lib/Support/Signals.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/contrib/llvm/lib/Support/Signals.cpp b/contrib/llvm/lib/Support/Signals.cpp index 3dc6b7c99d01..e5e38f59c040 100644 --- a/contrib/llvm/lib/Support/Signals.cpp +++ b/contrib/llvm/lib/Support/Signals.cpp @@ -62,28 +62,40 @@ static FormattedNumber format_ptr(void *PC) { return format_hex((uint64_t)PC, PtrWidth); } -static bool printSymbolizedStackTrace(void **StackTrace, int Depth, +static bool printSymbolizedStackTrace(StringRef Argv0, + void **StackTrace, int Depth, llvm::raw_ostream &OS) LLVM_ATTRIBUTE_USED; /// Helper that launches llvm-symbolizer and symbolizes a backtrace. -static bool printSymbolizedStackTrace(void **StackTrace, int Depth, +static bool printSymbolizedStackTrace(StringRef Argv0, + void **StackTrace, int Depth, llvm::raw_ostream &OS) { + // Don't recursively invoke the llvm-symbolizer binary. + if (Argv0.find("llvm-symbolizer") != std::string::npos) + return false; + // FIXME: Subtract necessary number from StackTrace entries to turn return addresses // into actual instruction addresses. - // Use llvm-symbolizer tool to symbolize the stack traces. - ErrorOr<std::string> LLVMSymbolizerPathOrErr = - sys::findProgramByName("llvm-symbolizer"); + // Use llvm-symbolizer tool to symbolize the stack traces. First look for it + // alongside our binary, then in $PATH. + ErrorOr<std::string> LLVMSymbolizerPathOrErr = std::error_code(); + if (!Argv0.empty()) { + StringRef Parent = llvm::sys::path::parent_path(Argv0); + if (!Parent.empty()) + LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer", Parent); + } + if (!LLVMSymbolizerPathOrErr) + LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer"); if (!LLVMSymbolizerPathOrErr) return false; const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr; - // We don't know argv0 or the address of main() at this point, but try - // to guess it anyway (it's possible on some platforms). - std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); - if (MainExecutableName.empty() || - MainExecutableName.find("llvm-symbolizer") != std::string::npos) - return false; + // If we don't know argv0 or the address of main() at this point, try + // to guess it anyway (it's possible on some platforms). + std::string MainExecutableName = + Argv0.empty() ? sys::fs::getMainExecutable(nullptr, nullptr) + : (std::string)Argv0; BumpPtrAllocator Allocator; StringSaver StrPool(Allocator); std::vector<const char *> Modules(Depth, nullptr); |