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.

272 lines
8.5 KiB

  1. //+---------------------------------------------------------------------------
  2. // Copyright (C) 1991, Microsoft Corporation.
  3. //
  4. // File: debug.h
  5. //
  6. // Contents: Debugging macros. Stolen from old Cairo debnot.h with the
  7. // following history...
  8. //
  9. // History: 23-Jul-91 KyleP Created.
  10. // 15-Oct-91 KevinRo Major changes and comments added
  11. // 18-Oct-91 vich Consolidated win4p.hxx
  12. // 22-Oct-91 SatoNa Added SHLSTRICT
  13. // 29-Apr-92 BartoszM Moved from win4p.h
  14. // 3-Jun-92 BruceFo Added SMUISTRICT
  15. // 17-Dec-92 AlexT Moved UN..._PARM out of DEVL==1
  16. // 30-Sep-93 KyleP DEVL obsolete
  17. // 18-Jun-94 AlexT Make Assert a better statement
  18. // 7-Oct-94 BruceFo Stole and ripped out everything except
  19. // debug prints and asserts.
  20. // 30-Dec-95 BruceFo More cleanup, make suitable for DFS
  21. // project. Get rid of Win4 naming.
  22. //
  23. // NOTE: you must call the DebugInitialize() API before calling any other
  24. // APIs!
  25. //
  26. //----------------------------------------------------------------------------
  27. #ifndef __DEBUG_H__
  28. #define __DEBUG_H__
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #include <stdio.h> // for vsprintf
  33. #include <stdarg.h>
  34. //----------------------------------------------------------------------------
  35. // Parameter Macros
  36. //
  37. // To avoid compiler warnings for unimplemented functions, use
  38. // UNIMPLEMENTED_PARM(x) for each unreferenced parameter. This will
  39. // later be defined to nul to reveal functions that we forgot to implement.
  40. //
  41. // For functions which will never use a parameter, use
  42. // UNREFERENCED_PARM(x).
  43. //
  44. #define UNIMPLEMENTED_PARM(x) (x)
  45. #define UNREFERENCED_PARM(x) (x)
  46. #if DBG == 1
  47. //
  48. // DEBUG -- DEBUG -- DEBUG -- DEBUG -- DEBUG
  49. //
  50. #ifndef DEBUGAPI
  51. #define DEBUGAPI __stdcall
  52. #endif
  53. //
  54. // The following APIs are public and may be called
  55. //
  56. void DEBUGAPI
  57. DebugInitialize(
  58. void);
  59. unsigned long DEBUGAPI
  60. DebugSetInfoLevel(
  61. unsigned long ulNewLevel);
  62. unsigned long DEBUGAPI
  63. DebugSetInfoMask(
  64. unsigned long ulNewMask);
  65. unsigned long DEBUGAPI
  66. DebugSetAssertLevel(
  67. unsigned long ulNewLevel);
  68. //
  69. // The following APIs should never be called directly. They will be called
  70. // via macros defined herein.
  71. //
  72. void DEBUGAPI
  73. Debugvprintf(
  74. unsigned long ulCompMask,
  75. char const *pszComp,
  76. char const *ppszfmt,
  77. va_list ArgList);
  78. void DEBUGAPI
  79. DebugAssertEx(
  80. char const *pszFile,
  81. int iLine,
  82. char const *pszMsg);
  83. void DEBUGAPI
  84. DebugCheckInit(
  85. char* pInfoLevelString,
  86. unsigned long* InfoLevel);
  87. //
  88. // Public assertion macros
  89. //
  90. #define DebugAssert(x) (void)((x) || (DebugAssertEx(__FILE__, __LINE__, #x),0))
  91. #define DebugVerify(x) DebugAssert(x)
  92. //
  93. // Debug print macros
  94. //
  95. #define DEB_ERROR 0x00000001 // exported error paths
  96. #define DEB_WARN 0x00000002 // exported warnings
  97. #define DEB_TRACE 0x00000004 // exported trace messages
  98. #define DEB_DBGOUT 0x00000010 // Output to debugger
  99. #define DEB_STDOUT 0x00000020 // Output to stdout
  100. #define DEB_IERROR 0x00000100 // internal error paths
  101. #define DEB_IWARN 0x00000200 // internal warnings
  102. #define DEB_ITRACE 0x00000400 // internal trace messages
  103. #define DEB_USER1 0x00010000 // User defined
  104. #define DEB_USER2 0x00020000 // User defined
  105. #define DEB_USER3 0x00040000 // User defined
  106. #define DEB_USER4 0x00080000 // User defined
  107. #define DEB_USER5 0x00100000 // User defined
  108. #define DEB_USER6 0x00200000 // User defined
  109. #define DEB_USER7 0x00400000 // User defined
  110. #define DEB_USER8 0x00800000 // User defined
  111. #define DEB_USER9 0x01000000 // User defined
  112. #define DEB_USER10 0x02000000 // User defined
  113. #define DEB_USER11 0x04000000 // User defined
  114. #define DEB_USER12 0x08000000 // User defined
  115. #define DEB_USER13 0x10000000 // User defined
  116. #define DEB_USER14 0x20000000 // User defined
  117. #define DEB_USER15 0x40000000 // User defined
  118. #define DEB_NOCOMPNAME 0x80000000 // suppress component name
  119. #define DEB_FORCE 0x7fffffff // force message
  120. #define ASSRT_MESSAGE 0x00000001 // Output a message
  121. #define ASSRT_BREAK 0x00000002 // Int 3 on assertion
  122. #define ASSRT_POPUP 0x00000004 // And popup message
  123. //+----------------------------------------------------------------------
  124. //
  125. // DECLARE_DEBUG(comp)
  126. // DECLARE_INFOLEVEL(comp)
  127. //
  128. // This macro defines xxDebugOut where xx is the component prefix
  129. // to be defined. This declares a static variable 'xxInfoLevel', which
  130. // can be used to control the type of xxDebugOut messages printed to
  131. // the terminal. For example, xxInfoLevel may be set at the debug terminal.
  132. // This will enable the user to turn debugging messages on or off, based
  133. // on the type desired. The predefined types are defined below. Component
  134. // specific values should use the upper 24 bits
  135. //
  136. // To Use:
  137. //
  138. // 1) In your components main include file, include the line
  139. // DECLARE_DEBUG(comp)
  140. // where comp is your component prefix
  141. //
  142. // 2) In one of your components source files, include the line
  143. // DECLARE_INFOLEVEL(comp)
  144. // where comp is your component prefix. This will define the
  145. // global variable that will control output.
  146. //
  147. // It is suggested that any component define bits be combined with
  148. // existing bits. For example, if you had a specific error path that you
  149. // wanted, you might define DEB_<comp>_ERRORxxx as being
  150. //
  151. // (0x100 | DEB_ERROR)
  152. //
  153. // This way, we can turn on DEB_ERROR and get the error, or just 0x100
  154. // and get only your error.
  155. //
  156. //-----------------------------------------------------------------------
  157. #ifndef DEF_INFOLEVEL
  158. #define DEF_INFOLEVEL 0
  159. #endif
  160. #ifdef __cplusplus
  161. #define DECLARE_INFOLEVEL(comp) \
  162. extern "C" unsigned long comp##InfoLevel = DEF_INFOLEVEL; \
  163. extern "C" char* comp##InfoLevelString = #comp;
  164. #define DECLARE_DEBUG(comp) \
  165. extern "C" unsigned long comp##InfoLevel;\
  166. extern "C" char* comp##InfoLevelString;\
  167. __inline void\
  168. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...)\
  169. {\
  170. DebugCheckInit(comp##InfoLevelString, &comp##InfoLevel);\
  171. if (comp##InfoLevel & fDebugMask)\
  172. {\
  173. va_list va;\
  174. va_start(va, pszfmt);\
  175. Debugvprintf(fDebugMask, comp##InfoLevelString, pszfmt, va);\
  176. va_end(va);\
  177. }\
  178. }\
  179. class comp##CDbgTrace\
  180. {\
  181. private:\
  182. unsigned long _ulFlags;\
  183. char const * const _pszName;\
  184. public:\
  185. comp##CDbgTrace(unsigned long ulFlags, char const * const pszName)\
  186. : _ulFlags(ulFlags), _pszName(pszName)\
  187. {\
  188. comp##InlineDebugOut(_ulFlags, "Entering %s\n", _pszName);\
  189. }\
  190. ~comp##CDbgTrace()\
  191. {\
  192. comp##InlineDebugOut(_ulFlags, "Exiting %s\n", _pszName);\
  193. }\
  194. };
  195. #else // ! __cplusplus
  196. #define DECLARE_INFOLEVEL(comp) \
  197. extern unsigned long comp##InfoLevel = DEF_INFOLEVEL; \
  198. extern char* comp##InfoLevelString = #comp;
  199. #define DECLARE_DEBUG(comp) \
  200. extern unsigned long comp##InfoLevel;\
  201. extern char *comp##InfoLevelString;\
  202. __inline void\
  203. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...)\
  204. {\
  205. DebugCheckInit(comp##InfoLevelString, &comp##InfoLevel);\
  206. if (comp##InfoLevel & fDebugMask)\
  207. {\
  208. va_list va;\
  209. va_start(va, pszfmt);\
  210. Debugvprintf(fDebugMask, comp##InfoLevelString, pszfmt, va);\
  211. va_end(va);\
  212. }\
  213. }
  214. #endif // ! __cplusplus
  215. #else // DBG == 0
  216. //
  217. // NO DEBUG -- NO DEBUG -- NO DEBUG -- NO DEBUG -- NO DEBUG
  218. //
  219. #define DebugInitialize()
  220. #define DebugAssert(x) NULL
  221. #define DebugVerify(x) (x)
  222. #define DECLARE_DEBUG(comp)
  223. #define DECLARE_INFOLEVEL(comp)
  224. #endif // DBG == 0
  225. #ifdef __cplusplus
  226. }
  227. #endif // __cplusplus
  228. #endif // __DEBUG_H__