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.

331 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. DbgPrint ("\n"); \
  95. } \
  96. }
  97. // TRACE0 is like TRACE, except that it doesn't print the prefix.
  98. //
  99. #define TRACE0(ulLevel, Args) \
  100. { \
  101. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & TM_CURRENT)) \
  102. { \
  103. DbgPrint Args; \
  104. } \
  105. }
  106. #define TR_FATAL(Args) \
  107. TRACE(TL_FATAL, Args)
  108. #define TR_INFO(Args) \
  109. TRACE(TL_INFO, Args)
  110. #define TR_WARN(Args) \
  111. TRACE(TL_WARN, Args)
  112. #define TR_VERB(Args) \
  113. TRACE(TL_VERB, Args)
  114. #define ENTER(_Name, _locid) \
  115. char *dbg_func_name = (_Name); \
  116. UINT dbg_func_locid = (_locid);
  117. #define EXIT()
  118. // ASSERT checks caller's assertion expression and if false, prints a kernel
  119. // debugger message and breaks.
  120. //
  121. #undef ASSERT
  122. #define ASSERT(x) \
  123. { \
  124. if (!(x)) \
  125. { \
  126. DbgPrint( "A13: !ASSERT( %s ) L:%d,F:%s\n", \
  127. #x, __LINE__, __FILE__ ); \
  128. DbgBreakPoint(); \
  129. } \
  130. }
  131. #define ASSERTEX(x, ctxt) \
  132. { \
  133. if (!(x)) \
  134. { \
  135. DbgPrint( "A13: !ASSERT( %s ) C:0x%p L:%d,F:%s\n", \
  136. #x, (ctxt), __LINE__, __FILE__ ); \
  137. DbgBreakPoint(); \
  138. } \
  139. }
  140. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  141. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  142. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  143. // respectively. Note that the multi-byte dumps do not reflect little-endian
  144. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  145. //
  146. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  147. { \
  148. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  149. { \
  150. Dump( (CHAR* )p, cb, f, ul ); \
  151. } \
  152. }
  153. #define DUMPB(ulLevel,ulMask,p,cb) \
  154. { \
  155. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  156. { \
  157. Dump( (CHAR* )p, cb, 0, 1 ); \
  158. } \
  159. }
  160. #define DUMPW(ulLevel,ulMask,p,cb) \
  161. { \
  162. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  163. { \
  164. Dump( (CHAR* )p, cb, 0, 2 ); \
  165. } \
  166. }
  167. #define DUMPDW(ulLevel,ulMask,p,cb) \
  168. { \
  169. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  170. { \
  171. Dump( (CHAR* )p, cb, 0, 4 ); \
  172. } \
  173. }
  174. // DbgMark does nothing useful. But it is convenient to insert DBGMARK in
  175. // places in your code while debugging, and set a breakpoint on DbgMark, so that
  176. // the debugger will stop at the places you inserted DBGMARK. It's a bit more
  177. // flexible than inserting a hardcoded DbgBreakPoint.
  178. //
  179. void DbgMark(UINT Luid);
  180. #define DBGMARK(_Luid) DbgMark(_Luid)
  181. #define DBGSTMT(_stmt) _stmt
  182. #define RETAILASSERTEX ASSERTEX
  183. #define RETAILASSERT ASSERT
  184. #define ARP_INIT_REENTRANCY_COUNT() \
  185. static LONG ReentrancyCount=1;
  186. #define ARP_INC_REENTRANCY() \
  187. arpDbgIncrementReentrancy(&ReentrancyCount)
  188. #define ARP_DEC_REENTRANCY() \
  189. arpDbgDecrementReentrancy(&ReentrancyCount)
  190. #else // !DBG
  191. // Debug macros compile out of non-DBG builds.
  192. //
  193. #define TRACE(ulLevel,ulMask,Args)
  194. #define TR_FATAL(Args)
  195. #define TR_INFO(Args)
  196. #define TR_WARN(Args)
  197. #define TR_VERB(Args)
  198. #undef ASSERT
  199. #define ASSERT(x)
  200. #define ASSERTEX(x, ctxt)
  201. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  202. #define DUMPB(ulLevel,ulMask,p,cb)
  203. #define DUMPW(ulLevel,ulMask,p,cb)
  204. #define DUMPDW(ulLevel,ulMask,p,cb)
  205. #define ENTER(_Name, _locid)
  206. #define EXIT()
  207. #define DBGMARK(_Luid) (0)
  208. #define DBGSTMT(_stmt)
  209. #if 1
  210. #define ARP_INIT_REENTRANCY_COUNT()
  211. #define ARP_INC_REENTRANCY() 0
  212. #define ARP_DEC_REENTRANCY() 0
  213. #else // !0
  214. #define ARP_INIT_REENTRANCY_COUNT() \
  215. static LONG ReentrancyCount=1;
  216. #define ARP_INC_REENTRANCY() \
  217. arpDbgIncrementReentrancy(&ReentrancyCount)
  218. #define ARP_DEC_REENTRANCY() \
  219. arpDbgDecrementReentrancy(&ReentrancyCount)
  220. #endif // 0
  221. #define RETAILASSERT(x) \
  222. { \
  223. if (!(x)) \
  224. { \
  225. DbgPrint( "A13: !RETAILASSERT( %s ) L:%d,F:%s\n", \
  226. #x, __LINE__, __FILE__ ); \
  227. DbgBreakPoint(); \
  228. } \
  229. }
  230. #define RETAILASSERTEX(x, ctxt) \
  231. { \
  232. if (!(x)) \
  233. { \
  234. DbgPrint( "A13: !RETAILASSERT( %s ) C:0x%p L:%d,F:%s\n",\
  235. #x, (ctxt), __LINE__, __FILE__ ); \
  236. DbgBreakPoint(); \
  237. } \
  238. }
  239. #endif
  240. #if BINARY_COMPATIBLE
  241. #define ASSERT_PASSIVE() (0)
  242. #else // !BINARY_COMPATIBLE
  243. #define ASSERT_PASSIVE() \
  244. ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL)
  245. #endif // !BINARY_COMPATIBLE
  246. //-----------------------------------------------------------------------------
  247. // Prototypes
  248. //-----------------------------------------------------------------------------
  249. VOID
  250. CheckList(
  251. IN LIST_ENTRY* pList,
  252. IN BOOLEAN fShowLinks );
  253. VOID
  254. Dump(
  255. CHAR* p,
  256. ULONG cb,
  257. BOOLEAN fAddress,
  258. ULONG ulGroup );
  259. VOID
  260. DumpLine(
  261. CHAR* p,
  262. ULONG cb,
  263. BOOLEAN fAddress,
  264. ULONG ulGroup );