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.

288 lines
8.4 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. #ifdef __cplusplus
  100. }
  101. #endif // __cplusplus
  102. # define Win4Assert(x) \
  103. (void)((x) || (Win4AssertEx(__FILE__, __LINE__, #x),0))
  104. # define Win4Verify(x) Win4Assert(x)
  105. //
  106. // Debug print macros
  107. //
  108. # define DEB_ERROR 0x00000001 // exported error paths
  109. # define DEB_WARN 0x00000002 // exported warnings
  110. # define DEB_TRACE 0x00000004 // exported trace messages
  111. # define DEB_DBGOUT 0x00000010 // Output to debugger
  112. # define DEB_STDOUT 0x00000020 // Output to stdout
  113. # define DEB_IERROR 0x00000100 // internal error paths
  114. # define DEB_IWARN 0x00000200 // internal warnings
  115. # define DEB_ITRACE 0x00000400 // internal trace messages
  116. # define DEB_USER1 0x00010000 // User defined
  117. # define DEB_USER2 0x00020000 // User defined
  118. # define DEB_USER3 0x00040000 // User defined
  119. # define DEB_USER4 0x00080000 // User defined
  120. # define DEB_USER5 0x00100000 // User defined
  121. # define DEB_USER6 0x00200000 // User defined
  122. # define DEB_USER7 0x00400000 // User defined
  123. # define DEB_USER8 0x00800000 // User defined
  124. # define DEB_USER9 0x01000000 // User defined
  125. # define DEB_USER10 0x02000000 // User defined
  126. # define DEB_USER11 0x04000000 // User defined
  127. # define DEB_USER12 0x08000000 // User defined
  128. # define DEB_USER13 0x10000000 // User defined
  129. # define DEB_USER14 0x20000000 // User defined
  130. # define DEB_USER15 0x40000000 // User defined
  131. # define DEB_NOCOMPNAME 0x80000000 // suppress component name
  132. # define DEB_FORCE 0x7fffffff // force message
  133. # define ASSRT_MESSAGE 0x00000001 // Output a message
  134. # define ASSRT_BREAK 0x00000002 // Int 3 on assertion
  135. # define ASSRT_POPUP 0x00000004 // And popup message
  136. //+----------------------------------------------------------------------
  137. //
  138. // DECLARE_DEBUG(comp)
  139. // DECLARE_INFOLEVEL(comp)
  140. //
  141. // This macro defines xxDebugOut where xx is the component prefix
  142. // to be defined. This declares a static variable 'xxInfoLevel', which
  143. // can be used to control the type of xxDebugOut messages printed to
  144. // the terminal. For example, xxInfoLevel may be set at the debug terminal.
  145. // This will enable the user to turn debugging messages on or off, based
  146. // on the type desired. The predefined types are defined below. Component
  147. // specific values should use the upper 24 bits
  148. //
  149. // To Use:
  150. //
  151. // 1) In your components main include file, include the line
  152. // DECLARE_DEBUG(comp)
  153. // where comp is your component prefix
  154. //
  155. // 2) In one of your components source files, include the line
  156. // DECLARE_INFOLEVEL(comp)
  157. // where comp is your component prefix. This will define the
  158. // global variable that will control output.
  159. //
  160. // It is suggested that any component define bits be combined with
  161. // existing bits. For example, if you had a specific error path that you
  162. // wanted, you might define DEB_<comp>_ERRORxxx as being
  163. //
  164. // (0x100 | DEB_ERROR)
  165. //
  166. // This way, we can turn on DEB_ERROR and get the error, or just 0x100
  167. // and get only your error.
  168. //
  169. //-----------------------------------------------------------------------
  170. # ifndef DEF_INFOLEVEL
  171. # define DEF_INFOLEVEL (DEB_ERROR | DEB_WARN)
  172. # endif
  173. # define DECLARE_INFOLEVEL(comp) \
  174. extern EXTRNC unsigned long comp##InfoLevel = DEF_INFOLEVEL;\
  175. extern EXTRNC char* comp##InfoLevelString = #comp;
  176. # ifdef __cplusplus
  177. # define DECLARE_DEBUG(comp) \
  178. extern EXTRNC unsigned long comp##InfoLevel; \
  179. extern EXTRNC char *comp##InfoLevelString; \
  180. _inline void \
  181. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  182. { \
  183. if (comp##InfoLevel & fDebugMask) \
  184. { \
  185. va_list va; \
  186. va_start (va, pszfmt); \
  187. vdprintf(fDebugMask, comp##InfoLevelString, pszfmt, va);\
  188. va_end(va); \
  189. } \
  190. } \
  191. \
  192. class comp##CDbgTrace\
  193. {\
  194. private:\
  195. unsigned long _ulFlags;\
  196. char const * const _pszName;\
  197. public:\
  198. comp##CDbgTrace(unsigned long ulFlags, char const * const pszName);\
  199. ~comp##CDbgTrace();\
  200. };\
  201. \
  202. inline comp##CDbgTrace::comp##CDbgTrace(\
  203. unsigned long ulFlags,\
  204. char const * const pszName)\
  205. : _ulFlags(ulFlags), _pszName(pszName)\
  206. {\
  207. comp##InlineDebugOut(_ulFlags, "Entering %s\n", _pszName);\
  208. }\
  209. \
  210. inline comp##CDbgTrace::~comp##CDbgTrace()\
  211. {\
  212. comp##InlineDebugOut(_ulFlags, "Exiting %s\n", _pszName);\
  213. }
  214. # else // ! __cplusplus
  215. # define DECLARE_DEBUG(comp) \
  216. extern EXTRNC unsigned long comp##InfoLevel; \
  217. extern EXTRNC char *comp##InfoLevelString; \
  218. _inline void \
  219. comp##InlineDebugOut(unsigned long fDebugMask, char const *pszfmt, ...) \
  220. { \
  221. if (comp##InfoLevel & fDebugMask) \
  222. { \
  223. va_list va; \
  224. va_start (va, pszfmt); \
  225. vdprintf(fDebugMask, comp##InfoLevelString, pszfmt, va);\
  226. va_end(va); \
  227. } \
  228. }
  229. # endif // ! __cplusplus
  230. #else // DBG == 0
  231. //
  232. // NO DEBUG -- NO DEBUG -- NO DEBUG -- NO DEBUG -- NO DEBUG
  233. //
  234. # define Win4Assert(x) NULL
  235. # define Win4Verify(x) (x)
  236. # define DECLARE_DEBUG(comp)
  237. # define DECLARE_INFOLEVEL(comp)
  238. #endif // DBG == 0
  239. #endif // __DEBUG_H__