18#ifdef MFEM_USE_LIBUNWIND
20#define UNW_NAME_LEN 512
23#if defined(__APPLE__) || defined(__linux__)
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;
80extern 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_flag = unw_getcontext(&uc);
93 err_flag = err_flag ? err_flag : unw_init_local(&cursor, &uc);
96 while (unw_step(&cursor) > 0 && addrs.
Size() != depth)
98 err_flag = err_flag ? err_flag :
99 unw_get_proc_name(&cursor, name, UNW_NAME_LEN, &offp);
100 err_flag = err_flag ? err_flag : unw_get_reg(&cursor, UNW_REG_IP, &ip);
101 if (err_flag) {
break; }
106 char *name_demangle =
107 abi::__cxa_demangle(name, NULL, NULL, &demangle_status);
108 if (demangle_status == 0)
110 name_p = name_demangle;
113 merr << addrs.
Size() <<
") [0x" << std::hex << ip - 1 << std::dec
114 <<
"]: " << name_p << std::endl;
117 if (demangle_status == 0)
122#if defined(__APPLE__) || defined(__linux__)
123 if (addrs.
Size() > 0 && (mode & 1))
125 merr <<
"\nLookup backtrace source lines:";
126 const char *fname = NULL;
127 for (
int i = 0; i < addrs.
Size(); i++)
130 err_flag = !dladdr((
void*)addrs[i], &info);
135 else if (fname != info.dli_fname)
137 fname = info.dli_fname;
140 merr <<
"addr2line -C -e " << fname;
142 merr <<
"atos -o " << fname <<
" -l "
143 << (err_flag ? 0 : info.dli_fbase);
146 merr <<
" 0x" << std::hex << addrs[i] << std::dec;
156 std::ostream &merr = internal::mfem_err_initialized ?
mfem::err : std::cerr;
162 merr <<
"\n\n" << msg <<
"\n";
165#ifdef MFEM_USE_LIBUNWIND
166 merr <<
"Backtrace:" << std::endl;
171#ifdef MFEM_USE_EXCEPTIONS
179 int init_flag, fin_flag;
180 MPI_Initialized(&init_flag);
181 MPI_Finalized(&fin_flag);
189 std::ostream &mout = internal::mfem_out_initialized ?
mfem::out : std::cout;
192 mout <<
"\n\n" << msg << std::endl;
int Size() const
Return the logical size of the array.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Exception class thrown when MFEM encounters an error and the current ErrorAction is set to MFEM_ERROR...
virtual const char * what() const
void mfem_error(const char *msg)
void mfem_warning(const char *msg)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void mfem_backtrace(int mode, int depth)
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...
ErrorAction get_error_action()
Get the action MFEM takes when an error is encountered.
@ HOST
Host memory; using new[] and delete[].
MPI_Comm GetGlobalMPI_Comm()
Get MFEM's "global" MPI communicator.