carl  24.04
Computer ARithmetic Library
debug.cpp
Go to the documentation of this file.
1 #include "debug.h"
2 
3 #include <boost/core/demangle.hpp>
4 
5 #define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
6 #include <boost/stacktrace.hpp>
7 
8 #include <memory>
9 #include <sstream>
10 
11 #if !defined __VS
12 #include <cxxabi.h>
13 #include <dlfcn.h>
14 #include <execinfo.h>
15 #endif
16 
17 namespace carl {
18 
19 std::string demangle(const char* name) {
20  return boost::core::demangle(name);
21 }
22 
24  std::cerr << boost::stacktrace::stacktrace();
25 }
26 
27 std::string callingFunction() {
28  std::stringstream ss;
29  ss << boost::stacktrace::stacktrace(1,1);
30  return ss.str();
31 }
32 
33 #ifndef NDEBUG
34 
37 
38 /**
39  * Actual signal handler.
40  */
41 #ifdef __VS
42 __declspec(noreturn) static void handle_signal(int signal) {
43 #else
44 [[noreturn]] static void handle_signal(int signal) {
45 #endif
46  //printStacktrace(false);
47  std::cerr << std::endl << "Catched SIGABRT " << signal << ", exiting with " << (last_assertion_code%256) << std::endl;
48  if (!last_assertion_string.empty()) {
49  std::cerr << "Last Assertion catched is: " << last_assertion_string << std::endl;
50  std::cerr << "Please check if this is the assertion that is actually thrown." << std::endl;
51  }
52  exit(last_assertion_code % 256);
53 }
54 /**
55  * Installs the signal handler.
56  */
57 static bool install_signal_handler() noexcept {
58  // CARL_LOG_INFO("carl.util", "Installing signal handler for SIGABRT");
59  // std::cerr << "Installing signal handler for SIGABRT" << std::endl;
60  std::signal(SIGABRT, handle_signal);
61  return true;
62 }
63 /**
64  * Static variable that ensures that install_signal_handler is called.
65  */
67 #endif
68 
69 }
carl is the main namespace for the library.
std::string callingFunction()
Definition: debug.cpp:27
std::string demangle(const char *name)
Definition: debug.cpp:19
static bool signal_installed
Static variable that ensures that install_signal_handler is called.
Definition: debug.cpp:66
int last_assertion_code
Stores an integer representation of the last assertion that was registered via REGISTER_ASSERT.
Definition: debug.cpp:36
static void handle_signal(int signal)
Actual signal handler.
Definition: debug.cpp:44
void printStacktrace()
Uses GDB to print a stack trace.
Definition: debug.cpp:23
static bool install_signal_handler() noexcept
Installs the signal handler.
Definition: debug.cpp:57
std::string last_assertion_string
Stores a textual representation of the last assertion that was registered via REGISTER_ASSERT.
Definition: debug.cpp:35