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.

237 lines
6.2 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1999
  5. //
  6. // File: StdDbg.h
  7. //
  8. // Contents: Common debug definitions.
  9. //
  10. // History: 5/20/1996 RaviR Created
  11. //
  12. //____________________________________________________________________________
  13. #include "admindbg.h"
  14. //
  15. // EXAMPLE: A debug file for component SAMPLE, with the debugging tag
  16. // name "Samp" is defined as shown below:
  17. //
  18. //
  19. // //
  20. // // File: SampDbg.h
  21. // //
  22. //
  23. // #ifndef _SAMPDBG_H_
  24. // #define _SAMPDBG_H_
  25. //
  26. // #include "stddbg.h"
  27. //
  28. // #if DBG==1
  29. // DECLARE_DEBUG(Samp)
  30. // #define DBG_COMP SampInfoLevel
  31. // #endif // DBG==1
  32. //
  33. // #endif // _SAMPDBG_H_
  34. //
  35. //
  36. // A corresponding DECLARE_INFOLEVEL(Samp) should be implemented in a .cpp
  37. // file. This creates a global instance of an CDbg -> SampInfoLevel.
  38. // SampInfoLevel can be initialized by setting the "Samp" value under reg key
  39. //
  40. // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AdminDebug
  41. //
  42. // By defalut it is set to (DEB_ERROR | DEB_WARN)
  43. //
  44. //
  45. // ------------------------------------------------------------------------
  46. // Method: CDbg::DebugOut(debug_level, lpstrfmt, ...);
  47. //
  48. // Where debug_level is a combination of one or more of the DEB_XXX
  49. // values defined in admindbg.h. If ((SampInfoLevel & debug_level) != 0)
  50. // The string lpstrfmt will be printed out to the debugger.
  51. //
  52. // ------------------------------------------------------------------------
  53. // Method: CDbg::Trace(lpstrfmt, ...);
  54. //
  55. // Same as CDbg::DebugOut, except that debug_level is internally
  56. // set to DEB_TRACE.
  57. //
  58. // ------------------------------------------------------------------------
  59. // Method: DebugMsg(file, line, message)
  60. //
  61. // Force output the <file, line, message>.
  62. //
  63. // ------------------------------------------------------------------------
  64. //
  65. #ifndef __STDDBG_HXX__
  66. #define __STDDBG_HXX__
  67. //
  68. // C++ files redefine THIS_FILE by adding the following two lines:
  69. //
  70. // #undef THIS_FILE
  71. // static char THIS_FILE[] = __FILE__;
  72. //
  73. #define THIS_FILE __FILE__
  74. #define DEB_RESOURCE DEB_USER10 // Constructor/Destructor
  75. #define DEB_METHOD DEB_USER11
  76. #define DEB_FUNCTION DEB_USER12
  77. #undef TRACE
  78. #undef ASSERT
  79. #undef VERIFY
  80. #if DBG==1
  81. #define Dbg DBG_COMP.DebugOut
  82. #define TRACE DBG_COMP.Trace
  83. // Heap checking
  84. extern DWORD dwHeapChecking;
  85. #define DECLARE_HEAPCHECKING DWORD dwHeapChecking = 0
  86. #define DEBUGCHECK \
  87. if ( (dwHeapChecking & 0x1) == 0x1 ) \
  88. { \
  89. HeapValidate(GetProcessHeap(),0,NULL); \
  90. } else 1
  91. // Debug messages
  92. #define TRACE_CONSTRUCTOR(cls) \
  93. Dbg(DEB_RESOURCE, _T(#cls) _T("::") _T(#cls) _T("<%x>\n"), this);
  94. #define TRACE_DESTRUCTOR(cls) \
  95. Dbg(DEB_RESOURCE, _T(#cls) _T("::~") _T(#cls) _T("<%x>\n"), this);
  96. #define TRACE_METHOD(Class, Method) \
  97. DEBUGCHECK; \
  98. Dbg(DEB_METHOD, _T(#Class) _T("::") _T(#Method) _T("(%x)\n"), this);
  99. #define TRACE_FUNCTION(Function) \
  100. DEBUGCHECK; \
  101. Dbg(DEB_FUNCTION, _T(#Function) _T("\n"));
  102. #define CHECK_HRESULT(hr) \
  103. if ( FAILED(hr) ) \
  104. { \
  105. DBG_COMP.DebugErrorX(THIS_FILE, __LINE__, hr); \
  106. } else 1
  107. #define CHECK_LASTERROR(lr) \
  108. if ( lr != ERROR_SUCCESS ) \
  109. { \
  110. DBG_COMP.DebugErrorL(THIS_FILE, __LINE__, lr); \
  111. } else 1
  112. #define DBG_OUT_LASTERROR \
  113. DBG_COMP.DebugErrorL(THIS_FILE, __LINE__, GetLastError());
  114. #define ASSERTMSG(x) \
  115. (void)((x) || (DBG_COMP.DebugMsg(THIS_FILE, __LINE__, _T(#x)),0))
  116. #define VERIFYMSG(e) ASSERTMSG(e)
  117. #define ASSERT(x) Win4Assert(x)
  118. #define VERIFY(x) Win4Assert(x)
  119. #else
  120. inline void __DummyDbg(ULONG, LPCWSTR, ...) { }
  121. inline void __DummyDbg(ULONG, LPCSTR, ...) { }
  122. #define Dbg 1 ? (void)0 : ::__DummyDbg
  123. inline void __DummyTrace(LPCWSTR, ...) { }
  124. inline void __DummyTrace(LPCSTR, ...) { }
  125. #define TRACE 1 ? (void)0 : ::__DummyTrace
  126. #define TRACE_SCOPE(x)
  127. #define DECLARE_HEAPCHECKING
  128. #define DEBUGCHECK
  129. #define TRACE_CONSTRUCTOR(cls)
  130. #define TRACE_DESTRUCTOR(cls)
  131. #define TRACE_METHOD(ClassName,MethodName)
  132. #define TRACE_FUNCTION(FunctionName)
  133. #define CHECK_HRESULT(hr)
  134. #define CHECK_LASTERROR(lr)
  135. #define DBG_OUT_LASTERROR
  136. #define ASSERTMSG(e)
  137. #define VERIFYMSG(e) e
  138. #define ASSERT(e)
  139. #define VERIFY(e) e
  140. #endif // DBG==1
  141. #if DBG==1 && defined(_NODEMGR_DLL_)
  142. // Debug instance counter
  143. inline void DbgInstanceRemaining(char * pszClassName, int cInstRem)
  144. {
  145. char buf[100];
  146. wsprintfA(buf, "%s has %d instances left over.", pszClassName, cInstRem);
  147. ::MessageBoxA(NULL, buf, "MMC: Memory Leak!!!", MB_OK);
  148. }
  149. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls) extern int s_cInst_##cls = 0;
  150. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls) extern int s_cInst_##cls; ++(s_cInst_##cls);
  151. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls) extern int s_cInst_##cls; --(s_cInst_##cls);
  152. #define DEBUG_VERIFY_INSTANCE_COUNT(cls) \
  153. extern int s_cInst_##cls; \
  154. if (s_cInst_##cls) DbgInstanceRemaining(#cls, s_cInst_##cls);
  155. #else
  156. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls)
  157. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls)
  158. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls)
  159. #define DEBUG_VERIFY_INSTANCE_COUNT(cls)
  160. #endif
  161. #ifdef UNICODE
  162. #define DBGSTRING %ls
  163. #else
  164. #define DBGSTRING %s
  165. #endif
  166. #define SAFEDBGBSTR(x) ((x==NULL)?L"<NULL>":x)
  167. #define SAFEDBGTCHAR(x) ((x==NULL)?_T("<NULL>"):x)
  168. #define ASSERT_OBJECTPTR(x) ASSERT( NULL == (x) || !::IsBadWritePtr(x,sizeof(x)) );
  169. #define ASSERT_STRINGPTR(x) ASSERT( NULL == (x) || AfxIsValidStringPtr(x) );
  170. #define FREE_OBJECTPTR(x) { ASSERT_OBJECTPTR(x); delete x; x = NULL; }
  171. #ifdef DBX
  172. #define DbxAssert(x) ASSERT(x)
  173. #define DbxMsg(sz) ::MessageBox(NULL, sz, _T("MMC"), MB_OK|MB_APPLMODAL)
  174. #else
  175. #define DbxAssert(x)
  176. #define DbxMsg(sz)
  177. #endif
  178. #endif // __STDDBG_HXX__