Debug.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "Debug.h"
  2. Debug::Debug(int lineNumber)
  3. {
  4. pid_t thread_id;
  5. LineNumber = lineNumber;
  6. thread_id = error_signals::GetThreadID();
  7. _thread = error_signals::GetThread(thread_id);
  8. if (_thread != nullptr)
  9. {
  10. // Store a pointer to the current line number in the thread line number stack.
  11. if (_thread->LineNumberStack < error_signals::CALL_STACK_SIZE)
  12. {
  13. _thread->LineNumbers[_thread->LineNumberStack] = &LineNumber;
  14. _thread->FileNames[_thread->LineNumberStack] = nullptr;
  15. _thread->FunctionNames[_thread->LineNumberStack++] = nullptr;
  16. }
  17. }
  18. }
  19. Debug::Debug(const char *fileName,const char *functionName,int lineNumber)
  20. {
  21. pid_t thread_id;
  22. LineNumber = lineNumber;
  23. thread_id = error_signals::GetThreadID();
  24. _thread = error_signals::GetThread(thread_id);
  25. if (_thread != nullptr)
  26. {
  27. // Store a pointer to the current line number in the thread line number stack.
  28. if (_thread->LineNumberStack < error_signals::CALL_STACK_SIZE)
  29. {
  30. _thread->LineNumbers[_thread->LineNumberStack] = &LineNumber;
  31. _thread->FileNames[_thread->LineNumberStack] = fileName;
  32. _thread->FunctionNames[_thread->LineNumberStack++] = functionName;
  33. }
  34. }
  35. }
  36. void Debug::SaveLineNumbers()
  37. {
  38. if (_thread != nullptr) {
  39. _thread->SaveLineNumbers();
  40. }
  41. return;
  42. }
  43. Debug::~Debug()
  44. {
  45. if (_thread != nullptr)
  46. {
  47. // Pop the line number off the line number stack.
  48. if (_thread->LineNumberStack > 0)
  49. {
  50. _thread->LineNumberStack--;
  51. }
  52. }
  53. }