18 #include "llvm/Config/config.h"
41 cl::desc(
"Disable symbolizing crash backtraces."),
51 CallBacksToRun->clear();
56 const char *MainExecutableName,
63 unsigned PtrWidth = 2 + 2 *
sizeof(
void *);
68 void **StackTrace,
int Depth,
74 void **StackTrace,
int Depth,
80 if (Argv0.
find(
"llvm-symbolizer") != std::string::npos)
93 if (!LLVMSymbolizerPathOrErr)
95 if (!LLVMSymbolizerPathOrErr)
97 const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr;
101 std::string MainExecutableName =
103 : (std::string)Argv0;
106 std::vector<const char *> Modules(Depth,
nullptr);
107 std::vector<intptr_t>
Offsets(Depth, 0);
109 MainExecutableName.c_str(), StrPool))
120 for (
int i = 0; i <
Depth; i++) {
122 Input << Modules[i] <<
" " << (
void*)Offsets[i] <<
"\n";
129 const StringRef *Redirects[] = {&InputFileStr, &OutputFileStr,
131 const char *
Args[] = {
"llvm-symbolizer",
"--functions=linkage",
"--inlining",
136 "--relative-address",
138 "--demangle",
nullptr};
149 StringRef Output = OutputBuf.get()->getBuffer();
151 Output.
split(Lines,
"\n");
152 auto CurLine = Lines.
begin();
154 for (
int i = 0; i <
Depth; i++) {
156 OS <<
'#' << frame_no++ <<
' ' <<
format_ptr(StackTrace[i]) <<
'\n';
162 if (CurLine == Lines.
end())
165 if (FunctionName.
empty())
167 OS <<
'#' << frame_no++ <<
' ' <<
format_ptr(StackTrace[i]) <<
' ';
169 OS << FunctionName <<
' ';
170 if (CurLine == Lines.
end())
176 OS <<
"(" << Modules[i] <<
'+' <<
format_hex(Offsets[i], 0) <<
")";
Represents either an error or a value T.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
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.
static cl::opt< bool > DisableSymbolication("disable-symbolication", cl::desc("Disable symbolizing crash backtraces."), cl::init(false), cl::Hidden)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
int ExecuteAndWait(StringRef Program, const char **args, const char **env=nullptr, const StringRef **redirects=nullptr, unsigned secondsToWait=0, unsigned memoryLimit=0, std::string *ErrMsg=nullptr, bool *ExecutionFailed=nullptr)
This function executes the program using the arguments provided.
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...
initializer< Ty > init(const Ty &Val)
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.
Allocate memory in an ever growing pool, as if by bump-pointer.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, int Depth, llvm::raw_ostream &OS) LLVM_ATTRIBUTE_USED
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...
This file declares helper objects for defining debug options that can be configured via the command l...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Saves strings in the inheritor's stable storage and returns a StringRef with a stable character point...
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.
ErrorOr< std::string > findProgramByName(StringRef Name, ArrayRef< StringRef > Paths=None)
Find the first executable file Name in Paths.
static ManagedStatic< std::vector< std::pair< void(*)(void *), void * > > > CallBacksToRun
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.
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.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
#define LLVM_ATTRIBUTE_USED