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.

134 lines
3.4 KiB

  1. /*****************************************************************************
  2. *
  3. * $Workfile: debug.cpp $
  4. *
  5. * Copyright (C) 1997 Hewlett-Packard Company.
  6. * Copyright (C) 1997 Microsoft Corporation.
  7. * All rights reserved.
  8. *
  9. * 11311 Chinden Blvd.
  10. * Boise, Idaho 83714
  11. *
  12. *****************************************************************************/
  13. #include "precomp.h"
  14. #include "debug.h"
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // Global definitions/declerations
  17. HANDLE g_hDebugFile;
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // InitDebug
  20. void
  21. InitDebug( LPTSTR pszDebugFile )
  22. {
  23. g_hDebugFile = CreateFile( pszDebugFile, // file name
  24. GENERIC_WRITE, // access mode
  25. FILE_SHARE_WRITE | FILE_SHARE_READ, // share mode
  26. NULL, // security attributes
  27. OPEN_ALWAYS, // creation
  28. FILE_ATTRIBUTE_NORMAL, // file attributes
  29. NULL ); // template file
  30. if (g_hDebugFile == INVALID_HANDLE_VALUE)
  31. {
  32. DWORD dwError = GetLastError();
  33. //_RPT1(_CRT_WARN, "\t>ERROR!! CreateFile dwError = %d\n", dwError);
  34. }
  35. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  36. _CrtSetReportFile(_CRT_WARN, (_HFILE)g_hDebugFile);
  37. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  38. _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
  39. _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  40. _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
  41. } // InitDebug()
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // DeInitDebug
  44. void
  45. DeInitDebug(void)
  46. {
  47. if (g_hDebugFile)
  48. {
  49. CloseHandle(g_hDebugFile);
  50. }
  51. } // DeInitDebug()
  52. ///////////////////////////////////////////////////////////////////////////////
  53. // debugRPT -- used w/ the macros
  54. void
  55. debugRPT(char *p, int i)
  56. {
  57. //_RPT2(_CRT_WARN, "%s %d\n", p, i);
  58. }
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // debugCSect -- used w/ the macros
  61. void
  62. debugCSect(char *p, int i, char *fileName, int lineNum, long csrc)
  63. {
  64. //_RPT4(_CRT_WARN, "%s (%d) @%s %d", p, i, fileName, lineNum);
  65. //_RPT1(_CRT_WARN, " [recursioncount=(%ld)]\n", csrc);
  66. }
  67. ///////////////////////////////////////////////////////////////////////////////
  68. // CMemoryDebug
  69. DWORD CMemoryDebug::m_dwMemUsed = 0;
  70. ///////////////////////////////////////////////////////////////////////////////
  71. // CMemoryDebug::CMemoryDebug
  72. CMemoryDebug::CMemoryDebug()
  73. {
  74. } // ::CMemoryDebug()
  75. ///////////////////////////////////////////////////////////////////////////////
  76. // CMemoryDebug::~CMemoryDebug
  77. CMemoryDebug::~CMemoryDebug()
  78. {
  79. } // ::~CMemoryDebug()
  80. ///////////////////////////////////////////////////////////////////////////////
  81. // operator new
  82. void *
  83. CMemoryDebug::operator new(size_t in s)
  84. {
  85. m_dwMemUsed += s;
  86. //_RPT2(_CRT_WARN, "DEBUG -- operator new() ----- Bytes allocated = %d, Total Memory used upto date = %d\n", s, m_dwMemUsed);
  87. return (void *) new char[s];
  88. } // ::operator new()
  89. ///////////////////////////////////////////////////////////////////////////////
  90. // operator delete
  91. void
  92. CMemoryDebug::operator delete(void in *p,
  93. size_t in s)
  94. {
  95. m_dwMemUsed -= s;
  96. //_RPT2(_CRT_WARN, "DEBUG -- operator delete() ----- Bytes deleted = %d,Total Memory used upto date = %d\n", s, m_dwMemUsed);
  97. delete [] p;
  98. } // ::operator delete()