mirror of
https://github.com/TREX-CoE/qmckl.git
synced 2024-08-24 22:21:46 +02:00
Enable FPE tracking
This commit is contained in:
parent
5228c287ad
commit
db13db8afa
12
configure.ac
12
configure.ac
@ -315,6 +315,18 @@ AC_ARG_ENABLE([hpc],
|
|||||||
AS_IF([test "x$enable_hpc" = "xyes"],
|
AS_IF([test "x$enable_hpc" = "xyes"],
|
||||||
[AC_DEFINE([HAVE_HPC], [1], [Activate HPC routines])])
|
[AC_DEFINE([HAVE_HPC], [1], [Activate HPC routines])])
|
||||||
|
|
||||||
|
|
||||||
|
AC_ARG_ENABLE([fpe],
|
||||||
|
[AS_HELP_STRING([--enable-fpe],
|
||||||
|
[Enable floating-point exceptions])],
|
||||||
|
[enable_fpe=$enableval],
|
||||||
|
[enable_fpe=no])
|
||||||
|
|
||||||
|
AS_IF([test "x$enable_fpe" = "xyes"],
|
||||||
|
[AC_DEFINE([HAVE_FPE], [1], [Activate floating-point exceptions])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AC_ARG_ENABLE([doc],
|
AC_ARG_ENABLE([doc],
|
||||||
[AS_HELP_STRING([--disable-doc],
|
[AS_HELP_STRING([--disable-doc],
|
||||||
[Disable documentation])],
|
[Disable documentation])],
|
||||||
|
@ -40,6 +40,42 @@ int main() {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_FPE
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <fenv.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <execinfo.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_BACKTRACE_SIZE 100
|
||||||
|
|
||||||
|
void floatingPointExceptionHandler(int signal) {
|
||||||
|
void* backtraceArray[MAX_BACKTRACE_SIZE];
|
||||||
|
int backtraceSize = backtrace(backtraceArray, MAX_BACKTRACE_SIZE);
|
||||||
|
char** backtraceSymbols = backtrace_symbols(backtraceArray, backtraceSize);
|
||||||
|
|
||||||
|
// Print the backtrace
|
||||||
|
for (int i = 0; i < backtraceSize; ++i) {
|
||||||
|
printf("[%d] %s\n", i, backtraceSymbols[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up the memory used by backtrace_symbols
|
||||||
|
free(backtraceSymbols);
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __attribute__ ((constructor))
|
||||||
|
trapfpe ()
|
||||||
|
{
|
||||||
|
/* Enable some exceptions. At startup all exceptions are masked. */
|
||||||
|
|
||||||
|
feenableexcept (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
|
||||||
|
signal(SIGFPE, floatingPointExceptionHandler);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "qmckl.h"
|
#include "qmckl.h"
|
||||||
#include "qmckl_context_private_type.h"
|
#include "qmckl_context_private_type.h"
|
||||||
#+end_src
|
#+end_src
|
||||||
|
Loading…
Reference in New Issue
Block a user