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.

251 lines
9.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: dsysdbg.h
  7. //
  8. // Contents: Merged all the debug code together
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 3-14-95 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __DSYSDBG_H__
  18. #define __DSYSDBG_H__
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include <stdarg.h>
  23. typedef struct _DEBUG_KEY {
  24. DWORD Mask;
  25. PCHAR Tag;
  26. } DEBUG_KEY, * PDEBUG_KEY;
  27. #define DSYSDBG_OPEN_ONLY 0x00000001
  28. #define DSYSDBG_DEMAND_OPEN 0x00000002
  29. #define DSYSDBG_BREAK_ON_ERROR 0x00000004
  30. #define DSYSDBG_ASSERT_CONTINUE 0
  31. #define DSYSDBG_ASSERT_BREAK 1
  32. #define DSYSDBG_ASSERT_SUSPEND 2
  33. #define DSYSDBG_ASSERT_KILL 3
  34. #define DSYSDBG_ASSERT_PROMPT 4
  35. #define DSYSDBG_ASSERT_DEBUGGER 5
  36. //
  37. // Global Flags exposed to callers:
  38. //
  39. #define DEBUG_HEAP_CHECK 0x00000040 // Check Heap on every debug out
  40. #define DEBUG_MULTI_THREAD 0x00000080 // Use critical section in header
  41. #define DEBUG_BREAK_ON_ERROR 0x00000400 // Break on an error out
  42. VOID _DsysAssertEx(PVOID FailedAssertion, PVOID FileName, ULONG LineNumber,
  43. PCHAR Message, ULONG ContinueCode);
  44. VOID _DebugOut(PVOID pControl, ULONG Mask, CHAR * Format, va_list ArgList);
  45. VOID _InitDebug(DWORD Flags, DWORD * InfoLevel, PVOID * Control, char * ModuleName, PDEBUG_KEY pKey);
  46. VOID _UnloadDebug( PVOID pControl );
  47. VOID _DbgSetOption(PVOID pControl, DWORD Flag, BOOL On, BOOL Global);
  48. VOID _DbgSetLoggingOption(PVOID pControl, BOOL On);
  49. VOID DbgpDumpException(PVOID p);
  50. VOID _DbgSetLoggingFile(PVOID pControl, HANDLE hLogFile);
  51. // Hack to allow retail builds to include debug support
  52. // define RETAIL_LOG_SUPPORT in your sources to do it!
  53. #ifdef RETAIL_LOG_SUPPORT
  54. #define DEBUG_SUPPORT
  55. #else
  56. #if DBG
  57. #define DEBUG_SUPPORT
  58. #endif
  59. #endif
  60. #ifdef DEBUG_SUPPORT
  61. //
  62. // Use this in your header file. It declares the variables that we need
  63. //
  64. #define DECLARE_DEBUG2(comp) \
  65. extern PVOID comp##ControlBlock; \
  66. extern DWORD comp##InfoLevel; \
  67. void comp##DebugPrint(ULONG Mask, CHAR * Format, ... ); \
  68. //
  69. // Use this when you control when you are initialized, for example a DLL or
  70. // EXE. This defines the wrapper functions that will call into dsysdbg.lib
  71. //
  72. #define DEFINE_DEBUG2(comp) \
  73. PVOID comp##ControlBlock = NULL ; \
  74. DWORD comp##InfoLevel; \
  75. PVOID comp##__DebugKeys; \
  76. void comp##DebugPrint( \
  77. ULONG Mask, \
  78. CHAR * Format, \
  79. ... ) \
  80. { \
  81. va_list ArgList; \
  82. va_start(ArgList, Format); \
  83. _DebugOut( comp##ControlBlock, Mask, Format, ArgList); \
  84. } \
  85. void \
  86. comp##InitDebugEx(DWORD Flags, PDEBUG_KEY pKey) \
  87. { \
  88. comp##__DebugKeys = pKey; \
  89. _InitDebug(Flags, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  90. } \
  91. void \
  92. comp##InitDebug(PDEBUG_KEY pKey) \
  93. { \
  94. _InitDebug(0, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  95. } \
  96. void \
  97. comp##SetOption(DWORD Option, BOOL On, BOOL Global) \
  98. { \
  99. _DbgSetOption( comp##ControlBlock, Option, On, Global); \
  100. } \
  101. void \
  102. comp##SetLoggingOption(BOOL On) \
  103. { \
  104. _DbgSetLoggingOption(comp##ControlBlock, On); \
  105. } \
  106. void \
  107. comp##UnloadDebug(void) \
  108. { \
  109. _UnloadDebug( comp##ControlBlock ); \
  110. comp##ControlBlock = NULL ; \
  111. } \
  112. void \
  113. comp##SetLoggingFile(HANDLE hLogFile) \
  114. { \
  115. _DbgSetLoggingFile(comp##ControlBlock, hLogFile); \
  116. } \
  117. //
  118. // Use this when you don't control when you are initialized, e.g. a static
  119. // library like the gluon code.
  120. //
  121. #define DEFINE_DEBUG_DEFER(comp,keys) \
  122. PVOID comp##ControlBlock = INVALID_HANDLE_VALUE; \
  123. DWORD comp##InfoLevel; \
  124. PDEBUG_KEY comp##__DebugKeys = keys; \
  125. void comp##DebugPrint( \
  126. ULONG Mask, \
  127. CHAR * Format, \
  128. ... ) \
  129. { \
  130. va_list ArgList; \
  131. va_start(ArgList, Format); \
  132. if (comp##ControlBlock == INVALID_HANDLE_VALUE) \
  133. { \
  134. _InitDebug(DSYSDBG_DEMAND_OPEN, & comp##InfoLevel, & comp##ControlBlock, #comp, comp##__DebugKeys); \
  135. } \
  136. _DebugOut( comp##ControlBlock, Mask, Format, ArgList); \
  137. } \
  138. void \
  139. comp##InitDebugEx(DWORD Flags, PDEBUG_KEY pKey) \
  140. { \
  141. comp##__DebugKeys = pKey; \
  142. _InitDebug(Flags, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  143. } \
  144. void \
  145. comp##InitDebug(PDEBUG_KEY pKey) \
  146. { \
  147. _InitDebug(DSYSDBG_DEMAND_OPEN, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  148. } \
  149. void \
  150. comp##UnloadDebug(void) \
  151. { \
  152. _UnloadDebug( comp##ControlBlock ); \
  153. }
  154. #else // NOT DEBUG_SUPPORT
  155. //
  156. // Empty defines for the retail case:
  157. //
  158. #define DECLARE_DEBUG2(comp)
  159. #define DEFINE_DEBUG2(comp)
  160. #define DEFINE_DEBUG_DEFER(x, y)
  161. #endif // DEBUG_SUPPORT
  162. #if DBG
  163. //
  164. // Moved assertions to new section, so no asserts occur in retail builds
  165. // with DEBUG_SUPPORT.
  166. //
  167. // Assertions: Most should use DsysAssert or DsysAssertMsg. These forward on
  168. // the call to dsysdbg.lib, with the continue code set to drop into the
  169. // debugger. The more sophisticated can call DsysAssertEx, which allows you
  170. // to specify one of the assert codes from above:
  171. //
  172. #define DsysAssertEx(exp, ContinueCode) \
  173. if (!(exp)) \
  174. _DsysAssertEx( #exp, __FILE__, __LINE__, NULL, ContinueCode);
  175. #define DsysAssertMsgEx(exp, Message, ContinueCode) \
  176. if (!(exp)) \
  177. _DsysAssertEx( #exp, __FILE__, __LINE__, Message, ContinueCode);
  178. #define DsysAssertMsg(exp, Message) DsysAssertMsgEx(exp, Message, DSYSDBG_ASSERT_DEBUGGER)
  179. #define DsysAssert(exp) DsysAssertMsgEx(exp, NULL, DSYSDBG_ASSERT_DEBUGGER)
  180. #define DsysException(p) DbgpDumpException(p)
  181. #define SZ_DEFAULT_PROFILE_STRING "Error"
  182. #else // retail builds cannot contain asserts...
  183. #define DsysAssertEx(x,y)
  184. #define DsysAssertMsgEx(x, y, z)
  185. #define DsysAssert(x)
  186. #define DsysAssertMsg(x, y)
  187. #define DsysException(p)
  188. #define SZ_DEFAULT_PROFILE_STRING ""
  189. #endif // dbg
  190. #ifndef DEB_ERROR
  191. #define DEB_ERROR 0x00000001
  192. #endif
  193. #ifndef DEB_WARN
  194. #define DEB_WARN 0x00000002
  195. #endif
  196. #ifndef DEB_TRACE
  197. #define DEB_TRACE 0x00000004
  198. #endif
  199. #define DSYSDBG_FORCE 0x80000000
  200. #define DSYSDBG_CLEAN 0x40000000
  201. #ifdef __cplusplus
  202. }
  203. #endif // __cplusplus
  204. #endif // __DSYSDBG_H__