Debug.h 1021 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef __DEBUG_H
  2. #define __DEBUG_H
  3. #include "error_signals.h"
  4. // To turn debugging on, uncomment the following line. To turn debugging off, comment the following line.
  5. #define SHOULD_DEBUG
  6. #ifdef SHOULD_DEBUG
  7. #define DEBUG_FUNCTION Debug debug(__FILE__,__func__,__LINE__);
  8. #define DEBUG_LINE debug = __LINE__;
  9. #else
  10. #define DEBUG_FUNCTION
  11. #define DEBUG_LINE
  12. #endif
  13. // Use DEBUG_FUNCTION at the start of every function.
  14. // Use DEBUG_LINE several times during the function before and after critical pieces of code that might crash.
  15. // Example:
  16. // Debug debug(__FILE__,__func__,__LINE__);
  17. // debug = __LINE__;
  18. class Debug
  19. {
  20. public:
  21. int LineNumber;
  22. Debug(int lineNumber);
  23. Debug(const char *fileName,const char *functionName,int lineNumber);
  24. ~Debug();
  25. void SaveLineNumbers(); // Call SaveLineNumbers before rewinding the stack because Thread.LineNumbers points to LineNumber in other Debug objects.
  26. void operator=(int lineNumber) { LineNumber = lineNumber; };
  27. private:
  28. error_signals *_thread;
  29. };
  30. #endif