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.

303 lines
9.5 KiB

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