Leaked source code of windows server 2003
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.

65 lines
1.9 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. /*
  20. _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
  21. _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
  22. _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
  23. _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
  24. _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
  25. _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
  26. */
  27. // Set the debug-heap flag so that memory leaks are reported when
  28. // the process terminates. Then, exit.
  29. // Also, check the integrity of memory at every allocation and deallocation
  30. // *NOTE:* this will slow down the program substantially.
  31. //SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF| _CRTDBG_CHECK_ALWAYS_DF );
  32. }
  33. class CInitDbg
  34. {
  35. public:
  36. CInitDbg()
  37. {
  38. printf("(**) Setting up memory \n");
  39. InitDbg();
  40. }
  41. ~CInitDbg() {}
  42. };
  43. // we define a static variable here and let the constructor do the
  44. // initialization automatically
  45. static CInitDbg theInitDbg;
  46. #else // #if defined(_MSC_VER) && defined(_DEBUG)
  47. #define SET_CRT_DEBUG_FIELD(a) ((void) 0)
  48. #define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
  49. #define InitDbg() ((void) 0)
  50. #ifndef _MSC_VER
  51. #define _CrtCheckMemory() (TRUE)
  52. #endif
  53. #endif // #if defined(_MSC_VER) && defined(_DEBUG)
  54. #endif // #ifndef _DBG_HXX