Go to the documentation of this file.
19 #include "llvm/Config/llvm-config.h"
46 struct CreateDisableSymbolication {
49 "disable-symbolication",
50 cl::desc(
"Disable symbolizing crash backtraces."),
54 struct CreateCrashDiagnosticsDir {
58 cl::desc(
"Directory for crash diagnostic files."),
68 *DisableSymbolication;
81 enum class Status { Empty, Initializing, Initialized, Executing };
89 static std::array<CallbackAndCookie, MaxSignalHandlerCallbacks> &
91 static std::array<CallbackAndCookie, MaxSignalHandlerCallbacks> callbacks;
100 if (!RunMe.Flag.compare_exchange_strong(
Expected, Desired))
102 (*RunMe.Callback)(RunMe.Cookie);
103 RunMe.Callback =
nullptr;
104 RunMe.Cookie =
nullptr;
115 if (!SetMe.Flag.compare_exchange_strong(
Expected, Desired))
117 SetMe.Callback = FnPtr;
118 SetMe.Cookie = Cookie;
127 const char *MainExecutableName,
134 unsigned PtrWidth = 2 + 2 *
sizeof(
void *);
146 if (Argv0.
find(
"llvm-symbolizer") != std::string::npos)
156 }
else if (!Argv0.
empty()) {
161 if (!LLVMSymbolizerPathOrErr)
163 if (!LLVMSymbolizerPathOrErr)
165 const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr;
169 std::string MainExecutableName =
174 std::vector<const char *> Modules(
Depth,
nullptr);
177 MainExecutableName.c_str(), StrPool))
190 Input << Modules[
i] <<
" " << (
void*)
Offsets[
i] <<
"\n";
196 StringRef Args[] = {
"llvm-symbolizer",
"--functions=linkage",
"--inlining",
201 "--relative-address",
214 StringRef Output = OutputBuf.get()->getBuffer();
216 Output.split(Lines,
"\n");
217 auto CurLine = Lines.begin();
220 auto PrintLineHeader = [&]() {
222 std::log10(
Depth) + 2)
233 if (CurLine == Lines.end())
236 if (FunctionName.
empty())
240 OS << FunctionName <<
' ';
241 if (CurLine == Lines.end())
ErrorOr< std::string > findProgramByName(StringRef Name, ArrayRef< StringRef > Paths={})
Find the first executable file Name in Paths.
#define LLVM_ATTRIBUTE_USED
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
This is an optimization pass for GlobalISel generic memory operations.
LocationClass< Ty > location(Ty &L)
FileRemover - This class is a simple object meant to be stack allocated.
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static FormattedNumber format_ptr(void *PC)
Format a pointer value as hexadecimal.
Tagged union holding either a T or a Error.
constexpr char LLVMSymbolizerPathEnv[]
void(*)(void *) SignalHandlerCallback
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
void initSignalsOptions()
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
static ManagedStatic< std::string > CrashDiagnosticsDirectory
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
std::atomic< Status > Flag
static void insertSignalHandler(sys::SignalHandlerCallback FnPtr, void *Cookie)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class implements an extremely fast bulk output stream that can only output to a stream.
sys::SignalHandlerCallback Callback
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.
bool exists(const basic_file_status &status)
Does file exist?
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Allocate memory in an ever growing pool, as if by bump-pointer.
S is passed via registers r2 But gcc stores them to the and then reload them to and r3 before issuing the call(r0 contains the address of the format string)
static bool DisableSymbolicationFlag
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
static std::array< CallbackAndCookie, MaxSignalHandlerCallbacks > & CallBacksToRun()
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
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 - Represent a constant reference to a string, i.e.
A raw_ostream that writes to a file descriptor.
FormattedString right_justify(StringRef Str, unsigned Width)
right_justify - add spaces before string so total output is Width characters.
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...
StringRef str() const
Explicit conversion to StringRef.
constexpr char DisableSymbolizationEnv[]
int ExecuteAndWait(StringRef Program, ArrayRef< StringRef > Args, Optional< ArrayRef< StringRef >> Env=None, ArrayRef< Optional< StringRef >> Redirects={}, unsigned SecondsToWait=0, unsigned MemoryLimit=0, std::string *ErrMsg=nullptr, bool *ExecutionFailed=nullptr, Optional< ProcessStatistics > *ProcStat=nullptr, BitVector *AffinityMask=nullptr)
This function executes the program using the arguments provided.
Represents either an error or a value T.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static bool findModulesAndOffsets(void **StackTrace, int Depth, const char **Modules, intptr_t *Offsets, const char *MainExecutableName, StringSaver &StrPool)
static constexpr size_t MaxSignalHandlerCallbacks
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.