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.

357 lines
11 KiB

  1. /***************************************************************************
  2. * Debug.h
  3. *
  4. * Copyright (C) 1996-1999 Microsoft Corporation. All Rights Reserved.
  5. *
  6. * Content: DirectInput debugging macros
  7. *
  8. *@@BEGIN_MSINTERNAL
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 1996.05.07 raymondc Somebody had to
  13. *
  14. *@@END_MSINTERNAL
  15. *
  16. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  17. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  19. * PURPOSE.
  20. *
  21. ***************************************************************************/
  22. #ifndef _INC_DEBUG
  23. #define _INC_DEBUG
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #ifdef XDEBUG
  29. #define RD(x) x
  30. #ifdef DEBUG
  31. #define D(x) x
  32. #else
  33. #define D(x)
  34. #endif
  35. #else
  36. #define RD(x)
  37. #define D(x)
  38. #endif
  39. /*****************************************************************************
  40. *
  41. * assert.c - Assertion stuff
  42. *
  43. * A sqfl is in multiple parts.
  44. *
  45. * The low word specifies the area that is generating the message.
  46. *
  47. * The high word contains flags that describe why this squirty
  48. * is being generated.
  49. *
  50. *****************************************************************************/
  51. typedef enum _SQFL{
  52. /*
  53. * Areas.
  54. */
  55. sqflAlways = 0x0000, /* Unconditional */
  56. sqflDll = 0x0001, /* Dll bookkeeping */
  57. sqflFactory = 0x0002, /* IClassFactory */
  58. sqflDi = 0x0003, /* IDirectInput */
  59. sqflHid = 0x0004,
  60. sqflReg = 0x0005, /* Registry Setup */
  61. sqflInit = 0x0006, /* Initialization */
  62. sqflEff = 0x0007, /* Effect Block Download */
  63. sqflParam = 0x0008, /* Parameter Block(s) Download */
  64. sqflOp = 0x0009, /* PID device Operation */
  65. sqflRead = 0x000A,
  66. sqflEffDrv = 0x000B,
  67. sqflParams = 0x000C, /* Incoming parameters */
  68. sqflCrit = 0x000D, /* Critical Section */
  69. sqflMaxArea, /* Last area */
  70. /*
  71. * Flags which may be combined. For now, they all fit into a byte.
  72. */
  73. sqflTrace = 0x00010000, /* Trace squirties */
  74. sqflIn = 0x00020000, /* Function entry */
  75. sqflOut = 0x00040000, /* Function exit */
  76. sqflBenign = 0x00080000, /* Not a bad error */
  77. sqflError = 0x00100000, /* A bad error */
  78. sqflVerbose = 0x00200000, /* Really verbose */
  79. } SQFL; /* squiffle */
  80. #ifdef XDEBUG
  81. void EXTERNAL WarnPtszV(LPCTSTR ptsz, ...);
  82. void EXTERNAL SquirtSqflPtszV(SQFL sqfl, LPCTSTR ptsz, ...);
  83. #endif
  84. #ifndef DEBUG
  85. #define SquirtSqflPtszV sizeof
  86. #endif
  87. #ifdef XDEBUG
  88. #define RPF WarnPtszV
  89. #else
  90. #define WarnPtszV sizeof
  91. #define RPF sizeof
  92. #define s_tszProc 0
  93. #define iarg 0
  94. #endif
  95. /*****************************************************************************
  96. *
  97. * Buffer scrambling
  98. *
  99. * All output buffers should be scrambled on entry to any function.
  100. *
  101. * Each output bitmask should set an unused bit randomly to ensure
  102. * that callers ignore bits that aren't defined.
  103. *
  104. *****************************************************************************/
  105. #ifdef XDEBUG
  106. void EXTERNAL ScrambleBuf(LPVOID pv, UINT cb);
  107. void EXTERNAL ScrambleBit(LPDWORD pdw, DWORD flMask);
  108. #else
  109. #define ScrambleBuf(pv, cb)
  110. #define ScrambleBit(pdw, flRandom)
  111. #endif
  112. /*****************************************************************************
  113. *
  114. * Procedure enter/exit tracking.
  115. *
  116. * Start a procedure with
  117. *
  118. * EnterProc(ProcedureName, (_ "format", arg, arg, arg, ...));
  119. * EnterProcS(ProcedureName, (_ "format", arg, arg, arg, ...));
  120. * EnterProcI(ProcedureName, (_ "format", arg, arg, arg, ...));
  121. * EnterProcR(ProcedureName, (_ "format", arg, arg, arg, ...));
  122. *
  123. * The format string is documented in EmitPal.
  124. *
  125. * Suffixing an "S" indicates that the macro should not generate
  126. * a procedure name because there is a formal parameter with the
  127. * name s_tszProc. This is a hack.
  128. *
  129. * Suffixing an "R" indicates that the macro should generate a
  130. * procedure name in RDEBUG.
  131. *
  132. * Suffixing an "I" indicates that the macro should emit a dummy
  133. * procedure name in RDEBUG because the interface is internal.
  134. *
  135. * No suffix means that the macro should be active only in the
  136. * DEBUG build and should vanish in RDEBUG (and RETAIL).
  137. *
  138. * End a procedure with one of the following:
  139. *
  140. * ExitProc();
  141. *
  142. * Procedure returns no value.
  143. *
  144. * ExitProcX();
  145. *
  146. * Procedure returns an arbitrary DWORD.
  147. *
  148. * ExitProcF();
  149. *
  150. * Procedure returns a BOOL, where FALSE is an error.
  151. *
  152. * ExitOleProc();
  153. *
  154. * Procedure returns an HRESULT (named "hres").
  155. *
  156. * ExitOleProcPpv(ppvOut);
  157. *
  158. * Procedure returns an HRESULT (named "hres") and, on success,
  159. * puts a new object in ppvOut.
  160. *
  161. * The ExitBenign* versions consider any error to be benign.
  162. *
  163. *****************************************************************************/
  164. #define cpvArgMax 10 /* Max of 10 args per procedure */
  165. typedef struct ARGLIST {
  166. LPCTSTR ptszProc;
  167. LPCSTR pszFormat;
  168. PV rgpv[cpvArgMax];
  169. } ARGLIST, *PARGLIST;
  170. void EXTERNAL ArgsPalPszV(PARGLIST pal, LPCSTR psz, ...);
  171. void EXTERNAL EnterSqflPszPal(SQFL sqfl, LPCTSTR psz, PARGLIST pal);
  172. void EXTERNAL ExitSqflPalHresPpv(SQFL, PARGLIST, HRESULT, PPV);
  173. void EXTERNAL Sqfl_Init(void);
  174. #ifdef DEBUG
  175. extern BYTE g_rgbSqfl[sqflMaxArea];
  176. BOOL INLINE
  177. IsSqflSet(SQFL sqfl)
  178. {
  179. WORD wHi;
  180. if (LOWORD(sqfl) == sqflAlways) {
  181. return TRUE;
  182. }
  183. wHi = HIWORD(sqfl);
  184. if (wHi == 0) {
  185. wHi = HIWORD(sqflTrace);
  186. }
  187. return g_rgbSqfl[LOWORD(sqfl)] & wHi;
  188. }
  189. #endif
  190. #define _SetupEnterProc(nm) \
  191. static TCHAR s_tszProc[] = TEXT(#nm); \
  192. ARGLIST _al[1] \
  193. #define _ _al,
  194. #define ppvDword ((PPV)1)
  195. #define ppvVoid ((PPV)2)
  196. #define ppvBool ((PPV)3)
  197. #define _DoEnterProc(v) \
  198. ArgsPalPszV v; \
  199. EnterSqflPszPal(sqfl, s_tszProc, _al) \
  200. #define _EnterProc(nm, v) \
  201. _SetupEnterProc(nm); \
  202. _DoEnterProc(v) \
  203. #define _ExitOleProcPpv(ppv) \
  204. ExitSqflPalHresPpv(sqfl, _al, hres, (PPV)(ppv)) \
  205. #define _ExitOleProc() \
  206. _ExitOleProcPpv(0) \
  207. #define _ExitProc() \
  208. ExitSqflPalHresPpv(sqfl, _al, 0, ppvVoid) \
  209. #define _ExitProcX(x) \
  210. ExitSqflPalHresPpv(sqfl, _al, (HRESULT)(x), ppvDword) \
  211. #define _ExitProcF(x) \
  212. ExitSqflPalHresPpv(sqfl, _al, (HRESULT)(x), ppvBool) \
  213. #define _ExitBenignOleProcPpv(ppv) \
  214. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, hres, (PPV)(ppv)) \
  215. #define _ExitBenignOleProc() \
  216. _ExitBenignOleProcPpv(0) \
  217. #define _ExitBenignProc() \
  218. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, 0, ppvVoid) \
  219. #define _ExitBenignProcX(x) \
  220. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, (HRESULT)(x), ppvDword) \
  221. #define _ExitBenignProcF(x) \
  222. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, (HRESULT)(x), ppvBool) \
  223. #if defined(DEBUG)
  224. #define EnterProc _EnterProc
  225. #define ExitOleProcPpv _ExitOleProcPpv
  226. #define ExitOleProc _ExitOleProc
  227. #define ExitProc _ExitProc
  228. #define ExitProcX _ExitProcX
  229. #define ExitProcF _ExitProcF
  230. #define ExitBenignOleProcPpv _ExitBenignOleProcPpv
  231. #define ExitBenignOleProc _ExitBenignOleProc
  232. #define ExitBenignProc _ExitBenignProc
  233. #define ExitBenignProcX _ExitBenignProcX
  234. #define ExitBenignProcF _ExitBenignProcF
  235. #define EnterProcS(nm, v) \
  236. static TCHAR s_tszProc2[] = TEXT(#nm); \
  237. ARGLIST _al[1]; \
  238. ArgsPalPszV v; \
  239. EnterSqflPszPal(sqfl, s_tszProc2, _al) \
  240. #define EnterProcI _EnterProc
  241. #define EnterProcR _EnterProc
  242. #define ExitOleProcPpvR _ExitOleProcPpv
  243. #define ExitOleProcR _ExitOleProc
  244. #define ExitProcR _ExitProc
  245. #define ExitProcXR _ExitProcX
  246. #define ExitProcFR _ExitProcF
  247. #define ExitBenignOleProcPpvR _ExitBenignOleProcPpv
  248. #define ExitBenignOleProcR _ExitBenignOleProc
  249. #define ExitBenignProcR _ExitBenignProc
  250. #define ExitBenignProcXR _ExitBenignProcX
  251. #define ExitBenignProcFR _ExitBenignProcF
  252. #elif defined(RDEBUG)
  253. #define EnterProc(nm, v)
  254. #define ExitOleProcPpv(ppv)
  255. #define ExitOleProc()
  256. #define ExitProc()
  257. #define ExitProcX(x)
  258. #define ExitProcF(x)
  259. #define ExitBenignOleProcPpv(ppv)
  260. #define ExitBenignOleProc()
  261. #define ExitBenignProc()
  262. #define ExitBenignProcX(x)
  263. #define ExitBenignProcF(x)
  264. #define EnterProcS(nm, v)
  265. #define EnterProcI(nm, v) static TCHAR s_tszProc[] = TEXT("")
  266. #define EnterProcR(nm, v) static TCHAR s_tszProc[] = TEXT(#nm)
  267. #define ExitOleProcPpvR(ppv)
  268. #define ExitOleProcR()
  269. #define ExitProcR()
  270. #define ExitProcXR()
  271. #define ExitProcFR()
  272. #define ExitBenignOleProcPpvR(ppv)
  273. #define ExitBenignOleProcR()
  274. #define ExitBenignProcR()
  275. #define ExitBenignProcXR()
  276. #define ExitBenignProcFR()
  277. #else
  278. #define EnterProc(nm, v)
  279. #define ExitOleProcPpv(ppv)
  280. #define ExitOleProc()
  281. #define ExitProc()
  282. #define ExitProcX(x)
  283. #define ExitProcF(x)
  284. #define ExitBenignOleProcPpv(ppv)
  285. #define ExitBenignOleProc()
  286. #define ExitBenignProc()
  287. #define ExitBenignProcX(x)
  288. #define ExitBenignProcF(x)
  289. #define EnterProcS(nm, v)
  290. #define EnterProcI(nm, v)
  291. #define EnterProcR(nm, v)
  292. #define ExitOleProcPpvR(ppv)
  293. #define ExitOleProcR()
  294. #define ExitProcR()
  295. #define ExitProcXR(x)
  296. #define ExitProcFR(x)
  297. #define ExitBenignOleProcPpvR(ppv)
  298. #define ExitBenignOleProcR()
  299. #define ExitBenignProcR()
  300. #define ExitBenignProcXR()
  301. #define ExitBenignProcFR()
  302. #endif
  303. #ifdef __cplusplus
  304. }
  305. #endif
  306. #endif // _INC_DEBUG
  307.