23 #ifdef GETFEM_HAVE_BACKTRACE 24 # include <execinfo.h> 26 #ifdef GETFEM_HAVE_CXXABI_H 35 std::string demangle(
const char *
36 #ifdef GETFEM_HAVE_CXXABI_H
40 #ifdef GETFEM_HAVE_CXXABI_H 43 char *sd = abi::__cxa_demangle(s, NULL, NULL, &status);
44 if (sd == NULL || status) {
46 return std::string(
"");
48 std::string res(sd); free(sd);
return res;
51 return std::string(
"");
55 #ifdef GETFEM_HAVE_BACKTRACE 56 void dump_glibc_backtrace() {
62 n = backtrace(trace, 256);
63 strings = backtrace_symbols (trace, n);
64 if (strings == NULL) {
65 fprintf(stderr,
"backtrace unavailable ... no more memory ?\n");
return;
67 fprintf(stderr,
"Backtrace dump follows:\n");
68 for (i = 0; i < n; ++i) {
69 char s[256]; strncpy(s,strings[i],256);s[255]=0;
70 char *a = strchr(s,
'('), *b = 0;
71 if (a) b = strchr(a,
'+');
73 fprintf(stderr,
"%2d : %s\n", i, s);
76 fprintf(stderr,
"%2d : %s(%s+%s %s\n",
77 i, s, a+1, b+1, demangle(a+1).c_str());
83 fprintf(stderr,
"ooops, a recursive bug in dump_glibc_backtrace\n");