|
|
@ -9,16 +9,18 @@ |
|
|
|
#include <execinfo.h> |
|
|
|
#include <execinfo.h> |
|
|
|
#include <cxxabi.h> |
|
|
|
#include <cxxabi.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
/** Print a demangled stack backtrace of the caller function to FILE* out. */ |
|
|
|
/** Print a demangled stack backtrace of the caller function to FILE* out. */ |
|
|
|
static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames = 63) |
|
|
|
static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames = 63) |
|
|
|
{ |
|
|
|
{ |
|
|
|
fprintf(out, "stack trace:\n"); |
|
|
|
fprintf(out, "stack trace:\n"); |
|
|
|
|
|
|
|
|
|
|
|
// storage array for stack trace address data
|
|
|
|
// storage array for stack trace address data
|
|
|
|
void *addrlist[max_frames + 1]; |
|
|
|
std::vector<void *> addrlist(max_frames + 1); |
|
|
|
|
|
|
|
|
|
|
|
// retrieve current stack addresses
|
|
|
|
// retrieve current stack addresses
|
|
|
|
int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void *)); |
|
|
|
int addrlen = backtrace(addrlist.data(), addrlist.size()); |
|
|
|
|
|
|
|
|
|
|
|
if (addrlen == 0) { |
|
|
|
if (addrlen == 0) { |
|
|
|
fprintf(out, " <empty, possibly corrupt>\n"); |
|
|
|
fprintf(out, " <empty, possibly corrupt>\n"); |
|
|
@ -27,7 +29,7 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames |
|
|
|
|
|
|
|
|
|
|
|
// resolve addresses into strings containing "filename(function+address)",
|
|
|
|
// resolve addresses into strings containing "filename(function+address)",
|
|
|
|
// this array must be free()-ed
|
|
|
|
// this array must be free()-ed
|
|
|
|
char * *symbollist = backtrace_symbols(addrlist, addrlen); |
|
|
|
char * *symbollist = backtrace_symbols(addrlist.data(), addrlen); |
|
|
|
|
|
|
|
|
|
|
|
// allocate string which will be filled with the demangled function name
|
|
|
|
// allocate string which will be filled with the demangled function name
|
|
|
|
size_t funcnamesize = 256; |
|
|
|
size_t funcnamesize = 256; |
|
|
|