18 #ifdef MFEM_USE_LIBUNWIND
19 #define UNW_LOCAL_ONLY
20 #define UNW_NAME_LEN 512
21 #include <libunwind.h>
23 #if defined(__APPLE__) || defined(__linux__)
29 #endif // MFEM_USE_LIBUNWIND
38 #ifdef MFEM_USE_EXCEPTIONS
56 #ifdef MFEM_USE_EXCEPTIONS
59 mfem_error(
"set_error_action: MFEM_ERROR_THROW requires the build "
60 "option MFEM_USE_EXCEPTIONS=YES");
64 mfem::err <<
"\n\nset_error_action: invalid action: " << action
69 mfem_error_action = action;
74 return mfem_error_action;
79 #ifdef MFEM_USE_LIBUNWIND
80 char name[UNW_NAME_LEN];
85 int err = unw_getcontext(&uc);
86 err = err ? err : unw_init_local(&cursor, &uc);
89 while (unw_step(&cursor) > 0 && addrs.
Size() != depth)
91 err = err ? err : unw_get_proc_name(&cursor, name, UNW_NAME_LEN, &offp);
92 err = err ? err : unw_get_reg(&cursor, UNW_REG_IP, &ip);
99 abi::__cxa_demangle(name, NULL, NULL, &demangle_status);
100 if (demangle_status == 0)
102 name_p = name_demangle;
105 mfem::err << addrs.
Size() <<
") [0x" << std::hex << ip - 1 << std::dec
106 <<
"]: " << name_p << std::endl;
109 if (demangle_status == 0)
114 #if defined(__APPLE__) || defined(__linux__)
115 if (addrs.
Size() > 0 && (mode & 1))
117 mfem::err <<
"\nLookup backtrace source lines:";
118 const char *fname = NULL;
119 for (
int i = 0; i < addrs.
Size(); i++)
122 err = !dladdr((
void*)addrs[i], &info);
127 else if (fname != info.dli_fname)
129 fname = info.dli_fname;
132 mfem::err <<
"addr2line -C -e " << fname;
134 mfem::err <<
"atos -o " << fname <<
" -l "
135 << (err ? 0 : info.dli_fbase);
138 mfem::err <<
" 0x" << std::hex << addrs[i] << std::dec;
143 #endif // MFEM_USE_LIBUNWIND
156 #ifdef MFEM_USE_LIBUNWIND
162 #ifdef MFEM_USE_EXCEPTIONS
170 int init_flag, fin_flag;
171 MPI_Initialized(&init_flag);
172 MPI_Finalized(&fin_flag);
int Size() const
Logical size of the array.
virtual const char * what() const
ErrorAction get_error_action()
Get the action MFEM takes when an error is encountered.
Exception class thrown when MFEM encounters an error and the current ErrorAction is set to MFEM_ERROR...
int Append(const T &el)
Append element to array, resize if necessary.
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
void set_error_action(ErrorAction action)
Set the action MFEM takes when an error is encountered.
ErrorAction
Action to take when MFEM encounters an error.
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
void mfem_warning(const char *msg)
Function called by the macro MFEM_WARNING.
void mfem_backtrace(int mode, int depth)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
MPI_Comm GetGlobalMPI_Comm()
Get MFEM's "global" MPI communicator.