29 #ifdef HAVE_EXECINFO_H
31 #define BACKTRACE_LEVELMAX 0100
34 #include <lal/XLALError.h>
35 #include <lal/LALStdlib.h>
38 #define UNUSED __attribute__ ((unused))
105 const char *fmt, va_list ap)
119 const char *fmt, va_list ap)
133 const char *fmt, va_list ap)
147 const char *fmt, ...)
157 const char *fmt, ...)
167 const char *fmt, ...)
183 static const char mrk[] =
184 "+++++++++++++++++++++++++++++++++++++++++++++++++)";
185 static const char spc[] =
186 "-------------------------------------------------)";
189 floor((fraction < 0.0 ? 0.0 : fraction >
190 1.0 ? 1.0 : fraction) * l + 0.5);
192 return XLALPrintInfo(
"[%s%s %.1f%%", mrk + l - offset, spc + offset,
203 #ifndef LAL_PTHREAD_LOCK
235 pthread_key_t xlalErrnoKey;
236 pthread_once_t xlalErrnoKeyOnce = PTHREAD_ONCE_INIT;
237 pthread_key_t xlalErrorHandlerKey;
238 pthread_once_t xlalErrorHandlerKeyOnce = PTHREAD_ONCE_INIT;
241 static void XLALDestroyErrnoPtr(
void *xlalErrnoPtr)
248 static void XLALDestroyErrorHandlerPtr(
void *xlalErrorHandlerPtr)
250 free(xlalErrorHandlerPtr);
255 static void XLALCreateErrnoKey(
void)
262 static void XLALCreateErrorHandlerKey(
void)
279 xlalErrnoPtr = malloc(
sizeof(*xlalErrnoPtr));
282 (
"could not set xlal error number: malloc failed\n");
287 (
"could not set xlal error number: pthread_setspecific failed\n");
298 pthread_once(&xlalErrorHandlerKeyOnce, XLALCreateErrorHandlerKey);
302 if (!xlalErrorHandlerPtr) {
303 xlalErrorHandlerPtr = malloc(
sizeof(*xlalErrorHandlerPtr));
304 if (!xlalErrorHandlerPtr)
306 (
"could not set xlal error handler: malloc failed\n");
307 *xlalErrorHandlerPtr = NULL;
311 (
"could not set xlal error handler: pthread_setspecific failed\n");
313 return xlalErrorHandlerPtr;
418 return "Unknown return code";
424 return "Internal function call failed";
428 # define XLAL_ERROR_STRING(s) \
429 ( ( code & XLAL_EFUNC ) ? "Internal function call failed: " s : (const char *) s )
508 (
"Invalid floating point operation, eg sqrt(-1), 0/0");
532 return "Unknown error";
534 # undef XLAL_ERROR_STRING
570 const char UNUSED *
file,
int UNUSED line,
616 int line,
int errnum)
619 #if defined(HAVE_BACKTRACE) && defined(BACKTRACE_LEVELMAX)
620 void *callstack[BACKTRACE_LEVELMAX];
621 size_t frames = backtrace(callstack, BACKTRACE_LEVELMAX);
622 fprintf(stderr,
"backtrace:\n");
623 backtrace_symbols_fd(callstack, frames, fileno(stderr));
void(* lalAbortHook)(const char *,...)
int XLALPrintWarning(const char *fmt,...)
XLALErrorHandlerType * xlalErrorHandlerGlobal
void XLALPrintErrorMessage(const char *func, const char *file, int line, const char *fmt,...)
int XLALPrintInfo(const char *fmt,...)
#define XLAL_ERROR_STRING(s)
void XLALPrintWarningMessage(const char *func, const char *file, int line, const char *fmt,...)
void XLALSilentErrorHandler(const char UNUSED *func, const char UNUSED *file, int UNUSED line, int UNUSED errnum)
int XLALPrintError(const char *fmt,...)
void XLALPrintInfoMessage(const char *func, const char *file, int line, const char *fmt,...)
#define XLAL_NUM_ELEM(x)
MACRO which gives the number of elements in a fixed-size array.
@ LALINFO
enable info messages
@ LALERROR
enable error messages
@ LALWARNING
enable warning messages
void XLALBacktraceErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that prints a function call backtrace then raises SIGABRT.
int XLALVPrintError(const char *fmt, va_list ap)
Prints an error message if error printing is enabled by lalDebugLevel.
void XLALVPrintWarningMessage(const char *func, const char *file, int line, const char *fmt, va_list ap)
Print an warning message with standard XLAL formatting (if warning messages are enabled by lalDebugLe...
int XLALVPrintInfo(const char *fmt, va_list ap)
Prints an info message if info printing is enabled by lalDebugLevel.
void XLALError(const char *func, const char *file, int line, int errnum)
Routine to set the XLAL error number and invoke the XLAL error handler.
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that raises SIGABRT.
int * XLALGetErrnoPtr(void)
Function to return pointer to the XLAL error number.
XLALErrorHandlerType * XLALSetSilentErrorHandler(void)
Sets the error handler to a silent handler and returns the old handler.
int XLALVPrintWarning(const char *fmt, va_list ap)
Prints a warning message if warning printing is enabled by lalDebugLevel.
const char * XLALErrorString(int code)
Returns the error message associated with an error number.
int XLALGetBaseErrno(void)
Gets the XLAL base error number ignoring the internal-function-failed flag.
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
XLALErrorHandlerType ** XLALGetErrorHandlerPtr(void)
Function to return pointer to the XLAL error handler function pointer.
int XLALSetErrno(int errnum)
Sets the XLAL error number to errnum, returns the new value.
XLALErrorHandlerType * XLALSetDefaultErrorHandler(void)
Sets the error handler to the default handler and returns the old handler.
void XLALExitErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that calls exit.
#define XLAL_PRINT_WARNING(...)
Macro that will print a warning message with a standard format.
void XLALDefaultErrorHandler(const char *func, const char *file, int line, int errnum)
The default XLAL error handler.
void XLALVPrintInfoMessage(const char *func, const char *file, int line, const char *fmt, va_list ap)
Print an error message with standard XLAL formatting (if error messages are enabled by lalDebugLevel)...
void XLALVPrintErrorMessage(const char *func, const char *file, int line, const char *fmt, va_list ap)
Print an error message with standard XLAL formatting (if error messages are enabled by lalDebugLevel)...
void XLALErrorHandlerType(const char *func, const char *file, int line, int errnum)
The XLAL error handler type.
int XLALClearErrno(void)
Clears the XLAL error number, returns the old value.
int XLALPrintProgressBar(double fraction)
Prints a progress bar at the "info" verbosity level.
void XLALPerror(const char *func, const char *file, int line, int code)
Prints an error message for a particular error code in a standard format.
#define XLALErrorHandler
Modifiable lvalue containing the XLAL error handler.
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
Sets the error handler to a new handler and returns the old handler.
@ XLAL_ESING
Apparent singularity detected.
@ XLAL_EUSR7
User-defined error 7.
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_EUSR4
User-defined error 4.
@ XLAL_EUSR6
User-defined error 6.
@ XLAL_EFPINEXCT
IEEE Floating point inexact error.
@ XLAL_EUNIT
Invalid units.
@ XLAL_EUSR9
User-defined error 9.
@ XLAL_EUSR3
User-defined error 3.
@ XLAL_EFREQ
Invalid freqency.
@ XLAL_EDIVERGE
Series is diverging.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EDATA
Invalid data.
@ XLAL_EFPINVAL
IEEE Invalid floating point operation, eg sqrt(-1), 0/0.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EUSR0
User-defined error 0.
@ XLAL_ERANGE
Output range error.
@ XLAL_ENOENT
No such file or directory.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EMAXITER
Exceeded maximum number of iterations.
@ XLAL_ELOSS
Loss of accuracy.
@ XLAL_ETOL
Failed to reach specified tolerance.
@ XLAL_EERR
Internal error.
@ XLAL_EUSR2
User-defined error 2.
@ XLAL_EDOM
Input domain error.
@ XLAL_EUSR8
User-defined error 8.
@ XLAL_ETYPE
Wrong or unknown type.
@ XLAL_EUSR5
User-defined error 5.
@ XLAL_EUSR1
User-defined error 1.
@ XLAL_EDIMS
Wrong dimensions.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFPOVRFLW
IEEE Floating point overflow error.
@ XLAL_EFAILED
Generic failure.
@ XLAL_ENOSYS
Function not implemented.
@ XLAL_EFPUNDFLW
IEEE Floating point underflow error.
@ XLAL_ETIME
Invalid time.
@ XLAL_EFPDIV0
IEEE Division by zero floating point error.
int pthread_once(pthread_once_t *once_control, void(*init_routine)(void))
int pthread_key_create(pthread_key_t *key, destr_function destr)
void * pthread_getspecific(pthread_key_t key)
int pthread_setspecific(pthread_key_t key, const void *pointer)