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.

330 lines
12 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. dbg.h
  5. Abstract:
  6. Debug-related definitions for ARP1394
  7. Author:
  8. Revision History:
  9. Who When What
  10. -------- -------- ----
  11. josephj 11-20-98 created, adapted from L2TP.
  12. --*/
  13. //-----------------------------------------------------------------------------
  14. // Debug constants
  15. //-----------------------------------------------------------------------------
  16. // Memory tags used with NdisAllocateMemoryWithTag to identify allocations
  17. // made by the L2TP driver. Also, several context blocks define a first field
  18. // of 'ulTag' set to these values for ASSERT sanity checking and eased memory
  19. // dump browsing. Such tags are set to MTAG_FREED just before NdisFreeMemory
  20. // is called.
  21. //
  22. // Rm/generic tags
  23. //
  24. #define MTAG_DBGINFO 'd31A'
  25. #define MTAG_TASK 't31A'
  26. #define MTAG_STRING 's31A'
  27. #define MTAG_FREED 'z31A'
  28. #define MTAG_RMINTERNAL 'r31A'
  29. // Arp-sepcific
  30. //
  31. #define MTAG_ADAPTER 'A31A'
  32. #define MTAG_INTERFACE 'I31A'
  33. #define MTAG_LOCAL_IP 'L31A'
  34. #define MTAG_REMOTE_IP 'R31A'
  35. #define MTAG_REMOTE_ETH 'E31A'
  36. #define MTAG_DEST 'D31A'
  37. #define MTAG_PKT 'P31A'
  38. #define MTAG_MCAP_GD 'G31A'
  39. #define MTAG_ICS_BUF 'i31A'
  40. #define MTAG_ARP_GENERIC 'g31A'
  41. // Trace levels.
  42. //
  43. #define TL_FATAL 0x0 // Fatal errors -- always printed in checked build.
  44. #define TL_WARN 0x1 // Warnings
  45. #define TL_INFO 0x2 // Informational (highest level workable for general use)
  46. #define TL_VERB 0x3 // VERBOSE
  47. // Trace mask bits.
  48. //
  49. #define TM_MISC (0x1<<0) // Misc.
  50. #define TM_NT (0x1<<1) // Driver entry, dispatch, ioctl handling (nt.c)
  51. #define TM_ND (0x1<<2) // Ndis handlers except connection-oriented (nd.c)
  52. #define TM_CO (0x1<<3) // Connection-oriented handlers (co.c)
  53. #define TM_IP (0x1<<4) // Interface to IP (ip.c)
  54. #define TM_WMI (0x1<<5) // WMI (wmi.c)
  55. #define TM_CFG (0x1<<6) // Configuration (cfg.c)
  56. #define TM_RM (0x1<<7) // RM APIs (rm.c)
  57. #define TM_UT (0x1<<8) // UTIL APIs (util.c)
  58. #define TM_BUF (0x1<<9) // Buffer management (buf.c)
  59. #define TM_FAKE (0x1<<10) // FAKE ndis and ip entrypoints (fake.c)
  60. #define TM_ARP (0x1<<11) // ARP request/response handling code (arp.c)
  61. #define TM_PKT (0x1<<12) // ARP control packet management (pkt.c)
  62. #define TM_MCAP (0x1<<13) // MCAP protocol (mcap.c)
  63. #define TM_ETH (0x1<<14) // Ethernet-emulation (eth.c)
  64. // Bytes to appear on each line of dump output.
  65. //
  66. #define DUMP_BytesPerLine 16
  67. //-----------------------------------------------------------------------------
  68. // Debug global declarations (defined in debug.c)
  69. //-----------------------------------------------------------------------------
  70. // Active debug trace level and active trace set mask. Set these variables
  71. // with the debugger at startup to enable and filter the debug output. All
  72. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' and from
  73. // any (TM_*) set(s) present in 'g_ulTraceMask' are displayed.
  74. //
  75. extern INT g_ulTraceLevel;
  76. extern ULONG g_ulTraceMask;
  77. extern INT g_SkipAll;
  78. extern INT g_DiscardNonUnicastPackets;
  79. //-----------------------------------------------------------------------------
  80. // Debug macros
  81. //-----------------------------------------------------------------------------
  82. #if DBG
  83. // TRACE sends printf style output to the kernel debugger. Caller indicates a
  84. // "verbosity" level with the 'ulLevel' argument and associates the trace with
  85. // one or more trace sets with the 'ulMask' bit mask argument. Notice that
  86. // the variable count printf arguments 'Args' must be parenthesized.
  87. //
  88. #define TRACE(ulLevel, Args) \
  89. { \
  90. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & TM_CURRENT)) \
  91. { \
  92. DbgPrint( "A13: %s:", dbg_func_name); \
  93. DbgPrint Args; \
  94. } \
  95. }
  96. // TRACE0 is like TRACE, except that it doesn't print the prefix.
  97. //
  98. #define TRACE0(ulLevel, Args) \
  99. { \
  100. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & TM_CURRENT)) \
  101. { \
  102. DbgPrint Args; \
  103. } \
  104. }
  105. #define TR_FATAL(Args) \
  106. TRACE(TL_FATAL, Args)
  107. #define TR_INFO(Args) \
  108. TRACE(TL_INFO, Args)
  109. #define TR_WARN(Args) \
  110. TRACE(TL_WARN, Args)
  111. #define TR_VERB(Args) \
  112. TRACE(TL_VERB, Args)
  113. #define ENTER(_Name, _locid) \
  114. char *dbg_func_name = (_Name); \
  115. UINT dbg_func_locid = (_locid);
  116. #define EXIT()
  117. // ASSERT checks caller's assertion expression and if false, prints a kernel
  118. // debugger message and breaks.
  119. //
  120. #undef ASSERT
  121. #define ASSERT(x) \
  122. { \
  123. if (!(x)) \
  124. { \
  125. DbgPrint( "A13: !ASSERT( %s ) L:%d,F:%s\n", \
  126. #x, __LINE__, __FILE__ ); \
  127. DbgBreakPoint(); \
  128. } \
  129. }
  130. #define ASSERTEX(x, ctxt) \
  131. { \
  132. if (!(x)) \
  133. { \
  134. DbgPrint( "A13: !ASSERT( %s ) C:0x%p L:%d,F:%s\n", \
  135. #x, (ctxt), __LINE__, __FILE__ ); \
  136. DbgBreakPoint(); \
  137. } \
  138. }
  139. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  140. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  141. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  142. // respectively. Note that the multi-byte dumps do not reflect little-endian
  143. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  144. //
  145. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  146. { \
  147. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  148. { \
  149. Dump( (CHAR* )p, cb, f, ul ); \
  150. } \
  151. }
  152. #define DUMPB(ulLevel,ulMask,p,cb) \
  153. { \
  154. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  155. { \
  156. Dump( (CHAR* )p, cb, 0, 1 ); \
  157. } \
  158. }
  159. #define DUMPW(ulLevel,ulMask,p,cb) \
  160. { \
  161. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  162. { \
  163. Dump( (CHAR* )p, cb, 0, 2 ); \
  164. } \
  165. }
  166. #define DUMPDW(ulLevel,ulMask,p,cb) \
  167. { \
  168. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  169. { \
  170. Dump( (CHAR* )p, cb, 0, 4 ); \
  171. } \
  172. }
  173. // DbgMark does nothing useful. But it is convenient to insert DBGMARK in
  174. // places in your code while debugging, and set a breakpoint on DbgMark, so that
  175. // the debugger will stop at the places you inserted DBGMARK. It's a bit more
  176. // flexible than inserting a hardcoded DbgBreakPoint.
  177. //
  178. void DbgMark(UINT Luid);
  179. #define DBGMARK(_Luid) DbgMark(_Luid)
  180. #define DBGSTMT(_stmt) _stmt
  181. #define RETAILASSERTEX ASSERTEX
  182. #define RETAILASSERT ASSERT
  183. #define ARP_INIT_REENTRANCY_COUNT() \
  184. static LONG ReentrancyCount=1;
  185. #define ARP_INC_REENTRANCY() \
  186. arpDbgIncrementReentrancy(&ReentrancyCount)
  187. #define ARP_DEC_REENTRANCY() \
  188. arpDbgDecrementReentrancy(&ReentrancyCount)
  189. #else // !DBG
  190. // Debug macros compile out of non-DBG builds.
  191. //
  192. #define TRACE(ulLevel,ulMask,Args)
  193. #define TR_FATAL(Args)
  194. #define TR_INFO(Args)
  195. #define TR_WARN(Args)
  196. #define TR_VERB(Args)
  197. #undef ASSERT
  198. #define ASSERT(x)
  199. #define ASSERTEX(x, ctxt)
  200. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  201. #define DUMPB(ulLevel,ulMask,p,cb)
  202. #define DUMPW(ulLevel,ulMask,p,cb)
  203. #define DUMPDW(ulLevel,ulMask,p,cb)
  204. #define ENTER(_Name, _locid)
  205. #define EXIT()
  206. #define DBGMARK(_Luid) (0)
  207. #define DBGSTMT(_stmt)
  208. #if 1
  209. #define ARP_INIT_REENTRANCY_COUNT()
  210. #define ARP_INC_REENTRANCY() 0
  211. #define ARP_DEC_REENTRANCY() 0
  212. #else // !0
  213. #define ARP_INIT_REENTRANCY_COUNT() \
  214. static LONG ReentrancyCount=1;
  215. #define ARP_INC_REENTRANCY() \
  216. arpDbgIncrementReentrancy(&ReentrancyCount)
  217. #define ARP_DEC_REENTRANCY() \
  218. arpDbgDecrementReentrancy(&ReentrancyCount)
  219. #endif // 0
  220. #define RETAILASSERT(x) \
  221. { \
  222. if (!(x)) \
  223. { \
  224. DbgPrint( "A13: !RETAILASSERT( %s ) L:%d,F:%s\n", \
  225. #x, __LINE__, __FILE__ ); \
  226. DbgBreakPoint(); \
  227. } \
  228. }
  229. #define RETAILASSERTEX(x, ctxt) \
  230. { \
  231. if (!(x)) \
  232. { \
  233. DbgPrint( "A13: !RETAILASSERT( %s ) C:0x%p L:%d,F:%s\n",\
  234. #x, (ctxt), __LINE__, __FILE__ ); \
  235. DbgBreakPoint(); \
  236. } \
  237. }
  238. #endif
  239. #if BINARY_COMPATIBLE
  240. #define ASSERT_PASSIVE() (0)
  241. #else // !BINARY_COMPATIBLE
  242. #define ASSERT_PASSIVE() \
  243. ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL)
  244. #endif // !BINARY_COMPATIBLE
  245. //-----------------------------------------------------------------------------
  246. // Prototypes
  247. //-----------------------------------------------------------------------------
  248. VOID
  249. CheckList(
  250. IN LIST_ENTRY* pList,
  251. IN BOOLEAN fShowLinks );
  252. VOID
  253. Dump(
  254. CHAR* p,
  255. ULONG cb,
  256. BOOLEAN fAddress,
  257. ULONG ulGroup );
  258. VOID
  259. DumpLine(
  260. CHAR* p,
  261. ULONG cb,
  262. BOOLEAN fAddress,
  263. ULONG ulGroup );