17 #ifdef MFEM_USE_LIBUNWIND
18 #define UNW_LOCAL_ONLY
19 #define UNW_NAME_LEN 512
20 #include <libunwind.h>
22 #if defined(__APPLE__) || defined(__linux__)
28 #endif // MFEM_USE_LIBUNWIND
39 #ifdef MFEM_USE_LIBUNWIND
40 char name[UNW_NAME_LEN];
45 int err = unw_getcontext(&uc);
46 err = err ? err : unw_init_local(&cursor, &uc);
49 while (unw_step(&cursor) > 0 && addrs.
Size() != depth)
51 err = err ? err : unw_get_proc_name(&cursor, name, UNW_NAME_LEN, &offp);
52 err = err ? err : unw_get_reg(&cursor, UNW_REG_IP, &ip);
59 abi::__cxa_demangle(name, NULL, NULL, &demangle_status);
60 if (demangle_status == 0)
62 name_p = name_demangle;
65 std::cerr << addrs.
Size() <<
") [0x" << std::hex << ip - 1 << std::dec
66 <<
"]: " << name_p << std::endl;
69 if (demangle_status == 0)
74 #if defined(__APPLE__) || defined(__linux__)
75 if (addrs.
Size() > 0 && (mode & 1))
77 std::cerr <<
"\nLookup backtrace source lines:";
78 const char *fname = NULL;
79 for (
int i = 0; i < addrs.
Size(); i++)
82 err = !dladdr((
void*)addrs[i], &info);
87 else if (fname != info.dli_fname)
89 fname = info.dli_fname;
92 std::cerr <<
"addr2line -C -e " << fname;
94 std::cerr <<
"atos -o " << fname <<
" -l "
95 << (err ? 0 : info.dli_fbase);
98 std::cerr <<
" 0x" << addrs[i];
103 #endif // MFEM_USE_LIBUNWIND
113 std::cerr <<
"\n\n" << msg <<
"\n";
116 #ifdef MFEM_USE_LIBUNWIND
117 std::cerr <<
"Backtrace:" << std::endl;
119 std::cerr << std::endl;
124 MPI_Initialized(&flag);
125 if (flag) { MPI_Abort(MPI_COMM_WORLD, 1); }
134 std::cout <<
"\n\n" << msg << std::endl;
int Size() const
Logical size of the array.
void mfem_warning(const char *msg)
int Append(const T &el)
Append element to array, resize if necessary.
void mfem_error(const char *msg)
void mfem_backtrace(int mode, int depth)