Isis 3 Programmer Reference
IsisDebug.h
1 #ifndef IsisDebug_h
2 #define IsisDebug_h
3 
4 #ifdef __GTHREADS
5 #error *****IsisDebug.h MUST be included before any system header files!*****
6 #endif
7 
8 void startMonitoringMemory();
9 void stopMonitoringMemory();
10 void SegmentationFault(int);
11 void Abort(int);
12 void InterruptSignal(int);
13 
14 #ifdef CWDEBUG
15 
19 #include <libcwd/sys.h>
20 #include <libcwd/debug.h>
21 #include <execinfo.h>
22 #include <dlfcn.h>
23 
24 #include <fstream>
25 #include <QMutex>
26 
33 #include "QString.h"
34 #include "Constants.h"
35 
39 #define ASSERT_PTR(x) \
40  if (libcwd::test_delete(x)) \
41  { \
42  std::cerr << ">> " << __FILE__ << ":" << __LINE__ << \
43  " error: ASSERT POINTER " << #x << " FAILED\n"; \
44  }
45 
46 class MyMutex : public QMutex {
47  public:
48  bool trylock() {
49  return tryLock();
50  }
51 };
52 
58 class StackTrace {
59  public:
70  static void GetStackTrace(std::vector<std::string> *stackTraceResult) {
71  stackTraceResult->clear();
72  const int MAX_STACK_DEPTH = 1024;
73 
74  void *stackTrace[MAX_STACK_DEPTH];
75  int stackSize = backtrace(stackTrace, MAX_STACK_DEPTH);
76 
77  for(int stackEl = 2; stackEl < stackSize; stackEl ++) {
78  std::string currElement;
79  void *addr = stackTrace[stackEl];
80 
81  libcwd::location_ct addrInfo(addr);
82  std::string demangled_name;
83  libcwd::demangle_symbol(addrInfo.mangled_function_name(), demangled_name);
84 
85  currElement = ">> ";
86 
87  if(addrInfo.is_known()) {
88  currElement +=
89  std::string(addrInfo.file()) +
90  std::string(":") +
91  QString((Isis::BigInt)addrInfo.line()) +
92  std::string(" --- ") +
93  demangled_name;
94  }
95  else {
96  currElement += "?????:0 --- " + demangled_name;
97  }
98 
99  stackTraceResult->push_back(currElement);
100  }
101  }
102 };
103 
104 #else
105 #define ASSERT_PTR(x)
106 
107 
113 class StackTrace {
114  public:
115  static void GetStackTrace(const void *) {}
116 };
117 #endif
118 
119 #ifdef DEBUG
120 #include <iostream>
121 #define ASSERT(x) \
122  if (!(x)) \
123  { \
124  std::cerr << ">> " << __FILE__ << ":" << __LINE__ << \
125  " error: ASSERT " << #x << " FAILED\n"; \
126  }
127 #else
128 #define ASSERT(x)
129 #endif
130 
131 #endif
long long int BigInt
Big int.
Definition: Constants.h:65