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;
80 extern bool mfem_out_initialized, mfem_err_initialized;
85 #ifdef MFEM_USE_LIBUNWIND
86 char name[UNW_NAME_LEN];
90 std::ostream &merr = internal::mfem_err_initialized ?
mfem::err : std::cerr;
92 int err = unw_getcontext(&uc);
93 err = err ? err : unw_init_local(&cursor, &uc);
96 while (unw_step(&cursor) > 0 && addrs.
Size() != depth)
98 err = err ? err : unw_get_proc_name(&cursor, name, UNW_NAME_LEN, &offp);
99 err = err ? err : unw_get_reg(&cursor, UNW_REG_IP, &ip);
105 char *name_demangle =
106 abi::__cxa_demangle(name, NULL, NULL, &demangle_status);
107 if (demangle_status == 0)
109 name_p = name_demangle;
112 merr << addrs.
Size() <<
") [0x" << std::hex << ip - 1 << std::dec
113 <<
"]: " << name_p << std::endl;
116 if (demangle_status == 0)
121 #if defined(__APPLE__) || defined(__linux__)
122 if (addrs.
Size() > 0 && (mode & 1))
124 merr <<
"\nLookup backtrace source lines:";
125 const char *fname = NULL;
126 for (
int i = 0; i < addrs.
Size(); i++)
129 err = !dladdr((
void*)addrs[i], &info);
134 else if (fname != info.dli_fname)
136 fname = info.dli_fname;
139 merr <<
"addr2line -C -e " << fname;
141 merr <<
"atos -o " << fname <<
" -l "
142 << (err ? 0 : info.dli_fbase);
145 merr <<
" 0x" << std::hex << addrs[i] << std::dec;
150 #endif // MFEM_USE_LIBUNWIND
155 std::ostream &merr = internal::mfem_err_initialized ?
mfem::err : std::cerr;
161 merr <<
"\n\n" << msg <<
"\n";
164 #ifdef MFEM_USE_LIBUNWIND
165 merr <<
"Backtrace:" << std::endl;
170 #ifdef MFEM_USE_EXCEPTIONS
178 int init_flag, fin_flag;
179 MPI_Initialized(&init_flag);
180 MPI_Finalized(&fin_flag);
188 std::ostream &mout = internal::mfem_out_initialized ?
mfem::out : std::cout;
191 mout <<
"\n\n" << msg << std::endl;
int Size() const
Return the 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 'el' 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.