MCPcopy Create free account
hub / github.com/ablab/spades / printSymbolizedStackTrace

Function printSymbolizedStackTrace

ext/src/llvm/Signals.cpp:104–215  ·  view source on GitHub ↗

Helper that launches llvm-symbolizer and symbolizes a backtrace.

Source from the content-addressed store, hash-verified

102
103/// Helper that launches llvm-symbolizer and symbolizes a backtrace.
104LLVM_ATTRIBUTE_USED
105static 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

Callers

nothing calls this directly

Calls 15

error_codeEnum · 0.85
parent_pathFunction · 0.85
createTemporaryFileFunction · 0.85
right_justifyFunction · 0.85
formatvFunction · 0.85
format_ptrFunction · 0.85
format_hexFunction · 0.85
startswithMethod · 0.80
existsFunction · 0.70
StringRefClass · 0.70
log10Function · 0.50
findMethod · 0.45

Tested by

no test coverage detected