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