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.

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