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.

246 lines
8.6 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. // Hack to allow retail builds to include debug support
  51. // define RETAIL_LOG_SUPPORT in your sources to do it!
  52. #ifdef RETAIL_LOG_SUPPORT
  53. #define DEBUG_SUPPORT
  54. #else
  55. #if DBG
  56. #define DEBUG_SUPPORT
  57. #endif
  58. #endif
  59. #ifdef DEBUG_SUPPORT
  60. //
  61. // Use this in your header file. It declares the variables that we need
  62. //
  63. #define DECLARE_DEBUG2(comp) \
  64. extern PVOID comp##ControlBlock; \
  65. extern DWORD comp##InfoLevel; \
  66. void comp##DebugPrint(ULONG Mask, CHAR * Format, ... ); \
  67. //
  68. // Use this when you control when you are initialized, for example a DLL or
  69. // EXE. This defines the wrapper functions that will call into dsysdbg.lib
  70. //
  71. #define DEFINE_DEBUG2(comp) \
  72. PVOID comp##ControlBlock = NULL ; \
  73. DWORD comp##InfoLevel; \
  74. PVOID comp##__DebugKeys; \
  75. void comp##DebugPrint( \
  76. ULONG Mask, \
  77. CHAR * Format, \
  78. ... ) \
  79. { \
  80. va_list ArgList; \
  81. va_start(ArgList, Format); \
  82. _DebugOut( comp##ControlBlock, Mask, Format, ArgList); \
  83. } \
  84. void \
  85. comp##InitDebugEx(DWORD Flags, PDEBUG_KEY pKey) \
  86. { \
  87. comp##__DebugKeys = pKey; \
  88. _InitDebug(Flags, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  89. } \
  90. void \
  91. comp##InitDebug(PDEBUG_KEY pKey) \
  92. { \
  93. _InitDebug(0, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  94. } \
  95. void \
  96. comp##SetOption(DWORD Option, BOOL On, BOOL Global) \
  97. { \
  98. _DbgSetOption( comp##ControlBlock, Option, On, Global); \
  99. } \
  100. void \
  101. comp##SetLoggingOption(BOOL On) \
  102. { \
  103. _DbgSetLoggingOption(comp##ControlBlock, On); \
  104. } \
  105. void \
  106. comp##UnloadDebug(void) \
  107. { \
  108. _UnloadDebug( comp##ControlBlock ); \
  109. comp##ControlBlock = NULL ; \
  110. }
  111. //
  112. // Use this when you don't control when you are initialized, e.g. a static
  113. // library like the gluon code.
  114. //
  115. #define DEFINE_DEBUG_DEFER(comp,keys) \
  116. PVOID comp##ControlBlock = INVALID_HANDLE_VALUE; \
  117. DWORD comp##InfoLevel; \
  118. PDEBUG_KEY comp##__DebugKeys = keys; \
  119. void comp##DebugPrint( \
  120. ULONG Mask, \
  121. CHAR * Format, \
  122. ... ) \
  123. { \
  124. va_list ArgList; \
  125. va_start(ArgList, Format); \
  126. if (comp##ControlBlock == INVALID_HANDLE_VALUE) \
  127. { \
  128. _InitDebug(DSYSDBG_DEMAND_OPEN, & comp##InfoLevel, & comp##ControlBlock, #comp, comp##__DebugKeys); \
  129. } \
  130. _DebugOut( comp##ControlBlock, Mask, Format, ArgList); \
  131. } \
  132. void \
  133. comp##InitDebugEx(DWORD Flags, PDEBUG_KEY pKey) \
  134. { \
  135. comp##__DebugKeys = pKey; \
  136. _InitDebug(Flags, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  137. } \
  138. void \
  139. comp##InitDebug(PDEBUG_KEY pKey) \
  140. { \
  141. _InitDebug(DSYSDBG_DEMAND_OPEN, & comp##InfoLevel, & comp##ControlBlock, #comp, pKey); \
  142. } \
  143. void \
  144. comp##UnloadDebug(void) \
  145. { \
  146. _UnloadDebug( comp##ControlBlock ); \
  147. }
  148. #else // NOT DEBUG_SUPPORT
  149. //
  150. // Empty defines for the retail case:
  151. //
  152. #define DECLARE_DEBUG2(comp)
  153. #define DEFINE_DEBUG2(comp)
  154. #define DEFINE_DEBUG_DEFER(x, y)
  155. #endif // DEBUG_SUPPORT
  156. #if DBG
  157. //
  158. // Moved assertions to new section, so no asserts occur in retail builds
  159. // with DEBUG_SUPPORT.
  160. //
  161. // Assertions: Most should use DsysAssert or DsysAssertMsg. These forward on
  162. // the call to dsysdbg.lib, with the continue code set to drop into the
  163. // debugger. The more sophisticated can call DsysAssertEx, which allows you
  164. // to specify one of the assert codes from above:
  165. //
  166. #define DsysAssertEx(exp, ContinueCode) \
  167. if (!(exp)) \
  168. _DsysAssertEx( #exp, __FILE__, __LINE__, NULL, ContinueCode);
  169. #define DsysAssertMsgEx(exp, Message, ContinueCode) \
  170. if (!(exp)) \
  171. _DsysAssertEx( #exp, __FILE__, __LINE__, Message, ContinueCode);
  172. #define DsysAssertMsg(exp, Message) DsysAssertMsgEx(exp, Message, DSYSDBG_ASSERT_DEBUGGER)
  173. #define DsysAssert(exp) DsysAssertMsgEx(exp, NULL, DSYSDBG_ASSERT_DEBUGGER)
  174. #define DsysException(p) DbgpDumpException(p)
  175. #define SZ_DEFAULT_PROFILE_STRING "Error"
  176. #else // retail builds cannot contain asserts...
  177. #define DsysAssertEx(x,y)
  178. #define DsysAssertMsgEx(x, y, z)
  179. #define DsysAssert(x)
  180. #define DsysAssertMsg(x, y)
  181. #define DsysException(p)
  182. #define SZ_DEFAULT_PROFILE_STRING ""
  183. #endif // dbg
  184. #ifndef DEB_ERROR
  185. #define DEB_ERROR 0x00000001
  186. #endif
  187. #ifndef DEB_WARN
  188. #define DEB_WARN 0x00000002
  189. #endif
  190. #ifndef DEB_TRACE
  191. #define DEB_TRACE 0x00000004
  192. #endif
  193. #define DSYSDBG_FORCE 0x80000000
  194. #define DSYSDBG_CLEAN 0x40000000
  195. #ifdef __cplusplus
  196. }
  197. #endif // __cplusplus
  198. #endif // __DSYSDBG_H__