Helper that launches llvm-symbolizer and symbolizes a backtrace.
| 102 | |
| 103 | /// Helper that launches llvm-symbolizer and symbolizes a backtrace. |
| 104 | LLVM_ATTRIBUTE_USED |
| 105 | static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, |
| 106 | int Depth, llvm::raw_ostream &OS) { |
| 107 | if (DisableSymbolicationFlag) |
| 108 | return false; |
| 109 | |
| 110 | // Don't recursively invoke the llvm-symbolizer binary. |
| 111 | if (Argv0.find("llvm-symbolizer") != std::string::npos) |
| 112 | return false; |
| 113 | |
| 114 | // FIXME: Subtract necessary number from StackTrace entries to turn return addresses |
| 115 | // into actual instruction addresses. |
| 116 | // Use llvm-symbolizer tool to symbolize the stack traces. First look for it |
| 117 | // alongside our binary, then in $PATH. |
| 118 | ErrorOr<std::string> LLVMSymbolizerPathOrErr = std::error_code(); |
| 119 | if (!Argv0.empty()) { |
| 120 | StringRef Parent = llvm::sys::path::parent_path(Argv0); |
| 121 | if (!Parent.empty()) |
| 122 | LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer", Parent); |
| 123 | } |
| 124 | if (!LLVMSymbolizerPathOrErr) |
| 125 | LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer"); |
| 126 | if (!LLVMSymbolizerPathOrErr) |
| 127 | return false; |
| 128 | const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr; |
| 129 | |
| 130 | // If we don't know argv0 or the address of main() at this point, try |
| 131 | // to guess it anyway (it's possible on some platforms). |
| 132 | std::string MainExecutableName = |
| 133 | sys::fs::exists(Argv0) ? (std::string)std::string(Argv0) |
| 134 | : sys::fs::getMainExecutable(nullptr, nullptr); |
| 135 | BumpPtrAllocator Allocator; |
| 136 | StringSaver StrPool(Allocator); |
| 137 | std::vector<const char *> Modules(Depth, nullptr); |
| 138 | std::vector<intptr_t> Offsets(Depth, 0); |
| 139 | if (!findModulesAndOffsets(StackTrace, Depth, Modules.data(), Offsets.data(), |
| 140 | MainExecutableName.c_str(), StrPool)) |
| 141 | return false; |
| 142 | int InputFD; |
| 143 | SmallString<32> InputFile, OutputFile; |
| 144 | sys::fs::createTemporaryFile("symbolizer-input", "", InputFD, InputFile); |
| 145 | sys::fs::createTemporaryFile("symbolizer-output", "", OutputFile); |
| 146 | FileRemover InputRemover(InputFile.c_str()); |
| 147 | FileRemover OutputRemover(OutputFile.c_str()); |
| 148 | |
| 149 | { |
| 150 | raw_fd_ostream Input(InputFD, true); |
| 151 | for (int i = 0; i < Depth; i++) { |
| 152 | if (Modules[i]) |
| 153 | Input << Modules[i] << " " << (void*)Offsets[i] << "\n"; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | Optional<StringRef> Redirects[] = {StringRef(InputFile), |
| 158 | StringRef(OutputFile), StringRef("")}; |
| 159 | StringRef Args[] = {"llvm-symbolizer", "--functions=linkage", "--inlining", |
| 160 | #ifdef _WIN32 |
| 161 | // Pass --relative-address on Windows so that we don't |
nothing calls this directly
no test coverage detected