20 #include "libmesh/libmesh_exceptions.h" 23 #include "libmesh/libmesh.h" 24 #include "libmesh/perf_log.h" 25 #include "libmesh/print_trace.h" 28 #ifdef LIBMESH_ENABLE_EXCEPTIONS 36 #ifdef LIBMESH_HAVE_FENV_H 39 #ifdef LIBMESH_HAVE_XMMINTRIN_H 40 # include <xmmintrin.h> 50 #if LIBMESH_HAVE_DECL_SIGACTION 51 void libmesh_handleFPE(
int , siginfo_t *
info,
void * )
55 switch (
info->si_code)
57 case FPE_INTDIV:
libMesh::err <<
"integer divide by zero";
break;
58 case FPE_INTOVF:
libMesh::err <<
"integer overflow";
break;
59 case FPE_FLTDIV:
libMesh::err <<
"floating point divide by zero";
break;
60 case FPE_FLTOVF:
libMesh::err <<
"floating point overflow";
break;
61 case FPE_FLTUND:
libMesh::err <<
"floating point underflow";
break;
62 case FPE_FLTRES:
libMesh::err <<
"floating point inexact result";
break;
63 case FPE_FLTINV:
libMesh::err <<
"invalid floating point operation";
break;
64 case FPE_FLTSUB:
libMesh::err <<
"subscript out of range";
break;
69 libmesh_error_msg(
"\nTo track this down, compile in debug mode, then in gdb do:\n" \
70 <<
" break libmesh_handleFPE\n" \
76 void libmesh_handleSEGV(
int , siginfo_t *
info,
void * )
79 libMesh::err <<
"Segmentation fault exception signaled (";
80 switch (
info->si_code)
82 case SEGV_MAPERR:
libMesh::err <<
"Address not mapped";
break;
83 case SEGV_ACCERR:
libMesh::err <<
"Invalid permissions";
break;
88 libmesh_error_msg(
"\nTo track this down, compile in debug mode, then in gdb do:\n" \
89 <<
" break libmesh_handleSEGV\n" \
95 void libmesh_handleSIGINT(
int , siginfo_t * ,
void * )
97 libmesh_error_msg(
"Interrupt (Ctrl+C?) signaled!");
114 #ifdef LIBMESH_ENABLE_EXCEPTIONS 118 std::optional<std::string> exception_message;
119 std::exception_ptr ex = std::current_exception();
124 std::rethrow_exception(ex);
127 catch (
const std::exception & std_ex)
129 exception_message = std_ex.what();
149 #ifdef LIBMESH_ENABLE_EXCEPTIONS 150 if (exception_message)
196 #if !defined(LIBMESH_HAVE_FEENABLEEXCEPT) && defined(LIBMESH_HAVE_XMMINTRIN_H) 197 static int flags = 0;
202 #ifdef LIBMESH_HAVE_FEENABLEEXCEPT 203 feenableexcept(FE_DIVBYZERO | FE_INVALID);
204 #elif LIBMESH_HAVE_XMMINTRIN_H 205 flags = _MM_GET_EXCEPTION_MASK();
206 _MM_SET_EXCEPTION_MASK(flags & ~_MM_MASK_INVALID);
209 #if LIBMESH_HAVE_DECL_SIGACTION 210 struct sigaction new_action, old_action;
213 new_action.sa_sigaction = libmesh_handleFPE;
214 sigemptyset (&new_action.sa_mask);
215 new_action.sa_flags = SA_SIGINFO;
217 sigaction (SIGFPE,
nullptr, &old_action);
218 if (old_action.sa_handler != SIG_IGN)
219 sigaction (SIGFPE, &new_action,
nullptr);
224 #ifdef LIBMESH_HAVE_FEDISABLEEXCEPT 225 fedisableexcept(FE_DIVBYZERO | FE_INVALID);
226 #elif LIBMESH_HAVE_XMMINTRIN_H 227 _MM_SET_EXCEPTION_MASK(flags);
229 signal(SIGFPE, SIG_DFL);
238 #if LIBMESH_HAVE_DECL_SIGACTION 239 static struct sigaction old_action;
240 static bool was_on =
false;
244 struct sigaction new_action;
248 new_action.sa_sigaction = libmesh_handleSEGV;
249 sigemptyset (&new_action.sa_mask);
250 new_action.sa_flags = SA_SIGINFO;
252 sigaction (SIGSEGV, &new_action, &old_action);
257 sigaction (SIGSEGV, &old_action,
nullptr);
260 libmesh_error_msg(
"System call sigaction not supported.");
268 #if LIBMESH_HAVE_DECL_SIGACTION 269 static struct sigaction old_action;
270 static bool was_on =
false;
274 struct sigaction new_action;
278 new_action.sa_sigaction = libmesh_handleSIGINT;
279 sigemptyset (&new_action.sa_mask);
280 new_action.sa_flags = SA_SIGINFO;
282 sigaction (SIGINT, &new_action, &old_action);
287 sigaction (SIGINT, &old_action,
nullptr);
290 libmesh_error_msg(
"System call sigaction not supported.");
void enableSEGV(bool on)
Toggle libMesh reporting of segmentation faults.
The libMesh namespace provides an interface to certain functionality in the library.
void write_traceout()
Writes a stack trace to a uniquely named file if –enable-tracefiles has been set by configure...
void libmesh_abort()
Abort as soon as possible.
A class representing an exception used only to send a program to the terminate handler for abort afte...
static PerfLog & perf_log()
void enableFPE(bool on)
Toggle hardware trap floating point exceptions.
void print_log() const
Print the log.
void enableSIGINT(bool on)
Toggle libMesh handling of SIGINT (Ctrl+C) interrupts.
void libmesh_terminate_handler()
A terminate handler.