17 #include "llvm/Config/config.h"
46 CallBacksToRun->clear();
54 const char *MainExecutableName,
61 unsigned PtrWidth = 2 + 2 *
sizeof(
void *);
66 void **StackTrace,
int Depth,
72 void **StackTrace,
int Depth,
75 if (Argv0.
find(
"llvm-symbolizer") != std::string::npos)
88 if (!LLVMSymbolizerPathOrErr)
90 if (!LLVMSymbolizerPathOrErr)
92 const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr;
96 std::string MainExecutableName =
101 std::vector<const char *> Modules(Depth,
nullptr);
102 std::vector<intptr_t>
Offsets(Depth, 0);
104 MainExecutableName.c_str(), StrPool))
117 Input << Modules[
i] <<
" " << (
void*)Offsets[i] <<
"\n";
124 const StringRef *Redirects[] = {&InputFileStr, &OutputFileStr,
126 const char *
Args[] = {
"llvm-symbolizer",
"--functions=linkage",
"--inlining",
131 "--relative-address",
133 "--demangle",
nullptr};
144 StringRef Output = OutputBuf.get()->getBuffer();
146 Output.
split(Lines,
"\n");
147 auto CurLine = Lines.
begin();
151 OS <<
'#' << frame_no++ <<
' ' <<
format_ptr(StackTrace[i]) <<
'\n';
157 if (CurLine == Lines.
end())
160 if (FunctionName.
empty())
162 OS <<
'#' << frame_no++ <<
' ' <<
format_ptr(StackTrace[i]) <<
' ';
164 OS << FunctionName <<
' ';
165 if (CurLine == Lines.
end())
171 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.
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...
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()
Greedy Register Allocator
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...
StringRef parent_path(StringRef path)
Get parent path.
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.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
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.
Provides ErrorOr<T> smart pointer.
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...
static ManagedStatic< std::vector< std::pair< void(*)(void *), void * > > > CallBacksToRun
#define LLVM_ATTRIBUTE_USED