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.

232 lines
6.3 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  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. #include <tchar.h>
  15. //
  16. // EXAMPLE: A debug file for component SAMPLE, with the debugging tag
  17. // name "Samp" is defined as shown below:
  18. //
  19. //
  20. // //
  21. // // File: SampDbg.h
  22. // //
  23. //
  24. // #ifndef _SAMPDBG_H_
  25. // #define _SAMPDBG_H_
  26. //
  27. // #include "stddbg.h"
  28. //
  29. // #if DBG==1
  30. // DECLARE_DEBUG(Samp)
  31. // #define DBG_COMP SampInfoLevel
  32. // #endif // DBG==1
  33. //
  34. // #endif // _SAMPDBG_H_
  35. //
  36. //
  37. // A corresponding DECLARE_INFOLEVEL(Samp) should be implemented in a .cpp
  38. // file. This creates a global instance of an CDbg -> SampInfoLevel.
  39. // SampInfoLevel can be initialized by setting the "Samp" value under reg key
  40. //
  41. // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AdminDebug
  42. //
  43. // By defalut it is set to (DEB_ERROR | DEB_WARN)
  44. //
  45. //
  46. // ------------------------------------------------------------------------
  47. // Method: CDbg::DebugOut(debug_level, lpstrfmt, ...);
  48. //
  49. // Where debug_level is a combination of one or more of the DEB_XXX
  50. // values defined in admindbg.h. If ((SampInfoLevel & debug_level) != 0)
  51. // The string lpstrfmt will be printed out to the debugger.
  52. //
  53. // ------------------------------------------------------------------------
  54. // Method: CDbg::Trace(lpstrfmt, ...);
  55. //
  56. // Same as CDbg::DebugOut, except that debug_level is internally
  57. // set to DEB_TRACE.
  58. //
  59. // ------------------------------------------------------------------------
  60. // Method: DebugMsg(file, line, message)
  61. //
  62. // Force output the <file, line, message>.
  63. //
  64. // ------------------------------------------------------------------------
  65. //
  66. #ifndef __STDDBG_HXX__
  67. #define __STDDBG_HXX__
  68. #undef ASSERT
  69. #undef ASSERTMSG
  70. //
  71. // C++ files redefine THIS_FILE by adding the following two lines:
  72. //
  73. // #undef THIS_FILE
  74. // static char THIS_FILE[] = __FILE__;
  75. //
  76. #define THIS_FILE __FILE__
  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. #define DBG_INDENTER \
  92. CIndenter Indent(&DBG_COMP)
  93. // Debug messages
  94. #define TRACE_CONSTRUCTOR(cls) \
  95. DEBUGCHECK; \
  96. Dbg(DEB_RESOURCE, _T(#cls) _T("::") _T(#cls) _T("<%x>\n"), this); \
  97. DBG_INDENTER;
  98. #define TRACE_DESTRUCTOR(cls) \
  99. DEBUGCHECK; \
  100. Dbg(DEB_RESOURCE, _T(#cls) _T("::~") _T(#cls) _T("<%x>\n"), this); \
  101. DBG_INDENTER;
  102. #define TRACE_METHOD(Class, Method) \
  103. DEBUGCHECK; \
  104. Dbg(DEB_METHOD, _T(#Class) _T("::") _T(#Method) _T("(%x)\n"), this); \
  105. DBG_INDENTER;
  106. #define TRACE_FUNCTION(Function) \
  107. DEBUGCHECK; \
  108. Dbg(DEB_FUNCTION, _T(#Function) _T("\n")); \
  109. DBG_INDENTER;
  110. #define TRACE_CONSTRUCTOR_EX(Infolevel, cls) \
  111. DEBUGCHECK; \
  112. Dbg(Infolevel, _T(#cls) _T("::") _T(#cls) _T("<%x>\n"), this); \
  113. DBG_INDENTER;
  114. #define TRACE_DESTRUCTOR_EX(Infolevel, cls) \
  115. DEBUGCHECK; \
  116. Dbg(Infolevel, _T(#cls) _T("::~") _T(#cls) _T("<%x>\n"), this); \
  117. DBG_INDENTER;
  118. #define TRACE_METHOD_EX(Infolevel, Class, Method) \
  119. DEBUGCHECK; \
  120. Dbg(Infolevel, _T(#Class) _T("::") _T(#Method) _T("(%x)\n"), this); \
  121. DBG_INDENTER;
  122. #define TRACE_FUNCTION_EX(Infolevel, Function) \
  123. DEBUGCHECK; \
  124. Dbg(Infolevel, _T(#Function) _T("\n")); \
  125. DBG_INDENTER;
  126. #define CHECK_HRESULT(hr) \
  127. if ( FAILED(hr) ) \
  128. { \
  129. DBG_COMP.DebugErrorX(THIS_FILE, __LINE__, hr); \
  130. } else 1
  131. #define CHECK_LASTERROR(lr) \
  132. if ( lr != ERROR_SUCCESS ) \
  133. { \
  134. DBG_COMP.DebugErrorL(THIS_FILE, __LINE__, lr); \
  135. } else 1
  136. #define DBG_OUT_LASTERROR \
  137. DBG_COMP.DebugErrorL(THIS_FILE, __LINE__, GetLastError());
  138. #define ASSERTMSG(x) \
  139. (void)((x) || (DBG_COMP.DebugMsg(THIS_FILE, __LINE__, _T(#x)),0))
  140. #define VERIFYMSG(e) ASSERTMSG(e)
  141. #define ASSERT(x) Win4Assert(x)
  142. #define VERIFY(x) Win4Assert(x)
  143. #else
  144. inline void __cdecl __DummyDbg(ULONG, PCWSTR, ...) { }
  145. inline void __cdecl __DummyDbg(ULONG, LPCSTR, ...) { }
  146. #define Dbg 1 ? (void)0 : ::__DummyDbg
  147. inline void __cdecl __DummyTrace(PCWSTR, ...) { }
  148. inline void __cdecl __DummyTrace(LPCSTR, ...) { }
  149. #define TRACE 1 ? (void)0 : ::__DummyTrace
  150. #define TRACE_SCOPE(x)
  151. #define DECLARE_HEAPCHECKING
  152. #define DEBUGCHECK
  153. #define DBG_INDENTER
  154. #define TRACE_CONSTRUCTOR(cls)
  155. #define TRACE_DESTRUCTOR(cls)
  156. #define TRACE_METHOD(ClassName,MethodName)
  157. #define TRACE_FUNCTION(FunctionName)
  158. #define TRACE_CONSTRUCTOR_EX(Infolevel, cls)
  159. #define TRACE_DESTRUCTOR_EX(Infolevel, cls)
  160. #define TRACE_METHOD_EX(Infolevel, ClassName, MethodName)
  161. #define TRACE_FUNCTION_EX(Infolevel, FunctionName)
  162. #define CHECK_HRESULT(hr)
  163. #define CHECK_LASTERROR(lr)
  164. #define DBG_OUT_LASTERROR
  165. #define ASSERTMSG(e)
  166. #define VERIFYMSG(e) e
  167. #define ASSERT(e)
  168. #define VERIFY(e) ((void)(e))
  169. #endif // DBG==1
  170. #ifdef UNICODE
  171. #define DBGSTRING %ls
  172. #else
  173. #define DBGSTRING %s
  174. #endif
  175. #define SAFEDBGBSTR(x) ((x==NULL)?L"<NULL>":x)
  176. #define SAFEDBGTCHAR(x) ((x==NULL)?_T("<NULL>"):x)
  177. #define ASSERT_OBJECTPTR(x) ASSERT( NULL == (x) || !::IsBadWritePtr(x,sizeof(x)) );
  178. #define ASSERT_STRINGPTR(x) ASSERT( NULL == (x) || AfxIsValidStringPtr(x) );
  179. #define FREE_OBJECTPTR(x) { ASSERT_OBJECTPTR(x); delete x; x = NULL; }
  180. #endif // __STDDBG_HXX__