13 #ifndef STXXL_UTILS_STACKTRACE_HEADER
14 #define STXXL_UTILS_STACKTRACE_HEADER
29 fprintf(out,
"stack trace:\n");
32 void** addrlist = (
void**)alloca(max_frames *
sizeof(
void*));
35 int addrlen = backtrace(addrlist, max_frames);
38 fprintf(out,
" <empty, possibly corrupt>\n");
44 char** symbollist = backtrace_symbols(addrlist, addrlen);
47 size_t funcnamesize = 256;
48 char* funcname = (
char*)
malloc(funcnamesize);
52 for (
int i = 1; i < addrlen; i++)
54 char* begin_name = 0, * begin_offset = 0, * end_offset = 0;
58 for (
char* p = symbollist[i]; *p; ++p)
64 else if (*p ==
')' && begin_offset) {
70 if (begin_name && begin_offset && end_offset
71 && begin_name < begin_offset)
74 *begin_offset++ =
'\0';
82 char* ret = abi::__cxa_demangle(begin_name,
83 funcname, &funcnamesize, &status);
86 fprintf(out,
" %s : %s+%s\n",
87 symbollist[i], funcname, begin_offset);
92 fprintf(out,
" %s : %s()+%s\n",
93 symbollist[i], begin_name, begin_offset);
99 fprintf(out,
" %s\n", symbollist[i]);
109 #endif // !STXXL_UTILS_STACKTRACE_HEADER
void * malloc(size_t size)
static void print_stacktrace(FILE *out=stderr, unsigned int max_frames=64)
#define STXXL_BEGIN_NAMESPACE
#define STXXL_END_NAMESPACE