Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. #ifndef _DBG_HXX
  2. #define _DBG_HXX
  3. #if defined(_MSC_VER) && defined(_DEBUG)
  4. //////////////
  5. //
  6. // Debug routines for memory leakage/overwrite checking
  7. // These will only work on Microsoft's C Runtime Debug Library.
  8. //
  9. //////////////
  10. // The following macros set and clear, respectively, given bits
  11. // of the C runtime library debug flag, as specified by a bitmask.
  12. #define SET_CRT_DEBUG_FIELD(a) \
  13. _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
  14. #define CLEAR_CRT_DEBUG_FIELD(a) \
  15. _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
  16. void InitDbg(void)
  17. {
  18. // Send all reports to STDOUT
  19. _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
  20. _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
  21. _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
  22. _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
  23. _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
  24. _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
  25. // Set the debug-heap flag so that memory leaks are reported when
  26. // the process terminates. Then, exit.
  27. // Also, check the integrity of memory at every allocation and deallocation
  28. // *NOTE:* this will slow down the program substantially.
  29. SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF| _CRTDBG_CHECK_ALWAYS_DF );
  30. }
  31. class CInitDbg
  32. {
  33. CInitDbg()
  34. {
  35. printf("(**) Setting up memory \n");
  36. InitDbg();
  37. }
  38. ~CInitDbg() {}
  39. };
  40. // we define a static variable here and let the constructor do the
  41. // initialization automatically
  42. static CInitDbg theInitDbg;
  43. #else // #if defined(_MSC_VER) && defined(_DEBUG)
  44. #define SET_CRT_DEBUG_FIELD(a) ((void) 0)
  45. #define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
  46. #define InitDbg() ((void) 0)
  47. #ifndef _MSC_VER
  48. #define _CrtCheckMemory() (TRUE)
  49. #endif
  50. #endif // #if defined(_MSC_VER) && defined(_DEBUG)
  51. #endif // #ifndef _DBG_HXX