#include <Backtrace.h>
Public Member Functions | |
Backtrace (size_t maxdepth=32) | |
Captures the backtrace at the point of construction. | |
Backtrace (size_t bufsize, void **buffer) | |
Captures the backtrace at the point of construction. | |
~Backtrace () | |
std::ostream & | print (std::ostream &) const |
Prints the backtrace in human readable form. | |
void | print (int fd) const |
Prints the backtrace to a unix file descriptor: for use when out of memory. | |
Static Public Member Functions | |
static void | writeDemangled (std::ostream &out, char const *pMangled) |
Attempts to demangle a C++ name and write it to an ostream. | |
Static Private Member Functions | |
static int | lookupLibraryBase (struct dl_phdr_info *, size_t, void *) |
Private Attributes | |
size_t | depth |
const bool | ownbuf |
const size_t | bufsize |
void ** | addrbuf |
Classes | |
struct | LibraryInfo |
The constructor wraps up the backtrace of the current thread at the point of construction. A Backtrace object can be printed to an ostream.
Definition at line 46 of file Backtrace.h.
Backtrace::Backtrace | ( | size_t | maxdepth = 32 |
) |
Captures the backtrace at the point of construction.
The Backtrace object allocates its own address buffer.
maxdepth | maximum depth of backtrace |
Definition at line 46 of file Backtrace.cpp.
References addrbuf, bufsize, and depth.
00047 : ownbuf(true), bufsize(maxdepth + 1) 00048 { 00049 #ifndef __MSVC__ 00050 addrbuf = new void * [bufsize]; 00051 depth = backtrace(addrbuf, bufsize); 00052 #endif 00053 }
Backtrace::Backtrace | ( | size_t | bufsize, | |
void ** | buffer | |||
) |
Captures the backtrace at the point of construction.
The caller provides an address buffer, probably on the stack.
The buffer should contain an extra item to refer to the Backtrace constructor itself.
bufsize | buffer size, in words (sizeof(void*) = 1 word) | |
buffer | an array of BUFSIZE (void *) entries. |
Definition at line 55 of file Backtrace.cpp.
References addrbuf, and depth.
00056 : ownbuf(false), bufsize(bufsize) 00057 { 00058 #ifndef __MSVC__ 00059 addrbuf = buffer; 00060 depth = backtrace(addrbuf, bufsize); 00061 #endif 00062 }
Backtrace::~Backtrace | ( | ) |
int Backtrace::lookupLibraryBase | ( | struct dl_phdr_info * | , | |
size_t | , | |||
void * | ||||
) | [static, private] |
Definition at line 78 of file Backtrace.cpp.
References Backtrace::LibraryInfo::pImageName.
00080 { 00081 LibraryInfo *pLibInfo = reinterpret_cast<LibraryInfo *>(pData); 00082 if (strcmp(pLibInfo->pImageName, pInfo->dlpi_name) == 0) { 00083 pLibInfo->baseAddress = pInfo->dlpi_addr; 00084 return 1; 00085 } 00086 return 0; 00087 }
std::ostream& Backtrace::print | ( | std::ostream & | ) | const |
Prints the backtrace in human readable form.
Skips the Backtrace constructor.
Referenced by operator<<().
void Backtrace::print | ( | int | fd | ) | const |
Prints the backtrace to a unix file descriptor: for use when out of memory.
Definition at line 67 of file Backtrace.cpp.
References addrbuf, and depth.
00068 { 00069 #ifndef __MSVC__ 00070 // skip 1st stack frame (the Backtrace constructor) 00071 if (depth > 1) { 00072 backtrace_symbols_fd(addrbuf + 1, depth - 1, fd); 00073 } 00074 #endif 00075 }
void Backtrace::writeDemangled | ( | std::ostream & | out, | |
char const * | pMangled | |||
) | [static] |
Attempts to demangle a C++ name and write it to an ostream.
out | receives demangled name | |
pMangled | name to be demangled |
Definition at line 173 of file Backtrace.cpp.
References free().
Referenced by ExecStreamGraphImpl::DotVertexRenderer::operator()().
00174 { 00175 int status = -3; 00176 char *pDemangled = NULL; 00177 #ifndef __MSVC__ 00178 pDemangled = 00179 abi::__cxa_demangle(pMangled, NULL, NULL, &status); 00180 #endif 00181 if (status || !pDemangled) { 00182 // non-zero status means demangling failed; 00183 // use mangled name instead 00184 out << pMangled; 00185 } else { 00186 out << pDemangled; 00187 free(pDemangled); 00188 } 00189 }
size_t Backtrace::depth [private] |
const bool Backtrace::ownbuf [private] |
const size_t Backtrace::bufsize [private] |
void** Backtrace::addrbuf [private] |