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.

292 lines
8.7 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. //
  21. //
  22. // NOTE: you must call the InitializeDebugging() API before calling any other
  23. // APIs!
  24. //
  25. //----------------------------------------------------------------------------
  26. #ifndef __DEBUG_H__
  27. #define __DEBUG_H__
  28. #include <stdarg.h>
  29. //----------------------------------------------------------------------------
  30. // Parameter Macros
  31. //
  32. // To avoid compiler warnings for unimplemented functions, use
  33. // UNIMPLEMENTED_PARM(x) for each unreferenced parameter. This will
  34. // later be defined to nul to reveal functions that we forgot to implement.
  35. //
  36. // For functions which will never use a parameter, use
  37. // UNREFERENCED_PARM(x).
  38. //
  39. #define UNIMPLEMENTED_PARM(x) (x)
  40. #define UNREFERENCED_PARM(x) (x)
  41. #if DBG == 1
  42. //
  43. // DEBUG -- DEBUG -- DEBUG -- DEBUG -- DEBUG
  44. //
  45. //
  46. // Debug print functions.
  47. //
  48. #ifdef __cplusplus
  49. extern "C" {
  50. # define EXTRNC "C"
  51. #else
  52. # define EXTRNC
  53. #endif
  54. #ifndef EXPORTDEF
  55. #define EXPORTDEF
  56. #endif
  57. #ifndef EXPORTIMP
  58. #define EXPORTIMP
  59. #endif
  60. #ifndef EXPORTED
  61. #define EXPORTED _cdecl
  62. #endif
  63. #ifndef APINOT
  64. #ifdef _X86_
  65. #define APINOT _stdcall
  66. #else
  67. #define APINOT _cdecl
  68. #endif
  69. #endif
  70. // vdprintf should only be called from xxDebugOut()
  71. EXPORTDEF void APINOT
  72. vdprintf(
  73. unsigned long ulCompMask,
  74. char const *pszComp,
  75. char const *ppszfmt,
  76. va_list ArgList);
  77. EXPORTDEF void APINOT
  78. Win4AssertEx(
  79. char const *pszFile,
  80. int iLine,
  81. char const *pszMsg);
  82. EXPORTDEF int APINOT
  83. PopUpError(
  84. char const *pszMsg,
  85. int iLine,
  86. char const *pszFile);
  87. EXPORTDEF unsigned long APINOT
  88. SetWin4InfoLevel(
  89. unsigned long ulNewLevel);
  90. EXPORTDEF unsigned long APINOT
  91. SetWin4InfoMask(
  92. unsigned long ulNewMask);
  93. EXPORTDEF unsigned long APINOT
  94. SetWin4AssertLevel(
  95. unsigned long ulNewLevel);
  96. EXPORTDEF void APINOT
  97. InitializeDebugging(
  98. void);
  99. EXPORTDEF void APINOT
  100. UninitializeDebugging(
  101. void);
  102. #ifdef __cplusplus
  103. }
  104. #endif // __cplusplus
  105. # define Win4Assert(x) \
  106. (void)((x) || (Win4AssertEx(__FILE__, __LINE__, #x),0))
  107. # define Win4Verify(x) Win4Assert(x)
  108. //
  109. // Debug print macros
  110. //
  111. # define DEB_ERROR 0x00000001 // exported error paths
  112. # define DEB_WARN 0x00000002 // exported warnings
  113. # define DEB_TRACE 0x00000004 // exported trace messages
  114. # define DEB_DBGOUT 0x00000010 // Output to debugger
  115. # define DEB_STDOUT 0x00000020 // Output to stdout
  116. # define DEB_IERROR 0x00000100 // internal error paths
  117. # define DEB_IWARN 0x00000200 // internal warnings
  118. # define DEB_ITRACE 0x00000400 // internal trace messages
  119. # define DEB_USER1 0x00010000 // User defined
  120. # define DEB_USER2 0x00020000 // User defined
  121. # define DEB_USER3 0x00040000 // User defined
  122. # define DEB_USER4 0x00080000 // User defined
  123. # define DEB_USER5 0x00100000 // User defined
  124. # define DEB_USER6 0x00200000 // User defined
  125. # define DEB_USER7 0x00400000 // User defined
  126. # define DEB_USER8 0x00800000 // User defined
  127. # define DEB_USER9 0x01000000 // User defined
  128. # define DEB_USER10 0x02000000 // User defined
  129. # define DEB_USER11 0x04000000 // User defined
  130. # define DEB_USER12 0x08000000 // User defined
  131. # define DEB_USER13 0x10000000 // User defined
  132. # define DEB_USER14 0x20000000 // User defined
  133. # define DEB_USER15 0x40000000 // User defined
  134. # define DEB_NOCOMPNAME 0x80000000 // suppress component name
  135. # define DEB_FORCE 0x7fffffff // force message
  136. # define ASSRT_MESSAGE 0x00000001 // Output a message
  137. # define ASSRT_BREAK 0x00000002 // Int 3 on assertion
  138. # define ASSRT_POPUP 0x00000004 // And popup message
  139. //+----------------------------------------------------------------------
  140. //
  141. // DECLARE_DEBUG(comp)
  142. // DECLARE_INFOLEVEL(comp)
  143. //
  144. // This macro defines xxDebugOut where xx is the component prefix
  145. // to be defined. This declares a static variable 'xxInfoLevel', which
  146. // can be used to control the type of xxDebugOut messages printed to
  147. // the terminal. For example, xxInfoLevel may be set at the debug terminal.
  148. // This will enable the user to turn debugging messages on or off, based
  149. // on the type desired. The predefined types are defined below. Component
  150. // specific values should use the upper 24 bits
  151. //
  152. // To Use:
  153. //
  154. // 1) In your components main include file, include the line
  155. // DECLARE_DEBUG(comp)
  156. // where comp is your component prefix
  157. //
  158. // 2) In one of your components source files, include the line
  159. // DECLARE_INFOLEVEL(comp)
  160. // where comp is your component prefix. This will define the
  161. // global variable that will control output.
  162. //
  163. // It is suggested that any component define bits be combined with
  164. // existing bits. For example, if you had a specific error path that you
  165. // wanted, you might define DEB_<comp>_ERRORxxx as being
  166. //
  167. // (0x100 | DEB_ERROR)
  168. //
  169. // This way, we can turn on DEB_ERROR and get the error, or just 0x100
  170. // and get only your error.
  171. //
  172. //-----------------------------------------------------------------------
  173. # ifndef DEF_INFOLEVEL
  174. # define DEF_INFOLEVEL (DEB_ERROR | DEB_WARN)
  175. # endif
  176. # define DECLARE_INFOLEVEL(comp) \
  177. extern EXTRNC unsigned long comp##InfoLevel = DEF_INFOLEVEL;\
  178. extern EXTRNC char* comp##InfoLevelString = #comp;
  179. # ifdef __cplusplus
  180. # define DECLARE_DEBUG(comp) \
  181. extern EXTRNC unsigned long comp##InfoLevel; \
  182. extern EXTRNC char *comp##InfoLevelString; \
  183. _inline void \
  184. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  185. { \
  186. if (comp##InfoLevel & fDebugMask) \
  187. { \
  188. va_list va; \
  189. va_start (va, pszfmt); \
  190. vdprintf(fDebugMask, comp##InfoLevelString, pszfmt, va);\
  191. va_end(va); \
  192. } \
  193. } \
  194. \
  195. class comp##CDbgTrace\
  196. {\
  197. private:\
  198. unsigned long _ulFlags;\
  199. char const * const _pszName;\
  200. public:\
  201. comp##CDbgTrace(unsigned long ulFlags, char const * const pszName);\
  202. ~comp##CDbgTrace();\
  203. };\
  204. \
  205. inline comp##CDbgTrace::comp##CDbgTrace(\
  206. unsigned long ulFlags,\
  207. char const * const pszName)\
  208. : _ulFlags(ulFlags), _pszName(pszName)\
  209. {\
  210. comp##InlineDebugOut(_ulFlags, "Entering %s\n", _pszName);\
  211. }\
  212. \
  213. inline comp##CDbgTrace::~comp##CDbgTrace()\
  214. {\
  215. comp##InlineDebugOut(_ulFlags, "Exiting %s\n", _pszName);\
  216. }
  217. # else // ! __cplusplus
  218. # define DECLARE_DEBUG(comp) \
  219. extern EXTRNC unsigned long comp##InfoLevel; \
  220. extern EXTRNC char *comp##InfoLevelString; \
  221. _inline void \
  222. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  223. { \
  224. if (comp##InfoLevel & fDebugMask) \
  225. { \
  226. va_list va; \
  227. va_start (va, pszfmt); \
  228. vdprintf(fDebugMask, comp##InfoLevelString, pszfmt, va);\
  229. va_end(va); \
  230. } \
  231. }
  232. # endif // ! __cplusplus
  233. #else // DBG == 0
  234. //
  235. // NO DEBUG -- NO DEBUG -- NO DEBUG -- NO DEBUG -- NO DEBUG
  236. //
  237. # define Win4Assert(x) NULL
  238. # define Win4Verify(x) (x)
  239. # define DECLARE_DEBUG(comp)
  240. # define DECLARE_INFOLEVEL(comp)
  241. #endif // DBG == 0
  242. #endif // __DEBUG_H__