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.

383 lines
13 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: debug.h
  6. * Content: DirectInput debugging macros
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 1996.05.07 raymondc Somebody had to
  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 XDEBUG
  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. * A sqfl is in multiple parts.
  43. *
  44. * The low word specifies the area that is generating the message.
  45. *
  46. * The high word contains flags that describe why this squirty
  47. * is being generated.
  48. *
  49. *****************************************************************************/
  50. typedef enum {
  51. /*
  52. * Areas.
  53. */
  54. sqflAlways = 0x0000, /* Unconditional */
  55. sqflDll = 0x0001, /* Dll bookkeeping */
  56. sqflFactory = 0x0002, /* IClassFactory */
  57. sqflDi = 0x0003, /* IDirectInput */
  58. sqflMouse = 0x0004, /* IDirectInputMouse */
  59. sqflDev = 0x0005, /* IDirectInputDevice */
  60. sqflKbd = 0x0006, /* IDirectInputKeyboard */
  61. sqflDf = 0x0007, /* DataFormat goo */
  62. sqflJoy = 0x0008, /* joystick device */
  63. sqflEm = 0x0009, /* Emulation */
  64. sqflSubclass = 0x000A, /* subclassing */
  65. sqflCursor = 0x000B, /* Cursor show/hide */
  66. sqflHel = 0x000C, /* Hardware emulation layer */
  67. sqflLl = 0x000D, /* Low-level hooks */
  68. sqflExcl = 0x000E, /* Exclusivity management */
  69. sqflDEnum = 0x000F, /* Device enumeration */
  70. sqflExtDll = 0x0010, /* External DLLs */
  71. sqflHid = 0x0011, /* HID support */
  72. sqflHidDev = 0x0012, /* HID device support */
  73. sqflJoyCfg = 0x0013, /* IDirectInputJoyConfig */
  74. sqflEff = 0x0014, /* IDirectInputEffect */
  75. sqflOleDup = 0x0015, /* OLE duplication */
  76. sqflEShep = 0x0016, /* IDirectInputEffectShepherd */
  77. sqflJoyEff = 0x0017, /* Dummy DIEffectDriver */
  78. sqflJoyReg = 0x0018, /* Joystick registry goo */
  79. sqflVxdEff = 0x0019, /* VxD DIEffectDriver */
  80. sqflNil = 0x001A, /* CNil and CDefDcb */
  81. sqflHidUsage = 0x001B, /* HID usage mapping */
  82. sqflUtil = 0x001C, /* Misc utility fns */
  83. sqflObj = 0x001D, /* Object creation/destruction */
  84. sqflCommon = 0x001E, /* common.c */
  85. sqflHidParse = 0x001F, /* HID report parsing */
  86. sqflCal = 0x0020, /* Axis calibrations */
  87. sqflJoyType = 0x0021, /* Joystick type key */
  88. sqflHidOutput = 0x0022, /* HID output reports */
  89. sqflHidIni = 0x0023, /* HID device initialization */
  90. sqflPort = 0x0024, /* GamePort Bus Enumuration */
  91. sqflWDM = 0x0025, /* WDM specific Code */
  92. sqflRegUtils = 0x0026, /* Registry utilities */
  93. sqflCrit = 0x0027, /* Critical Section tracking */
  94. sqflCompat = 0x0028, /* App Hacks */
  95. sqflRaw = 0x0029, /* Raw Input - keyboard and mouse */
  96. sqflMaxArea, /* Last area */
  97. /*
  98. * Flags which may be combined. For now, they all fit into a byte.
  99. */
  100. sqflTrace = 0x00010000, /* Trace squirties */
  101. sqflIn = 0x00020000, /* Function entry */
  102. sqflOut = 0x00040000, /* Function exit */
  103. sqflBenign = 0x00080000, /* Not a bad error */
  104. sqflError = 0x00100000, /* A bad error */
  105. sqflVerbose = 0x00200000, /* Really verbose */
  106. sqflMajor = 0x00400000, /* Significant, generally positive, events */
  107. } SQFL; /* squiffle */
  108. void EXTERNAL WarnPszV(LPCSTR ptsz, ...);
  109. void EXTERNAL SquirtSqflPtszV(SQFL sqfl, LPCTSTR ptsz, ...);
  110. #ifndef DEBUG
  111. #define SquirtSqflPtszV sizeof
  112. #endif
  113. #ifdef XDEBUG
  114. #define RPF WarnPszV
  115. #else
  116. #define WarnPszV sizeof
  117. #define RPF sizeof
  118. #define s_szProc 0
  119. #define iarg 0
  120. #endif
  121. /*****************************************************************************
  122. *
  123. * Buffer scrambling
  124. *
  125. * All output buffers should be scrambled on entry to any function.
  126. *
  127. * Each output bitmask should set an unused bit randomly to ensure
  128. * that callers ignore bits that aren't defined.
  129. *
  130. *****************************************************************************/
  131. #ifdef XDEBUG
  132. void EXTERNAL ScrambleBuf(LPVOID pv, UINT cb);
  133. void EXTERNAL ScrambleBit(LPDWORD pdw, DWORD flMask);
  134. #else
  135. #define ScrambleBuf(pv, cb)
  136. #define ScrambleBit(pdw, flRandom)
  137. #endif
  138. /*****************************************************************************
  139. *
  140. * Procedure enter/exit tracking.
  141. *
  142. * Start a procedure with
  143. *
  144. * EnterProc(ProcedureName, (_ "format", arg, arg, arg, ...));
  145. * EnterProcS(ProcedureName, (_ "format", arg, arg, arg, ...));
  146. * EnterProcI(ProcedureName, (_ "format", arg, arg, arg, ...));
  147. * EnterProcR(ProcedureName, (_ "format", arg, arg, arg, ...));
  148. *
  149. * The format string is documented in EmitPal.
  150. *
  151. * Suffixing an "S" indicates that the macro should not generate
  152. * a procedure name because there is a formal parameter with the
  153. * name s_szProc. This is a hack.
  154. *
  155. * Suffixing an "R" indicates that the macro should generate a
  156. * procedure name in RDEBUG.
  157. *
  158. * Suffixing an "I" indicates that the macro should emit a dummy
  159. * procedure name in RDEBUG because the interface is internal.
  160. *
  161. * No suffix means that the macro should be active only in the
  162. * DEBUG build and should vanish in RDEBUG (and RETAIL).
  163. *
  164. * End a procedure with one of the following:
  165. *
  166. * ExitProc();
  167. *
  168. * Procedure returns no value.
  169. *
  170. * ExitProcX();
  171. *
  172. * Procedure returns an arbitrary DWORD.
  173. *
  174. * ExitProcF();
  175. *
  176. * Procedure returns a BOOL, where FALSE is an error.
  177. *
  178. * ExitOleProc();
  179. *
  180. * Procedure returns an HRESULT (named "hres").
  181. *
  182. * ExitOleProcPpv(ppvOut);
  183. *
  184. * Procedure returns an HRESULT (named "hres") and, on success,
  185. * puts a new object in ppvOut.
  186. *
  187. * The ExitBenign* versions consider any error to be benign.
  188. *
  189. *****************************************************************************/
  190. #define cpvArgMax 10 /* Max of 10 args per procedure */
  191. typedef struct ARGLIST {
  192. LPCSTR pszProc;
  193. LPCSTR pszFormat;
  194. PV rgpv[cpvArgMax];
  195. } ARGLIST, *PARGLIST;
  196. void EXTERNAL ArgsPalPszV(PARGLIST pal, LPCSTR psz, ...);
  197. void EXTERNAL EnterSqflPszPal(SQFL sqfl, LPCSTR psz, PARGLIST pal);
  198. void EXTERNAL ExitSqflPalHresPpv(SQFL, PARGLIST, HRESULT, PPV);
  199. void EXTERNAL Sqfl_Init(void);
  200. #ifdef DEBUG
  201. extern BYTE g_rgbSqfl[sqflMaxArea];
  202. BOOL INLINE
  203. IsSqflSet(SQFL sqfl)
  204. {
  205. WORD wHi;
  206. if (LOWORD(sqfl) == sqflAlways) {
  207. return TRUE;
  208. }
  209. wHi = HIWORD(sqfl);
  210. if (wHi == 0) {
  211. wHi = HIWORD(sqflTrace);
  212. }
  213. return g_rgbSqfl[LOWORD(sqfl)] & wHi;
  214. }
  215. #endif
  216. #define _SetupEnterProc(nm) \
  217. static CHAR s_szProc[] = #nm; \
  218. ARGLIST _al[1] \
  219. #define _ _al,
  220. #define ppvDword ((PPV)1)
  221. #define ppvVoid ((PPV)2)
  222. #define ppvBool ((PPV)3)
  223. #define _DoEnterProc(v) \
  224. ArgsPalPszV v; \
  225. EnterSqflPszPal(sqfl, s_szProc, _al) \
  226. #define _EnterProc(nm, v) \
  227. _SetupEnterProc(nm); \
  228. _DoEnterProc(v) \
  229. #define _ExitOleProcPpv(ppv) \
  230. ExitSqflPalHresPpv(sqfl, _al, hres, (PPV)(ppv)) \
  231. #define _ExitOleProc() \
  232. _ExitOleProcPpv(0) \
  233. #define _ExitProc() \
  234. ExitSqflPalHresPpv(sqfl, _al, 0, ppvVoid) \
  235. #define _ExitProcX(x) \
  236. ExitSqflPalHresPpv(sqfl, _al, (HRESULT)(x), ppvDword) \
  237. #define _ExitProcF(x) \
  238. ExitSqflPalHresPpv(sqfl, _al, (HRESULT)(x), ppvBool) \
  239. #define _ExitBenignOleProcPpv(ppv) \
  240. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, hres, (PPV)(ppv)) \
  241. #define _ExitBenignOleProc() \
  242. _ExitBenignOleProcPpv(0) \
  243. #define _ExitBenignProc() \
  244. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, 0, ppvVoid) \
  245. #define _ExitBenignProcX(x) \
  246. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, (HRESULT)(x), ppvDword) \
  247. #define _ExitBenignProcF(x) \
  248. ExitSqflPalHresPpv(sqfl | sqflBenign, _al, (HRESULT)(x), ppvBool) \
  249. #if defined(DEBUG)
  250. #define EnterProc _EnterProc
  251. #define ExitOleProcPpv _ExitOleProcPpv
  252. #define ExitOleProc _ExitOleProc
  253. #define ExitProc _ExitProc
  254. #define ExitProcX _ExitProcX
  255. #define ExitProcF _ExitProcF
  256. #define ExitBenignOleProcPpv _ExitBenignOleProcPpv
  257. #define ExitBenignOleProc _ExitBenignOleProc
  258. #define ExitBenignProc _ExitBenignProc
  259. #define ExitBenignProcX _ExitBenignProcX
  260. #define ExitBenignProcF _ExitBenignProcF
  261. #define EnterProcS(nm, v) \
  262. static CHAR s_szProc2[] = #nm; \
  263. ARGLIST _al[1]; \
  264. ArgsPalPszV v; \
  265. EnterSqflPszPal(sqfl, s_szProc2, _al) \
  266. #define EnterProcI _EnterProc
  267. #define EnterProcR _EnterProc
  268. #define ExitOleProcPpvR _ExitOleProcPpv
  269. #define ExitOleProcR _ExitOleProc
  270. #define ExitProcR _ExitProc
  271. #define ExitProcXR _ExitProcX
  272. #define ExitProcFR _ExitProcF
  273. #define ExitBenignOleProcPpvR _ExitBenignOleProcPpv
  274. #define ExitBenignOleProcR _ExitBenignOleProc
  275. #define ExitBenignProcR _ExitBenignProc
  276. #define ExitBenignProcXR _ExitBenignProcX
  277. #define ExitBenignProcFR _ExitBenignProcF
  278. #elif defined(RDEBUG)
  279. #define EnterProc(nm, v)
  280. #define ExitOleProcPpv(ppv)
  281. #define ExitOleProc()
  282. #define ExitProc()
  283. #define ExitProcX(x)
  284. #define ExitProcF(x)
  285. #define ExitBenignOleProcPpv(ppv)
  286. #define ExitBenignOleProc()
  287. #define ExitBenignProc()
  288. #define ExitBenignProcX(x)
  289. #define ExitBenignProcF(x)
  290. #define EnterProcS(nm, v)
  291. #define EnterProcI(nm, v) static CHAR s_szProc[] = ""
  292. #define EnterProcR(nm, v) static CHAR s_szProc[] = #nm
  293. #define ExitOleProcPpvR(ppv)
  294. #define ExitOleProcR()
  295. #define ExitProcR()
  296. #define ExitProcXR()
  297. #define ExitProcFR()
  298. #define ExitBenignOleProcPpvR(ppv)
  299. #define ExitBenignOleProcR()
  300. #define ExitBenignProcR()
  301. #define ExitBenignProcXR()
  302. #define ExitBenignProcFR()
  303. #else
  304. #define EnterProc(nm, v)
  305. #define ExitOleProcPpv(ppv)
  306. #define ExitOleProc()
  307. #define ExitProc()
  308. #define ExitProcX(x)
  309. #define ExitProcF(x)
  310. #define ExitBenignOleProcPpv(ppv)
  311. #define ExitBenignOleProc()
  312. #define ExitBenignProc()
  313. #define ExitBenignProcX(x)
  314. #define ExitBenignProcF(x)
  315. #define EnterProcS(nm, v)
  316. #define EnterProcI(nm, v)
  317. #define EnterProcR(nm, v)
  318. #define ExitOleProcPpvR(ppv)
  319. #define ExitOleProcR()
  320. #define ExitProcR()
  321. #define ExitProcXR(x)
  322. #define ExitProcFR(x)
  323. #define ExitBenignOleProcPpvR(ppv)
  324. #define ExitBenignOleProcR()
  325. #define ExitBenignProcR()
  326. #define ExitBenignProcXR()
  327. #define ExitBenignProcFR()
  328. #endif
  329. #ifdef __cplusplus
  330. }
  331. #endif
  332. #endif // _INC_DEBUG