18 #include "llvm/Config/llvm-config.h" 45 cl::desc(
"Disable symbolizing crash backtraces."),
54 enum class Status {
Empty, Initializing, Initialized, Executing };
63 auto &RunMe = CallBacksToRun[
I];
66 if (!RunMe.Flag.compare_exchange_strong(
Expected, Desired))
68 (*RunMe.Callback)(RunMe.Cookie);
69 RunMe.Callback =
nullptr;
70 RunMe.Cookie =
nullptr;
79 auto &SetMe = CallBacksToRun[
I];
82 if (!SetMe.Flag.compare_exchange_strong(
Expected, Desired))
84 SetMe.Callback = FnPtr;
85 SetMe.Cookie = Cookie;
94 const char *MainExecutableName,
101 unsigned PtrWidth = 2 + 2 *
sizeof(
void *);
109 if (DisableSymbolicationFlag)
113 if (Argv0.
find(
"llvm-symbolizer") != std::string::npos)
121 if (!Argv0.
empty()) {
126 if (!LLVMSymbolizerPathOrErr)
128 if (!LLVMSymbolizerPathOrErr)
130 const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr;
134 std::string MainExecutableName =
136 : (std::string)Argv0;
139 std::vector<const char *> Modules(Depth,
nullptr);
140 std::vector<intptr_t>
Offsets(Depth, 0);
142 MainExecutableName.c_str(), StrPool))
153 for (
int i = 0; i <
Depth; i++) {
155 Input << Modules[i] <<
" " << (
void*)Offsets[i] <<
"\n";
161 StringRef Args[] = {
"llvm-symbolizer",
"--functions=linkage",
"--inlining",
166 "--relative-address",
179 StringRef Output = OutputBuf.get()->getBuffer();
181 Output.
split(Lines,
"\n");
182 auto CurLine = Lines.
begin();
184 for (
int i = 0; i <
Depth; i++) {
185 auto PrintLineHeader = [&]() {
198 if (CurLine == Lines.
end())
201 if (FunctionName.
empty())
205 OS << FunctionName <<
' ';
206 if (CurLine == Lines.
end())
212 OS <<
"(" << Modules[i] <<
'+' <<
format_hex(Offsets[i], 0) <<
")";
Represents either an error or a value T.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
void(*)(void *) SignalHandlerCallback
ErrorOr< std::string > findProgramByName(StringRef Name, ArrayRef< StringRef > Paths={})
Find the first executable file Name in Paths.
sys::SignalHandlerCallback Callback
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
static cl::opt< bool, true > DisableSymbolication("disable-symbolication", cl::desc("Disable symbolizing crash backtraces."), cl::location(DisableSymbolicationFlag), cl::Hidden)
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)
This function executes the program using the arguments provided.
static bool findModulesAndOffsets(void **StackTrace, int Depth, const char **Modules, intptr_t *Offsets, const char *MainExecutableName, StringSaver &StrPool)
FileRemover - This class is a simple object meant to be stack allocated.
Tagged union holding either a T or a Error.
static bool DisableSymbolicationFlag
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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...
#define LLVM_ATTRIBUTE_USED
Allocate memory in an ever growing pool, as if by bump-pointer.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
std::atomic< Status > Flag
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
This file declares helper objects for defining debug options that can be configured via the command l...
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
A raw_ostream that writes to a file descriptor.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
static CallbackAndCookie CallBacksToRun[MaxSignalHandlerCallbacks]
Provides ErrorOr<T> smart pointer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
static constexpr size_t MaxSignalHandlerCallbacks
static void insertSignalHandler(sys::SignalHandlerCallback FnPtr, void *Cookie)
This class implements an extremely fast bulk output stream that can only output to a stream...
static FormattedNumber format_ptr(void *PC)
Format a pointer value as hexadecimal.
StringRef - Represent a constant reference to a string, i.e.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
LocationClass< Ty > location(Ty &L)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.