19#include "llvm/Config/llvm-config.h"
47struct CreateDisableSymbolication {
50 "disable-symbolication",
51 cl::desc(
"Disable symbolizing crash backtraces."),
55struct CreateCrashDiagnosticsDir {
59 cl::desc(
"Directory for crash diagnostic files."),
69 *DisableSymbolication;
90static std::array<CallbackAndCookie, MaxSignalHandlerCallbacks> &
92 static std::array<CallbackAndCookie, MaxSignalHandlerCallbacks> callbacks;
101 if (!RunMe.Flag.compare_exchange_strong(
Expected, Desired))
103 (*RunMe.Callback)(RunMe.Cookie);
104 RunMe.Callback =
nullptr;
105 RunMe.Cookie =
nullptr;
116 if (!SetMe.Flag.compare_exchange_strong(
Expected, Desired))
118 SetMe.Callback = FnPtr;
119 SetMe.Cookie = Cookie;
127 const char **Modules, intptr_t *Offsets,
128 const char *MainExecutableName,
135 unsigned PtrWidth = 2 + 2 *
sizeof(
void *);
147 if (Argv0.
find(
"llvm-symbolizer") != std::string::npos)
157 }
else if (!Argv0.
empty()) {
162 if (!LLVMSymbolizerPathOrErr)
164 if (!LLVMSymbolizerPathOrErr)
166 const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr;
170 std::string MainExecutableName =
175 std::vector<const char *> Modules(
Depth,
nullptr);
176 std::vector<intptr_t> Offsets(
Depth, 0);
178 MainExecutableName.c_str(), StrPool))
189 for (
int i = 0; i <
Depth; i++) {
191 Input << Modules[i] <<
" " << (
void*)Offsets[i] <<
"\n";
195 std::optional<StringRef> Redirects[] = {InputFile.
str(), OutputFile.
str(),
197 StringRef Args[] = {
"llvm-symbolizer",
"--functions=linkage",
"--inlining",
202 "--relative-address",
215 StringRef Output = OutputBuf.get()->getBuffer();
217 Output.
split(Lines,
"\n");
218 auto CurLine = Lines.begin();
220 for (
int i = 0; i <
Depth; i++) {
221 auto PrintLineHeader = [&]() {
223 std::log10(
Depth) + 2)
234 if (CurLine == Lines.end())
237 if (FunctionName.
empty())
241 OS << FunctionName <<
' ';
242 if (CurLine == Lines.end())
248 OS <<
"(" << Modules[i] <<
'+' <<
format_hex(Offsets[i], 0) <<
")";
#define LLVM_ATTRIBUTE_USED
Provides ErrorOr<T> smart pointer.
static FormattedNumber format_ptr(void *PC)
Format a pointer value as hexadecimal.
constexpr char DisableSymbolizationEnv[]
static LLVM_ATTRIBUTE_USED bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, int Depth, llvm::raw_ostream &OS)
Helper that launches llvm-symbolizer and symbolizes a backtrace.
static std::array< CallbackAndCookie, MaxSignalHandlerCallbacks > & CallBacksToRun()
static bool findModulesAndOffsets(void **StackTrace, int Depth, const char **Modules, intptr_t *Offsets, const char *MainExecutableName, StringSaver &StrPool)
static bool DisableSymbolicationFlag
static ManagedStatic< std::string > CrashDiagnosticsDirectory
static constexpr size_t MaxSignalHandlerCallbacks
constexpr char LLVMSymbolizerPathEnv[]
static void insertSignalHandler(sys::SignalHandlerCallback FnPtr, void *Cookie)
Allocate memory in an ever growing pool, as if by bump-pointer.
Represents either an error or a value T.
Tagged union holding either a T or a Error.
FileRemover - This class is a simple object meant to be stack allocated.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
empty - Check if the string is empty.
bool startswith(StringRef Prefix) const
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
A raw_ostream that writes to a file descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream.
LocationClass< Ty > location(Ty &L)
std::string getMainExecutable(const char *argv0, void *MainExecAddr)
Return the path to the main executable, given the value of argv[0] from program startup and the addre...
bool exists(const basic_file_status &status)
Does file exist?
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath, OpenFlags Flags=OF_None)
Create a file in the system temporary directory.
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
void(*)(void *) SignalHandlerCallback
int ExecuteAndWait(StringRef Program, ArrayRef< StringRef > Args, std::optional< ArrayRef< StringRef > > Env=std::nullopt, ArrayRef< std::optional< StringRef > > Redirects={}, unsigned SecondsToWait=0, unsigned MemoryLimit=0, std::string *ErrMsg=nullptr, bool *ExecutionFailed=nullptr, std::optional< ProcessStatistics > *ProcStat=nullptr, BitVector *AffinityMask=nullptr)
This function executes the program using the arguments provided.
ErrorOr< std::string > findProgramByName(StringRef Name, ArrayRef< StringRef > Paths={})
Find the first executable file Name in Paths.
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
FormattedString right_justify(StringRef Str, unsigned Width)
right_justify - add spaces before string so total output is Width characters.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void initSignalsOptions()
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
sys::SignalHandlerCallback Callback
std::atomic< Status > Flag