Debug.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __DEBUG_H
  2. #define __DEBUG_H
  3. #include "error_signals.h"
  4. // These are some macros to quickly turn on and turn off stack trace debugging in your program
  5. // to show the file, function, and line number the error happened at.
  6. // To turn stack trace on, uncomment the following line. To turn stack trace off, comment the following line:
  7. // Turning on stack trace causes larger and slightly slower executable code.
  8. // I tend to leave it on, even in production because errors happen in production and it's nice to know where.
  9. #define SHOULD_STACK_TRACE
  10. #ifdef SHOULD_STACK_TRACE
  11. #define DEBUG_FUNCTION Debug debug(__FILE__,__func__,__LINE__);
  12. #define DEBUG_LINE debug = __LINE__;
  13. #else
  14. #define DEBUG_FUNCTION
  15. #define DEBUG_LINE
  16. #endif
  17. // Use DEBUG_FUNCTION at the start of every function.
  18. // Use DEBUG_LINE several times during the function before and after critical pieces of code that might crash.
  19. // Example:
  20. // Debug debug(__FILE__,__func__,__LINE__);
  21. // debug = __LINE__;
  22. class Debug
  23. {
  24. public:
  25. int LineNumber;
  26. Debug(int lineNumber);
  27. Debug(const char *fileName,const char *functionName,int lineNumber);
  28. ~Debug();
  29. void SaveLineNumbers(); // Call SaveLineNumbers before rewinding the stack because Thread.LineNumbers points to LineNumber in other Debug objects.
  30. void operator=(int lineNumber) { LineNumber = lineNumber; };
  31. private:
  32. error_signals *_thread;
  33. };
  34. #endif