Isis Developer Reference
IsisDebug.h
Go to the documentation of this file.
1 #ifndef IsisDebug_h
2 #define IsisDebug_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 #ifdef __GTHREADS
11 #error *****IsisDebug.h MUST be included before any system header files!*****
12 #endif
13 
17 void Abort(int);
18 void InterruptSignal(int);
19 
20 #ifdef CWDEBUG
21 
25 #include <libcwd/sys.h>
26 #include <libcwd/debug.h>
27 #include <execinfo.h>
28 #include <dlfcn.h>
29 
30 #include <fstream>
31 #include <QMutex>
32 
39 #include "QString.h"
40 #include "Constants.h"
41 
45 #define ASSERT_PTR(x) \
46  if (libcwd::test_delete(x)) \
47  { \
48  std::cerr << ">> " << __FILE__ << ":" << __LINE__ << \
49  " error: ASSERT POINTER " << #x << " FAILED\n"; \
50  }
51 
52 class MyMutex : public QMutex {
53  public:
54  bool trylock() {
55  return tryLock();
56  }
57 };
58 
64 class StackTrace {
65  public:
76  static void GetStackTrace(std::vector<std::string> *stackTraceResult) {
77  stackTraceResult->clear();
78  const int MAX_STACK_DEPTH = 1024;
79 
80  void *stackTrace[MAX_STACK_DEPTH];
81  int stackSize = backtrace(stackTrace, MAX_STACK_DEPTH);
82 
83  for(int stackEl = 2; stackEl < stackSize; stackEl ++) {
84  std::string currElement;
85  void *addr = stackTrace[stackEl];
86 
87  libcwd::location_ct addrInfo(addr);
88  std::string demangled_name;
89  libcwd::demangle_symbol(addrInfo.mangled_function_name(), demangled_name);
90 
91  currElement = ">> ";
92 
93  if(addrInfo.is_known()) {
94  currElement +=
95  std::string(addrInfo.file()) +
96  std::string(":") +
97  QString((Isis::BigInt)addrInfo.line()) +
98  std::string(" --- ") +
99  demangled_name;
100  }
101  else {
102  currElement += "?????:0 --- " + demangled_name;
103  }
104 
105  stackTraceResult->push_back(currElement);
106  }
107  }
108 };
109 
110 #else
111 #define ASSERT_PTR(x)
112 
113 
119 class StackTrace {
120  public:
121  static void GetStackTrace(const void *) {}
122 };
123 #endif
124 
125 #ifdef DEBUG
126 #include <iostream>
127 #define ASSERT(x) \
128  if (!(x)) \
129  { \
130  std::cerr << ">> " << __FILE__ << ":" << __LINE__ << \
131  " error: ASSERT " << #x << " FAILED\n"; \
132  }
133 #else
134 #define ASSERT(x)
135 #endif
136 
137 #endif
SegmentationFault
void SegmentationFault(int)
StackTrace::GetStackTrace
static void GetStackTrace(const void *)
Definition: IsisDebug.h:121
InterruptSignal
void InterruptSignal(int)
stopMonitoringMemory
void stopMonitoringMemory()
StackTrace
Definition: IsisDebug.h:119
startMonitoringMemory
void startMonitoringMemory()
This is free and unencumbered software released into the public domain.
Abort
void Abort(int)
Isis::BigInt
long long int BigInt
Big int.
Definition: Constants.h:49
Constants.h