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.

284 lines
8.0 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: debug.h
  6. * Content: debugging macros and prototypes
  7. *@@BEGIN_MSINTERNAL
  8. *
  9. * History:
  10. *
  11. * 10/27/96 vlads Loosely based on somebody's else debugging support
  12. *
  13. *@@END_MSINTERNAL
  14. *
  15. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  16. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  18. * PURPOSE.
  19. *
  20. ***************************************************************************/
  21. #ifndef _INC_DEBUG
  22. #define _INC_DEBUG
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. #ifdef MAXDEBUG
  28. #define RD(x) x
  29. #ifdef DEBUG
  30. #define D(x) x
  31. #else
  32. #define D(x)
  33. #endif
  34. #else
  35. #define RD(x)
  36. #define D(x)
  37. #endif
  38. /*****************************************************************************
  39. *
  40. * assert.c - Assertion stuff
  41. *
  42. *****************************************************************************/
  43. typedef enum {
  44. DbgFlAlways = 0x00000000, /* Unconditional */
  45. DbgFlDll = 0x00000001, /* Dll bookkeeping */
  46. DbgFlFactory = 0x00000002, /* IClassFactory */
  47. DbgFlSti = 0x00000004, /* ISti */
  48. DbgFlStiObj = 0x00000008, /* ISti objects */
  49. DbgFlDevice = 0x00000010, /* Device code */
  50. DbgFlUtil = 0x10000000, /* Misc utility fns */
  51. DbgFlCommon = 0x40000000, /* common.c */
  52. DbgFlError = 0x80000000, /* Errors */
  53. } DBGFL; /* debug output flags */
  54. VOID EXTERNAL InitializeDebuggingSupport(VOID);
  55. VOID EXTERNAL SetDebugLogFileA(CHAR *pszLogFileName);
  56. DBGFL EXTERNAL SetCurrentDebugFlags(DBGFL NewFlags) ;
  57. void EXTERNAL WarnPszV(LPCSTR ptsz, ...);
  58. void EXTERNAL DebugOutPtszV(DBGFL DebFl, LPCTSTR ptsz, ...);
  59. int EXTERNAL AssertPtszPtszLn(LPCTSTR ptszExpr, LPCTSTR ptszFile, int iLine);
  60. #ifndef DEBUG
  61. #define DebugOutPtszV 1?(void)0 : (void)
  62. #endif
  63. #ifdef MAXDEBUG
  64. #define RPF WarnPszV
  65. #else
  66. #define WarnPszV 1?(void)0 : (void)
  67. #define RPF 1?(void)0 : (void)
  68. #define iarg 0
  69. #endif
  70. /*****************************************************************************
  71. *
  72. * Buffer scrambling
  73. *
  74. * All output buffers should be scrambled on entry to any function.
  75. *
  76. * Each output bitmask should set an unused bit randomly to ensure
  77. * that callers ignore bits that aren't defined.
  78. *
  79. *****************************************************************************/
  80. #ifdef MAXDEBUG
  81. void EXTERNAL ScrambleBuf(LPVOID pv, UINT cb);
  82. void EXTERNAL ScrambleBit(LPDWORD pdw, DWORD flMask);
  83. #else
  84. #define ScrambleBuf(pv, cb)
  85. #define ScrambleBit(pdw, flRandom)
  86. #endif
  87. /*****************************************************************************
  88. *
  89. * Procedure enter/exit tracking.
  90. *
  91. * Start a procedure with
  92. *
  93. * EnterProc(ProcedureName, (_ "format", arg, arg, arg, ...));
  94. * EnterProcS(ProcedureName, (_ "format", arg, arg, arg, ...));
  95. * EnterProcI(ProcedureName, (_ "format", arg, arg, arg, ...));
  96. * EnterProcR(ProcedureName, (_ "format", arg, arg, arg, ...));
  97. *
  98. * The format string is documented in EmitPal.
  99. *
  100. * Suffixing an "S" indicates that the macro should not generate
  101. * a procedure name because there is a formal parameter with the
  102. * name s_szProc. This is a hack.
  103. *
  104. * Suffixing an "R" indicates that the macro should generate a
  105. * procedure name in RDEBUG.
  106. *
  107. * Suffixing an "I" indicates that the macro should emit a dummy
  108. * procedure name in RDEBUG because the interface is internal.
  109. *
  110. * End a procedure with one of the following:
  111. *
  112. * ExitProc();
  113. *
  114. * Procedure returns no value.
  115. *
  116. * ExitProcX();
  117. *
  118. * Procedure returns an arbitrary DWORD.
  119. *
  120. * ExitOleProc();
  121. *
  122. * Procedure returns an HRESULT (named "hres").
  123. *
  124. * ExitOleProcPpv(ppvOut);
  125. *
  126. * Procedure returns an HRESULT (named "hres") and, on success,
  127. * puts a new object in ppvOut.
  128. *
  129. *****************************************************************************/
  130. #define cpvArgMax 10 /* Max of 10 args per procedure */
  131. typedef struct ARGLIST {
  132. LPCSTR pszProc;
  133. LPCSTR pszFormat;
  134. PV rgpv[cpvArgMax];
  135. } ARGLIST, *PARGLIST;
  136. void EXTERNAL ArgsPalPszV(PARGLIST pal, LPCSTR psz, ...);
  137. void EXTERNAL EnterDbgflPszPal(DBGFL Dbgfl, LPCSTR psz, PARGLIST pal);
  138. void EXTERNAL ExitDbgflPalHresPpv(DBGFL, PARGLIST, HRESULT, PPV);
  139. #ifdef DEBUG_VALIDATE
  140. extern DBGFL DbgFlCur;
  141. #define AssertFPtsz(c, ptsz) \
  142. ((c) ? 0 : AssertPtszPtszLn(ptsz, TEXT(__FILE__), __LINE__))
  143. #define ValidateF(c, arg) \
  144. ((c) ? 0 : (RPF arg, ValidationException(), 0))
  145. #define ConfirmF(c) \
  146. ((c) ? 0 : AssertPtszPtszLn(TEXT(#c), TEXT(__FILE__), __LINE__))
  147. #else /* !DEBUG */
  148. #define AssertFPtsz(c, ptsz)
  149. #define ValidateF(c, arg)
  150. #define ConfirmF(c) (c)
  151. #endif
  152. /*
  153. * CAssertF - compile-time assertion.
  154. */
  155. #define CAssertF(c) switch(0) case c: case 0:
  156. #define _SetupEnterProc(nm) \
  157. static CHAR s_szProc[] = #nm; \
  158. ARGLIST _al[1] \
  159. #define _ _al,
  160. #define ppvDword ((PPV)1)
  161. #define ppvVoid ((PPV)2)
  162. #define ppvBool ((PPV)3)
  163. #define _DoEnterProc(v) \
  164. ArgsPalPszV v; \
  165. EnterDbgflPszPal(DbgFl, s_szProc, _al) \
  166. #define _EnterProc(nm, v) \
  167. _SetupEnterProc(nm); \
  168. _DoEnterProc(v) \
  169. #define _ExitOleProcPpv(ppv) \
  170. ExitDbgflPalHresPpv(DbgFl, _al, hres, (PPV)(ppv)) \
  171. #define _ExitOleProc() \
  172. _ExitOleProcPpv(0) \
  173. #define _ExitProc() \
  174. ExitDbgflPalHresPpv(DbgFl, _al, 0, ppvVoid) \
  175. #define _ExitProcX(x) \
  176. ExitDbgflPalHresPpv(DbgFl, _al, (HRESULT)(x), ppvDword) \
  177. #define _ExitProcF(x) \
  178. ExitDbgflPalHresPpv(DbgFl, _al, (HRESULT)(x), ppvBool) \
  179. #if defined(DEBUG)
  180. #define EnterProc _EnterProc
  181. #define ExitOleProcPpv _ExitOleProcPpv
  182. #define ExitOleProc _ExitOleProc
  183. #define ExitProc _ExitProc
  184. #define ExitProcX _ExitProcX
  185. #define ExitProcF _ExitProcF
  186. #define EnterProcS(nm, v) \
  187. static CHAR s_szProc2[] = #nm; \
  188. ARGLIST _al[1]; \
  189. ArgsPalPszV v; \
  190. EnterDbgflPszPal(DbgFl, s_szProc2, _al) \
  191. #define EnterProcI _EnterProc
  192. #define EnterProcR _EnterProc
  193. #define ExitOleProcPpvR _ExitOleProcPpv
  194. #define ExitOleProcR _ExitOleProc
  195. #define ExitProcR _ExitProc
  196. #define ExitProcXR _ExitProcX
  197. #define ExitProcFR _ExitProcF
  198. #elif defined(RDEBUG)
  199. #define EnterProc(nm, v)
  200. #define ExitOleProcPpv(ppv)
  201. #define ExitOleProc()
  202. #define ExitProc()
  203. #define ExitProcX(x)
  204. #define ExitProcF(x)
  205. #define EnterProcS(nm, v)
  206. #define EnterProcI(nm, v) static CHAR s_szProc[] = ""
  207. #define EnterProcR(nm, v) static CHAR s_szProc[] = #nm
  208. #define ExitOleProcPpvR(ppv)
  209. #define ExitOleProcR()
  210. #define ExitProcR()
  211. #define ExitProcXR()
  212. #define ExitProcFR()
  213. #else
  214. #define EnterProc(nm, v)
  215. #define ExitOleProcPpv(ppv)
  216. #define ExitOleProc()
  217. #define ExitProc()
  218. #define ExitProcX(x)
  219. #define ExitProcF(x)
  220. #define EnterProcS(nm, v)
  221. #define EnterProcI(nm, v)
  222. #define EnterProcR(nm, v)
  223. #define ExitOleProcPpvR(ppv)
  224. #define ExitOleProcR()
  225. #define ExitProcR()
  226. #define ExitProcXR(x)
  227. #define ExitProcFR(x)
  228. #endif
  229. #define AssertF(c) AssertFPtsz(c, TEXT(#c))
  230. #ifdef __cplusplus
  231. }
  232. #endif
  233. #endif // _INC_DEBUG