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.

677 lines
26 KiB

  1. /*
  2. (C) Copyright 1998
  3. All rights reserved.
  4. Portions of this software are:
  5. (C) Copyright 1994 TriplePoint, Inc. -- http://www.TriplePoint.com
  6. License to use this software is granted under the same terms
  7. outlined in the Microsoft Windows Device Driver Development Kit.
  8. (C) Copyright 1992 Microsoft Corp. -- http://www.Microsoft.com
  9. License to use this software is granted under the terms outlined in
  10. the Microsoft Windows Device Driver Development Kit.
  11. @doc INTERNAL TpiDebug TpiDebug_h
  12. @module TpiDebug.h |
  13. This module, along with <f TpiDebug\.c>, implements code and macros to
  14. support NDIS driver debugging. This file should be #include'd in all
  15. the driver source code modules.
  16. @comm
  17. The code and macros defined by these modules is only generated during
  18. development debugging when the C pre-processor macro flag (DBG == 1).
  19. If (DBG == 0) no code will be generated, and all debug strings will be
  20. removed from the image.
  21. This is a driver independent module which can be re-used, without
  22. change, by any NDIS3 driver.
  23. @head3 Contents |
  24. @index class,mfunc,func,msg,mdata,struct,enum | TpiDebug_h
  25. @end
  26. */
  27. #ifndef _TPIDEBUG_H
  28. #define _TPIDEBUG_H
  29. /* @doc INTERNAL TpiDebug TpiDebug_h
  30. @topic Debug Globals |
  31. Debug macros are used to display error conditions, warnings, interesting
  32. events, and general flow through the components. Setting one or more bits
  33. in the <f DbgInfo> global variable will enable the output from these
  34. macros. See <t DEBUG_FLAGS> for details of the bits. Only the debug
  35. version of the driver will contain code for this purpose. All these
  36. macros will be compiled out in the release version.
  37. Each component has a separate <f DbgInfo> variable, so you can control
  38. debug output for each module separately. By default, all the modules
  39. breakpoint at their entry point to display the current value and memory
  40. location of the module's <f DbgInfo> variable. This way you can use
  41. the debugger to change the flags when the module is started. The default
  42. flag for each module is set at compile time, but can be overridden at
  43. run time using the debugger.
  44. @globalv DBG_SETTINGS | DbgInfo |
  45. DbgInfo is a global variable which points to the <t DBG_SETTINGS> for
  46. the module linked with <f TpiDebug\.c>. It is passed to most of
  47. the debug output macros to control which output is to be displayed.
  48. See <t DBG_FLAGS> to determine which bits to set.
  49. */
  50. /*
  51. // Module ID numbers to use for error logging
  52. */
  53. #define TPI_MODULE_PARAMS ((unsigned long)'P')+\
  54. ((unsigned long)'A'<<8)+\
  55. ((unsigned long)'R'<<16)+\
  56. ((unsigned long)'M'<<24)
  57. #define TPI_MODULE_DEBUG ((unsigned long)'D')+\
  58. ((unsigned long)'B'<<8)+\
  59. ((unsigned long)'U'<<16)+\
  60. ((unsigned long)'G'<<24)
  61. #define TPI_MODULE_PERF ((unsigned long)'P')+\
  62. ((unsigned long)'E'<<8)+\
  63. ((unsigned long)'R'<<16)+\
  64. ((unsigned long)'F'<<24)
  65. #define TPI_MODULE_WRAPS ((unsigned long)'W')+\
  66. ((unsigned long)'R'<<8)+\
  67. ((unsigned long)'A'<<16)+\
  68. ((unsigned long)'P'<<24)
  69. // In case these aren't defined in the current environment.
  70. #if !defined(IN)
  71. # define IN
  72. # define OUT
  73. #endif
  74. /* @doc INTERNAL TpiDebug TpiDebug_h DBG_FLAGS
  75. @enum DBG_FLAGS |
  76. The registry parameter <f DebugFlags> is read by the driver at
  77. initialization time and saved in the <f DbgFlags> field of the
  78. debug settings structure (See <t DBG_SETTINGS>). This value
  79. controls the output of debug information according to the
  80. following bit OR'd flags. The most significant 16 bits of the
  81. DbgFlags is available to use as you please, and can be used
  82. with the <f DBG_FILTER> macro.
  83. */
  84. #define DBG_ERROR_ON 0x0001L
  85. // @emem DBG_ERROR_ON | (0x0001) Display <f DBG_ERROR> messages.
  86. #define DBG_WARNING_ON 0x0002L
  87. // @emem DBG_WARNING_ON | (0x0002) Display <f DBG_WARNING> messages.
  88. #define DBG_NOTICE_ON 0x0004L
  89. // @emem DBG_NOTICE_ON | (0x0004) Display <f DBG_NOTICE> messages.
  90. #define DBG_TRACE_ON 0x0008L
  91. // @emem DBG_TRACE_ON | (0x0008) Display <f DBG_ENTER>, <f DBG_LEAVE>,
  92. // and <f DBG_TRACE> messages.
  93. #define DBG_REQUEST_ON 0x0010L
  94. // @emem DBG_REQUEST_ON | (0x0010) Display NDIS Set/Query request
  95. // parameters using <f DBG_REQUEST>.
  96. #define DBG_INDICATE_ON 0x0020L
  97. // @emem DBG_INDICATE_ON | (0x0020) Display NDIS status indications.
  98. #define DBG_TAPICALL_ON 0x0040L
  99. // @emem DBG_TAPICALL_ON | (0x0040) Display TAPI call state messages
  100. // using <f DBG_FILTER>.
  101. #define DBG_PARAMS_ON 0x0080L
  102. // @emem DBG_PARAMS_ON | (0x0080) Display function parameters and
  103. // return values using <f DBG_PARAMS>.
  104. #define DBG_TXRX_LOG_ON 0x0100L
  105. // @emem DBG_TXRX_LOG_ON | (0x0100) Enable Tx/Rx data logging.
  106. #define DBG_TXRX_ON 0x0200L
  107. // @emem DBG_TXRX_ON | (0x0200) Display Tx/Rx terse packet info.
  108. // This flag will just display the link index and packet length Rx#:#.
  109. #define DBG_TXRX_HEADERS_ON 0x0400L
  110. // @emem DBG_TXRX_HEADERS_ON | (0x0400) Display Tx/Rx packet headers.
  111. #define DBG_HEADERS_ON DBG_TXRX_HEADERS_ON
  112. #define DBG_TXRX_VERBOSE_ON 0x0800L
  113. // @emem DBG_TXRX_VERBOSE_ON | (0x0800) Display Tx/Rx packet data.
  114. #define DBG_PACKETS_ON DBG_TXRX_VERBOSE_ON
  115. #define DBG_MEMORY_ON 0x1000L
  116. // @emem DBG_MEMORY_ON | (0x1000) Display memory allocate and
  117. // free usage information.
  118. #define DBG_BUFFER_ON 0x2000L
  119. // @emem DBG_BUFFER_ON | (0x2000) Display buffer allocate and
  120. // free usage information.
  121. #define DBG_PACKET_ON 0x4000L
  122. // @emem DBG_PACKET_ON | (0x4000) Display packet allocate and
  123. // free usage information.
  124. #define DBG_BREAK_ON 0x8000L
  125. // @emem DBG_BREAK_ON | (0x8000) Enable <f DBG_BREAK> breakpoints.
  126. #define DbgFlags DebugFlags // For compatability
  127. #define DbgID AnsiDeviceName // For compatability
  128. #ifdef __cplusplus
  129. extern "C" {
  130. #endif // __cplusplus
  131. /* @doc INTERNAL TpiDebug TpiDebug_h DBG_SETTINGS
  132. @struct DBG_SETTINGS |
  133. This structure is used to control debug output for a given module.
  134. You can set and clear bits in the DbgFlags field to enabled and
  135. disable various debug macros. See <t DBG_FLAGS> to determine which
  136. bits to set.
  137. */
  138. typedef struct DBG_SETTINGS
  139. {
  140. unsigned long DbgFlags; // @field
  141. // Debug flags control how much debug is displayed in the checked build.
  142. // Put this field at the front so you can set it easily with debugger.
  143. // See <t DBG_FLAGS> to determine which bits to set in this field.
  144. unsigned char DbgID[12]; // @field
  145. // This field is initialized to an ASCII string containing a unique
  146. // module identifier. It is used to prefix debug messages. If you
  147. // have more than one module based on this code, you may want to
  148. // change the default value to a unqiue string for each module.
  149. // This string is used a C string, so the last byte must be a zero.
  150. } DBG_SETTINGS, *PDBG_SETTINGS;
  151. extern PDBG_SETTINGS DbgInfo;
  152. /* @doc INTERNAL TpiDebug TpiDebug_h DBG_FIELD_TABLE
  153. @struct DBG_FIELD_TABLE |
  154. This structure contains the data associated with a C data structure.
  155. You can use the <f DBG_FIELD_ENTRY> macro to add entries into a
  156. <t DBG_FIELD_TABLE>. At run-time you can pass this table pointer to
  157. the <f DbgPrintFieldTable> routine, and it will display the current
  158. contents of that data structure. This is useful for debugging drivers
  159. or code where no symbolic debugger is available, or if you have want to
  160. dump structure contents when certain run-time events are encountered.
  161. @comm
  162. If you have nested structures, you must display them separately. The
  163. <f DBG_FIELD_ENTRY> macro can only be used to declare integer type
  164. fields, and pointers. Pointers will be displayed as a long integer.<nl>
  165. The last entry in the table must be all zeros {0}.
  166. */
  167. typedef struct DBG_FIELD_TABLE
  168. {
  169. unsigned int FieldOffset; // @parm
  170. // This value indicates the offset, in bytes, from the <f pBaseContext>
  171. // pointer passed into <f DbgPrintFieldTable>. The value for the field
  172. // will be displayed from this offset from <f pBaseContext>.
  173. // <nl>*(PUINT)((PUCHAR)BaseContext+Offset) = (UINT) Value;
  174. unsigned int FieldType; // @parm
  175. // This value determines how the value will be displayed.
  176. // <f FieldType> can be one of the following values:
  177. // <nl>1=UCHAR - unsigned char integer (8 bits).
  178. // <nl>2=USHORT - unsigned short integer (16 bits).
  179. // <nl>4=ULONG - unsigned long integer (32 bits).
  180. unsigned char * FieldName; // @parm
  181. // This value points to a C String which is the name of the field within
  182. // the structure.
  183. } DBG_FIELD_TABLE, *PDBG_FIELD_TABLE;
  184. #define DBG_FIELD_BUFF 0
  185. #define DBG_FIELD_CHAR 1
  186. #define DBG_FIELD_SHORT 2
  187. #define DBG_FIELD_LONG 4
  188. #define DBG_FIELD_OFFSET(Strct, Field) ((unsigned int)((unsigned char *) &((Strct *) 0)->Field))
  189. #define DBG_FIELD_SIZEOF(Strct, Field) sizeof(((Strct *) 0)->Field)
  190. #define DBG_FIELD_ENTRY(Strct, Field) \
  191. { DBG_FIELD_OFFSET(Strct, Field), \
  192. DBG_FIELD_SIZEOF(Strct, Field), \
  193. #Field )
  194. extern VOID DbgPrintFieldTable(
  195. IN PDBG_FIELD_TABLE pFields,
  196. IN unsigned char * pBaseContext,
  197. IN unsigned char * pBaseName
  198. );
  199. extern VOID DbgPrintData(
  200. IN unsigned char * Data,
  201. IN unsigned int NumBytes,
  202. IN unsigned long Offset
  203. );
  204. extern VOID DbgQueueData(
  205. IN unsigned char * Data,
  206. IN unsigned int NumBytes,
  207. IN unsigned int Flags
  208. );
  209. #if !defined(NDIS_WIN) || !defined(DEBUG)
  210. extern unsigned long __cdecl DbgPrint(char * Format, ...);
  211. #endif
  212. // DbgBreakPoint is ugly because it is defined by NTDDK as _stdcall,
  213. // and 95DDK #defines it, and we must define our own for non-DDK builds.
  214. // So all these ifdefs are used to figure out how to handle it.
  215. #ifdef DbgBreakPoint
  216. # undef DbgBreakPoint
  217. #endif // DbgBreakPoint
  218. #if defined(_MSC_VER) && (_MSC_VER <= 800)
  219. // Must be building with 16-bit compiler
  220. extern VOID __cdecl DbgBreakPoint(VOID);
  221. #else
  222. // Must be building with 32-bit compiler
  223. extern VOID __stdcall DbgBreakPoint(VOID);
  224. #endif
  225. extern VOID DbgSilentQueue(unsigned char * str);
  226. #ifdef __cplusplus
  227. };
  228. #endif // __cplusplus
  229. // NDIS builds define DBG=0 or DBG=1
  230. #if defined(DEBUG) || defined(_DEBUG)
  231. # ifndef DBG
  232. # define DBG 1
  233. # endif
  234. #else
  235. # ifndef DBG
  236. # define DBG 0
  237. # endif
  238. #endif
  239. //###############################################################################
  240. #if DBG
  241. //###############################################################################
  242. #ifndef ASSERTS_ENABLED
  243. # define ASSERTS_ENABLED 1
  244. #endif
  245. #ifndef DBG_DEFAULTS
  246. # define DBG_DEFAULTS (DBG_ERROR_ON | DBG_WARNING_ON | DBG_BREAK_ON)
  247. #endif
  248. /* @doc INTERNAL TpiDebug TpiDebug_h
  249. */
  250. # define STATIC
  251. # define DBG_STATIC
  252. // Make all variables and functions global, so debugger can see them.
  253. # define TRAPFAULT DbgBreakPoint()
  254. // Use this macro to insert an unconditional INT-1 breakpoint. This
  255. // is used to distinguish between normal debugger breakpoints (INT-3)
  256. // and any special cases, such as ASSERT.
  257. # define BREAKPOINT DbgBreakPoint()
  258. // Use this macro to insert an unconditional INT-3 breakpoint.
  259. # define DBG_FUNC(F) static const char __FUNC__[] = F;
  260. // @func const char [] | DBG_FUNC |
  261. //
  262. // Use this macro to define the __FUNC__ string used by the rest of the
  263. // debugger macros to report the name of the function calling the macro.
  264. //
  265. // @parm const char * | FunctionName | Name of the function being defined.
  266. //
  267. // @ex <tab> | DBG_FUNC("MyFunctionName");
  268. # define DBG_BREAK(A) {if ((A) && ((A)->DbgFlags & DBG_BREAK_ON) || !(A)) \
  269. BREAKPOINT;}
  270. // @func VOID | DBG_BREAK |
  271. //
  272. // Use this macro to insert a conditional INT-3 breakpoint.
  273. //
  274. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  275. //
  276. // @ex <tab> | DBG_BREAK(DbgInfo);
  277. # define DBG_ENTER(A) {if ((A) && ((A)->DbgFlags & DBG_TRACE_ON)) \
  278. {DbgPrint("%s:>>>:%s\n",(A)->DbgID,__FUNC__);}}
  279. // @func VOID | DBG_ENTER |
  280. //
  281. // Use this macro to report entry to a function.
  282. //
  283. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  284. //
  285. // @ex <tab> | DBG_ENTER(DbgInfo);
  286. # define DBG_TRACE(A) {if ((A) && ((A)->DbgFlags & DBG_TRACE_ON)) \
  287. {DbgPrint("%s:%d:%s\n",(A)->DbgID,__LINE__,\
  288. __FUNC__);}}
  289. // @func VOID | DBG_TRACE |
  290. //
  291. // Use this macro to report a trace location within a function.
  292. //
  293. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  294. //
  295. // @ex <tab> | DBG_TRACE(DbgInfo);
  296. # define DBG_LEAVE(A) {if ((A) && ((A)->DbgFlags & DBG_TRACE_ON)) \
  297. {DbgPrint("%s:<<<:%s\n",(A)->DbgID,__FUNC__);}}
  298. // @func VOID | DBG_LEAVE |
  299. //
  300. // Use this macro to report exit from a function.
  301. //
  302. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  303. //
  304. // @ex <tab> | DBG_LEAVE(DbgInfo);
  305. # define DBG_RETURN(A,S) {if ((A) && ((A)->DbgFlags & DBG_TRACE_ON)) \
  306. {DbgPrint("%s:<<<:%s Return(0x%lX)\n",(A)->DbgID,__FUNC__,S);}}
  307. // @func VOID | DBG_RETURN |
  308. //
  309. // Use this macro to report exit from a function with a result.
  310. //
  311. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  312. //
  313. // @ex <tab> | DBG_RETURN(DbgInfo, Result);
  314. # define DBG_ERROR(A,S) {if ((A) && ((A)->DbgFlags & DBG_ERROR_ON)) \
  315. {DbgPrint("%s:ERROR:%s ",(A)->DbgID,__FUNC__);\
  316. DbgPrint S; \
  317. if ((A)->DbgFlags & DBG_BREAK_ON) \
  318. {TRAPFAULT;}}}
  319. // @func VOID | DBG_ERROR |
  320. //
  321. // Use this macro to report any unexpected error conditions.
  322. //
  323. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  324. //
  325. // @parm PRINTF_ARGS | PrintfArgs | Parenthesized, printf format string,
  326. // followed by parameters.
  327. //
  328. // @ex <tab> | DBG_ERROR(DbgInfo, ("Expected %d - Actual %d\n", Expected, Actual));
  329. # define DBG_WARNING(A,S) {if ((A) && ((A)->DbgFlags & DBG_WARNING_ON)) \
  330. {DbgPrint("%s:WARNING:%s ",(A)->DbgID,__FUNC__);\
  331. DbgPrint S;}}
  332. // @func VOID | DBG_WARNING |
  333. //
  334. // Use this macro to report any unusual run-time conditions.
  335. //
  336. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  337. //
  338. // @parm PRINTF_ARGS | PrintfArgs | Parenthesized, printf format string,
  339. // followed by parameters.
  340. //
  341. // @ex <tab> | DBG_WARNING(DbgInfo, ("Expected %d - Actual %d\n", Expected, Actual));
  342. # define DBG_NOTICE(A,S) {if ((A) && ((A)->DbgFlags & DBG_NOTICE_ON)) \
  343. {DbgPrint("%s:NOTICE:%s ",(A)->DbgID,__FUNC__);\
  344. DbgPrint S;}}
  345. // @func VOID | DBG_NOTICE |
  346. //
  347. // Use this macro to report any verbose debug information.
  348. //
  349. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  350. //
  351. // @ex <tab> | DBG_NOTICE(DbgInfo, ("Expected %d - Actual %d\n", Expected, Actual));
  352. # define DBG_REQUEST(A,S) {if ((A) && ((A)->DbgFlags & DBG_REQUEST_ON)) \
  353. {DbgPrint("%s:REQUEST:%s ",(A)->DbgID,__FUNC__);\
  354. DbgPrint S;}}
  355. // @func VOID | DBG_REQUEST |
  356. //
  357. // Use this macro to report NDIS Set/Query request information.
  358. //
  359. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  360. //
  361. // @ex <tab> | DBG_REQUEST(DbgInfo, ("Oid #0x%08X - %s\n", Oid, DbgGetOidString(Oid)));
  362. # define DBG_PARAMS(A,S) {if ((A) && ((A)->DbgFlags & DBG_PARAMS_ON)) \
  363. {DbgPrint("%s:PARAMS:%s ",(A)->DbgID,__FUNC__);\
  364. DbgPrint S;}}
  365. // @func VOID | DBG_PARAMS |
  366. //
  367. // Use this macro to report NDIS Set/Query request information.
  368. //
  369. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  370. //
  371. // @ex <tab> | DBG_PARAMS(DbgInfo, ("\n\tNum=0x%X\n\tStr='%s'\n", Num, Str));
  372. # define DBG_TX(A,I,N,B) {if ((A) && ((A)->DbgFlags & (DBG_TXRX_ON | \
  373. DBG_TXRX_VERBOSE_ON | \
  374. DBG_TXRX_HEADERS_ON))) \
  375. {DbgPrint("%s:Tx%d:%03X:\n",(A)->DbgID,I,N); \
  376. if (((A)->DbgFlags & DBG_TXRX_VERBOSE_ON)) \
  377. DbgPrintData((unsigned char *)B, (unsigned int)N, 0); \
  378. else if (((A)->DbgFlags & DBG_TXRX_HEADERS_ON)) \
  379. DbgPrintData((unsigned char *)B, 0x10, 0); \
  380. }\
  381. if ((A) && ((A)->DbgFlags & DBG_TXRX_LOG_ON)) \
  382. DbgQueueData((unsigned char *)B, (unsigned int)N, \
  383. (USHORT)((I<< 8) + 0x4000)); \
  384. }
  385. // @func VOID | DBG_TX |
  386. //
  387. // Use this macro to report outgoing packet information.
  388. //
  389. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  390. //
  391. // @parm IN UINT | Index | Index used to identify channel or stream.
  392. //
  393. // @parm IN UINT | NumBytes | Number of bytes being transmitted.
  394. //
  395. // @parm IN PUCHAR | Buffer | Pointer to data buffer being transmitted.
  396. //
  397. // @ex <tab> | DBG_TX(DbgInfo, BChannelIndex, BytesToSend, CurrentBuffer);
  398. # define DBG_TXC(A,I) {if ((A) && ((A)->DbgFlags & (DBG_TXRX_ON | \
  399. DBG_TXRX_VERBOSE_ON | \
  400. DBG_TXRX_HEADERS_ON))) \
  401. {DbgPrint("%s:Tc%d\n",(A)->DbgID,I); \
  402. }}
  403. // @func VOID | DBG_TXC |
  404. //
  405. // Use this macro to report outgoing packet completion.
  406. //
  407. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  408. //
  409. // @parm IN UINT | Index | Index used to identify channel or stream.
  410. //
  411. // @ex <tab> | DBG_TXC(DbgInfo, BChannelIndex);
  412. # define DBG_RX(A,I,N,B) {if ((A) && ((A)->DbgFlags & (DBG_TXRX_ON | \
  413. DBG_TXRX_VERBOSE_ON | \
  414. DBG_TXRX_HEADERS_ON))) \
  415. {DbgPrint("%s:Rx%d:%03X:\n",(A)->DbgID,I,N); \
  416. if (((A)->DbgFlags & DBG_TXRX_VERBOSE_ON)) \
  417. DbgPrintData((unsigned char *)B, (unsigned int)N, 0); \
  418. else if (((A)->DbgFlags & DBG_TXRX_HEADERS_ON)) \
  419. DbgPrintData((unsigned char *)B, 0x10, 0); \
  420. }\
  421. if ((A) && ((A)->DbgFlags & DBG_TXRX_LOG_ON)) \
  422. DbgQueueData((unsigned char *)B, (unsigned int)N, \
  423. (USHORT)((I<< 8) + 0x8000)); \
  424. }
  425. // @func VOID | DBG_RX |
  426. //
  427. // Use this macro to report incoming packet information.
  428. //
  429. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  430. //
  431. // @parm IN UINT | Index | Index used to identify channel or stream.
  432. //
  433. // @parm IN UINT | NumBytes | Number of bytes being received.
  434. //
  435. // @parm IN PUCHAR | Buffer | Pointer to data buffer being received.
  436. //
  437. // @ex <tab> | DBG_RX(DbgInfo, BChannelIndex, BytesReceived, ReceiveBuffer);
  438. # define DBG_RXC(A,I) {if ((A) && ((A)->DbgFlags & (DBG_TXRX_ON | \
  439. DBG_TXRX_VERBOSE_ON | \
  440. DBG_TXRX_HEADERS_ON))) \
  441. {DbgPrint("%s:Rc%d\n",(A)->DbgID,I); \
  442. }}
  443. // @func VOID | DBG_RXC |
  444. //
  445. // Use this macro to report incoming packet completion.
  446. //
  447. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  448. //
  449. // @parm IN UINT | Index | Index used to identify channel or stream.
  450. //
  451. // @ex <tab> | DBG_RXC(DbgInfo, BChannelIndex);
  452. # define DBG_FILTER(A,M,S){if ((A) && ((A)->DbgFlags & (M))) \
  453. {DbgPrint("%s:%s: ",(A)->DbgID,__FUNC__); \
  454. DbgPrint S;}}
  455. // @func VOID | DBG_FILTER |
  456. //
  457. // Use this macro to filter for specific DbgFlag combinations.
  458. //
  459. // @parm IN DBG_SETTINGS | DbgInfo | Pointer to <t DBG_SETTINGS> structure.
  460. //
  461. // @parm IN DBG_FLAGS | DbgMask | OR'd mask of <t DBG_FLAGS>.
  462. //
  463. // @parm PRINTF_ARGS | PrintfArgs | Parenthesized, printf format string,
  464. // followed by parameters.
  465. //
  466. // @ex <tab> | DBG_FILTER(DbgInfo, DBG_FILTER1_ON | DBG_REQUEST_ON,
  467. // ("Expected %d - Actual %d\n", Expected, Actual));
  468. # define DBG_DISPLAY(S) {DbgPrint("%s: ",__FUNC__); DbgPrint S;}
  469. // @func VOID | DBG_DISPLAY |
  470. //
  471. // Use this macro to unconditionally report a message. This macro does
  472. // not take a pointer to the DBG_SETTINGS structure, so it can be used in
  473. // any module or function of the driver. There is no way to disable the
  474. // display of these messages. The funcion name precedes the output string.
  475. //
  476. // @parm PRINTF_ARGS | PrintfArgs | Parenthesized, printf format string,
  477. // followed by parameters.
  478. //
  479. // @ex <tab> | DBG_DISPLAY(("Expected %d - Actual %d\n", Expected, Actual));
  480. # define DBG_PRINT(S) {DbgPrint S;}
  481. // @func VOID | DBG_PRINT |
  482. //
  483. // Use this macro to unconditionally report a message. This macro does
  484. // not take a pointer to the DBG_SETTINGS structure, so it can be used in
  485. // any module or function of the driver. There is no way to disable the
  486. // display of these messages.
  487. //
  488. // @parm PRINTF_ARGS | PrintfArgs | Parenthesized, printf format string,
  489. // followed by parameters.
  490. //
  491. // @ex <tab> | DBG_PRINT(("What happened at line %d!\n",__LINE__));
  492. //###############################################################################
  493. #else // !DBG
  494. //###############################################################################
  495. #ifndef ASSERTS_ENABLED
  496. # define ASSERTS_ENABLED 0
  497. #endif
  498. # define DBG_DEFAULTS (0)
  499. /*
  500. // When (DBG == 0) we disable all the debug macros.
  501. */
  502. # define STATIC static
  503. # define DBG_STATIC static
  504. # define TRAPFAULT DbgBreakPoint()
  505. # define BREAKPOINT
  506. # define DBG_FUNC(F)
  507. # define DBG_BREAK(A)
  508. # define DBG_ENTER(A)
  509. # define DBG_TRACE(A)
  510. # define DBG_LEAVE(A)
  511. # define DBG_RETURN(A,S)
  512. # define DBG_ERROR(A,S)
  513. # define DBG_WARNING(A,S)
  514. # define DBG_NOTICE(A,S)
  515. # define DBG_REQUEST(A,S)
  516. # define DBG_PARAMS(A,S)
  517. # define DBG_TX(A,I,N,P)
  518. # define DBG_TXC(A,I)
  519. # define DBG_RX(A,I,N,P)
  520. # define DBG_RXC(A,I)
  521. # define DBG_FILTER(A,M,S)
  522. # define DBG_DISPLAY(S)
  523. # define DBG_PRINT(S)
  524. //###############################################################################
  525. #endif // DBG
  526. //###############################################################################
  527. #ifdef ASSERT
  528. # undef ASSERT
  529. #endif
  530. #ifdef assert
  531. # undef assert
  532. #endif
  533. #if ASSERTS_ENABLED
  534. #define ASSERT(C) if (!(C)) { \
  535. DbgPrint("ASSERT(%s) -- FILE:%s LINE:%d\n", \
  536. #C, __FILE__, __LINE__); \
  537. TRAPFAULT; \
  538. }
  539. // @func VOID | ASSERT |
  540. //
  541. // Use this macro to conditionally report a fatal error if the condition
  542. // specified is NOT true.
  543. //
  544. // @parm BOOLEAN_EXPRESSION | Expression | Any valid if (Expression).
  545. //
  546. // @ex <tab> | ASSERT(Actual == Expected);
  547. # define assert(C) ASSERT(C)
  548. #else // !ASSERTS_ENABLED
  549. # define ASSERT(C)
  550. # define assert(C)
  551. #endif // ASSERTS_ENABLED
  552. #endif // _TPIDEBUG_H