12345678910111213141516171819202122232425262728293031323334353637383940 |
- #ifndef __DEBUG_H
- #define __DEBUG_H
- #include "error_signals.h"
- // These are some macros to quickly turn on and turn off stack trace debugging in your program
- // to show the file, function, and line number the error happened at.
- // To turn stack trace on, uncomment the following line. To turn stack trace off, comment the following line:
- // Turning on stack trace causes larger and slightly slower executable code.
- // I tend to leave it on, even in production because errors happen in production and it's nice to know where.
- #define SHOULD_STACK_TRACE
- #ifdef SHOULD_STACK_TRACE
- #define DEBUG_FUNCTION Debug debug(__FILE__,__func__,__LINE__);
- #define DEBUG_LINE debug = __LINE__;
- #else
- #define DEBUG_FUNCTION
- #define DEBUG_LINE
- #endif
- // Use DEBUG_FUNCTION at the start of every function.
- // Use DEBUG_LINE several times during the function before and after critical pieces of code that might crash.
- // Example:
- // Debug debug(__FILE__,__func__,__LINE__);
- // debug = __LINE__;
- class Debug
- {
- public:
- int LineNumber;
- Debug(int lineNumber);
- Debug(const char *fileName,const char *functionName,int lineNumber);
- ~Debug();
- void SaveLineNumbers(); // Call SaveLineNumbers before rewinding the stack because Thread.LineNumbers points to LineNumber in other Debug objects.
- void operator=(int lineNumber) { LineNumber = lineNumber; };
- private:
- error_signals *_thread;
- };
- #endif
|