errabort.c (6e25c4a1c90824faf3d538972096603dc1ddc238) errabort.c (8ff741ac7cdff47f2e2eef1c0728bbec021bb9cf)
1/*
2 The default error handlers and code that allows one to change
3 error handlers.
4*/
5#include <petscsys.h> /*I "petscsys.h" I*/
6
7/*@C
8 PetscAbortErrorHandler - Error handler that calls abort on error.
9 This routine is very useful when running in the debugger, because the
1/*
2 The default error handlers and code that allows one to change
3 error handlers.
4*/
5#include <petscsys.h> /*I "petscsys.h" I*/
6
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
10 user can look directly at the stack frames and the variables.
11
12 Not Collective
13
14 Input Parameters:
15+ comm - communicator over which error occurred
11
12 Not Collective
13
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
16. line - the line number of the error (indicated by __LINE__)
17. fun - the function name
18. file - the file in which the error was detected (indicated by __FILE__)
19. mess - an error text string, usually just printed to the screen
20. n - the generic error number
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
21. p - specific error number
22- ctx - error handler context
23
24 Options Database Keys:
22- ctx - error handler context
23
24 Options Database Keys:
25+ -on_error_abort - Activates aborting when an error is encountered
26- -start_in_debugger [noxterm,lldb or gdb] [-display name] - Starts all processes in the debugger and uses `PetscAbortErrorHandler()`. By default on Linux the
27 debugger is gdb and on macOS it is lldb
25+ -on_error_abort - Activates aborting when an error is encountered
26- -start_in_debugger [noxterm,dbx,xxgdb] [-display name] - Starts all
27 processes in the debugger and uses PetscAbortErrorHandler(). By default the
28 debugger is gdb; alternatives are dbx and xxgdb.
28
29 Level: developer
30
31 Notes:
32 Users do not directly employ this routine
33
34 Use `PetscPushErrorHandler()` to set the desired error handler. The
35 currently available PETSc error handlers include `PetscTraceBackErrorHandler()`,
36 `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`.
37
38.seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHander()`, `PetscTraceBackErrorHandler()`,
29
30 Level: developer
31
32 Notes:
33 Users do not directly employ this routine
34
35 Use `PetscPushErrorHandler()` to set the desired error handler. The
36 currently available PETSc error handlers include `PetscTraceBackErrorHandler()`,
37 `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`.
38
39.seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHander()`, `PetscTraceBackErrorHandler()`,
39 `PetscAttachDebuggerErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscReturnErrorHandler()`, `PetscEmacsClientErrorHandler()`,
40 `PetscErrorType`, `PETSC_ERROR_INITIAL`, `PETSC_ERROR_REPEAT`, `PetscErrorCode`
40 `PetscAttachDebuggerErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscReturnErrorHandler()`, `PetscEmacsClientErrorHandler()`
41@*/
42PetscErrorCode PetscAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx)
43{
41@*/
42PetscErrorCode PetscAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx)
43{
44 size_t len;
45
44 PetscFunctionBegin;
45 (void)comm;
46 (void)p;
47 (void)ctx;
46 PetscFunctionBegin;
47 (void)comm;
48 (void)p;
49 (void)ctx;
48 n = (*PetscErrorPrintf)("PetscAbortErrorHandler: %s() at %s:%d %s\n To prevent termination, change the error handler using PetscPushErrorHandler()\n", fun, file, line, mess);
50 (void)PetscStrlen(fun, &len);
51 if (len) {
52 n = (*PetscErrorPrintf)("PetscAbortErrorHandler: %s() at %s:%d %s\n To prevent termination, change the error handler using PetscPushErrorHandler()\n", fun, file, line, mess);
53 } else {
54 n = (*PetscErrorPrintf)("PetscAbortErrorHandler: %s\n To prevent termination, change the error handler using PetscPushErrorHandler()\n", mess);
55 }
49 abort();
50 (void)n;
51 PetscFunctionReturn(PETSC_SUCCESS);
52}
56 abort();
57 (void)n;
58 PetscFunctionReturn(PETSC_SUCCESS);
59}