Actual source code: errabort.c

  1: /*
  2:        The default error handlers and code that allows one to change
  3:    error handlers.
  4: */
  5: #include <petscsys.h>

  7: /*@C
  8:   PetscAbortErrorHandler - Error handler that calls abort on error.
  9:   This routine is very useful when running in the debugger, because the
 10:   user can look directly at the stack frames and the variables where the error occurred

 12:   Not Collective, No Fortran Support

 14:   Input Parameters:
 15: + comm - communicator over which error occurred
 16: . line - the line number of the error (usually indicated by `__LINE__` in the calling routine)
 17: . fun  - the function name of the calling routine
 18: . file - the file in which the error was detected (usually indicated by `__FILE__` in the calling routine)
 19: . mess - an error text string, usually this is just printed to the screen
 20: . n    - the generic error number
 21: . p    - `PETSC_ERROR_INITIAL` indicates this is the first time the error handler is being called while `PETSC_ERROR_REPEAT` indicates it was previously called
 22: - ctx  - error handler context

 24:   Options Database Keys:
 25: + -on_error_abort                                 - Activates aborting when an error is encountered
 26: . -start_in_debugger [(noxterm)],[(lldb|gdb|...)] - Starts all processes in the debugger and uses `PetscAbortErrorHandler()`. By default on Linux the
 27:                                                     debugger is gdb and on macOS it is lldb. On Linux it opens a new xterm and on macOS it opens a new
 28:                                                     Terminal for the debugger unless `noxterm` is given
 29: - -display name                                   - Uses the X-Windows display name to open the xterms

 31:   Level: developer

 33:   Notes:
 34:   Users do not directly employ this routine

 36:   Use `PetscPushErrorHandler()` to set the desired error handler.  The
 37:   currently available PETSc error handlers include `PetscTraceBackErrorHandler()`,
 38:   `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`.

 40: .seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHander()`, `PetscTraceBackErrorHandler()`,
 41:           `PetscAttachDebuggerErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscReturnErrorHandler()`, `PetscEmacsClientErrorHandler()`,
 42:           `PetscErrorType`, `PETSC_ERROR_INITIAL`, `PETSC_ERROR_REPEAT`, `PetscErrorCode`
 43: @*/
 44: PetscErrorCode PetscAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, PetscCtx ctx)
 45: {
 46:   size_t len;

 48:   PetscFunctionBegin;
 49:   (void)comm;
 50:   (void)p;
 51:   (void)ctx;
 52:   (void)n;
 53:   (void)PetscStrlen(fun, &len);
 54:   if (len) {
 55:     (void)(*PetscErrorPrintf)("PetscAbortErrorHandler: %s() at %s:%d %s\n  To prevent termination, change the error handler using PetscPushErrorHandler()\n", fun, file, line, mess);
 56:   } else {
 57:     (void)(*PetscErrorPrintf)("PetscAbortErrorHandler: %s\n  To prevent termination, change the error handler using PetscPushErrorHandler()\n", mess);
 58:   }
 59:   abort();
 60:   PetscFunctionReturn(PETSC_SUCCESS);
 61: }