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.

152 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  5. //
  6. // File: debug.hxx
  7. //
  8. // Contents: Debugging macros
  9. //
  10. // History: 12-04-96 DavidMun Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #ifndef __DEBUG_HXX_
  14. #define __DEBUG_HXX_
  15. #include "stddbg.h"
  16. #undef DEBUG_DECLARE_INSTANCE_COUNTER
  17. #undef DEBUG_INCREMENT_INSTANCE_COUNTER
  18. #undef DEBUG_DECREMENT_INSTANCE_COUNTER
  19. #undef DEBUG_VERIFY_INSTANCE_COUNT
  20. //
  21. //We have DEB_USER1 to DEB_USER10 for custom debugging
  22. //
  23. #define DEB_PERF DEB_USER1 //Timer info will be shown
  24. #define DEB_DLL DEB_USER2 //Use this for all the Sanpin
  25. //Initialization stuff
  26. #define DEB_SNAPIN DEB_USER3 //Used for Snapin About
  27. #if (DBG == 1)
  28. //============================================================================
  29. //
  30. // Debug version
  31. //
  32. //============================================================================
  33. #define DBG_COMP roleInfoLevel
  34. DECLARE_DEBUG(role)
  35. #define DBG_OUT_HRESULT(hr) \
  36. DBG_COMP.DebugErrorX(THIS_FILE, __LINE__, hr)
  37. #define DBG_OUT_LRESULT(lr) \
  38. DBG_COMP.DebugErrorL(THIS_FILE, __LINE__, lr)
  39. void
  40. SayNoItf(
  41. PCSTR szComponent,
  42. REFIID riid);
  43. #define DBG_OUT_NO_INTERFACE(qi, riid) SayNoItf((qi), (riid))
  44. // Instance counter
  45. inline void DbgInstanceRemaining(char * pszClassName, int cInstRem)
  46. {
  47. char buf[100];
  48. //Fine to truncate
  49. if(SUCCEEDED(StringCchPrintfA(buf,sizeof(buf)/sizeof(char), "%s has %d instances left over.", pszClassName, cInstRem)))
  50. {
  51. //lint -save -e64
  52. Dbg(DEB_ERROR, "Memory leak: %hs\n", buf);
  53. //lint -restore
  54. ::MessageBoxA(NULL, buf, "OPD: Memory Leak", MB_OK);
  55. }
  56. }
  57. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls) \
  58. int s_cInst_##cls = 0;
  59. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls) \
  60. extern int s_cInst_##cls; \
  61. InterlockedIncrement((LPLONG) &s_cInst_##cls);
  62. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls) \
  63. extern int s_cInst_##cls; \
  64. InterlockedDecrement((LPLONG) &s_cInst_##cls);
  65. #define DEBUG_VERIFY_INSTANCE_COUNT(cls) \
  66. extern int s_cInst_##cls; \
  67. \
  68. if (s_cInst_##cls) \
  69. { \
  70. DbgInstanceRemaining(#cls, s_cInst_##cls); \
  71. }
  72. //+--------------------------------------------------------------------------
  73. //
  74. // Class: CTimer
  75. //
  76. // Purpose: Display on debugger time from ctor invocation to dtor
  77. // invocation.
  78. //
  79. // History: 12-16-1996 DavidMun Created
  80. //
  81. //---------------------------------------------------------------------------
  82. class CTimer
  83. {
  84. public:
  85. CTimer(): m_ulStart(0) { m_wzTitle[0] = L'\0'; };
  86. void __cdecl Init(LPCSTR pszTitleFmt, ...);
  87. ~CTimer();
  88. private:
  89. ULONG m_ulStart;
  90. WCHAR m_wzTitle[512];
  91. };
  92. #define TIMER CTimer TempTimer; TempTimer.Init
  93. #define PING(msg) DBG_COMP.PingDc(msg)
  94. #else // !(DBG == 1)
  95. //============================================================================
  96. //
  97. // Retail version
  98. //
  99. //============================================================================
  100. #define DBG_OUT_HRESULT(hr)
  101. #define DBG_OUT_LRESULT(lr)
  102. #define DBG_DUMP_QUERY(title, query)
  103. #define DBG_OUT_NO_INTERFACE(qi, riid)
  104. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls)
  105. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls)
  106. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls)
  107. #define DEBUG_VERIFY_INSTANCE_COUNT(cls)
  108. #define TIMER ConsumePrintf
  109. #define PING(msg)
  110. inline void __cdecl ConsumePrintf(void *fmt, ...)
  111. {
  112. }
  113. #endif // !(DBG == 1)
  114. #endif // __DEBUG_HXX_