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.

255 lines
9.1 KiB

  1. // Copyright (c) 1998-1999, Microsoft Corporation, all rights reserved
  2. //
  3. // debug.h
  4. // IEEE1394 mini-port/call-manager driver
  5. // Debug helper header
  6. //
  7. // 12/27/1998 JosephJ adapted from the l2tp project.
  8. #ifndef _DEBUG_H_
  9. #define _DEBUG_H_
  10. //-----------------------------------------------------------------------------
  11. // Debug constants
  12. //-----------------------------------------------------------------------------
  13. // Memory tags used with NdisAllocateMemoryWithTag to identify allocations
  14. // made by the 1394 nic driver. Also, several context blocks define a first field
  15. // of 'ulTag' set to these values for ASSERT sanity checking and eased memory
  16. // dump browsing. Such tags are set to MTAG_FREED just before NdisFreeMemory
  17. // is called. Form: N13a, N13b, etc.
  18. //
  19. #define MTAG_FREED 'a31N'
  20. #define MTAG_ADAPTERCB 'b31N'
  21. #define MTAG_AFCB 'c31N'
  22. #define MTAG_VCCB 'd31N'
  23. #define MTAG_WORKITEM 'e31N'
  24. #define MTAG_TIMERQ 'f31N'
  25. #define MTAG_TIMERQITEM 'g31N'
  26. #define MTAG_PACKETPOOL 'h31N'
  27. #define MTAG_FBUFPOOL 'i31N'
  28. #define MTAG_HBUFPOOL 'j31N'
  29. #define MTAG_INCALL 'k31N'
  30. #define MTAG_UTIL 'l31N'
  31. #define MTAG_RBUF 'r31N' // Used in Receive Buffer
  32. #define MTAG_REMOTE_NODE 'p31N'
  33. #define MTAG_CBUF 'n31N' // Used in send buffer
  34. #define MTAG_DEFAULT 'z31N'
  35. #define MTAG_FRAG 'x31N'
  36. #define MTAG_REASSEMBLY 's31N'
  37. #define MTAG_PKTLOG 'y31N'
  38. #define MTAG_FIFO 'w31N'
  39. // Trace levels.
  40. //
  41. #define TL_None 0 // Trace disabled
  42. #define TL_A 0x10 // Alert
  43. #define TL_I 0x18 // Interface (highest level workable for general use)
  44. #define TL_N 0x20 // Normal
  45. #define TL_T 0x25 // Displays Entry and Exit points of all functions
  46. #define TL_V 0x30 // Verbose
  47. #define TL_D 0x40 // Dump packets
  48. // Trace mask bits.
  49. //
  50. #define TM_Cm 0x00000001 // Call manager general
  51. #define TM_Mp 0x00000002 // Mini-port general
  52. #define TM_Send 0x00000004 // Send path
  53. #define TM_Recv 0x00000008 // Receive path
  54. #define TM_Init 0x00000020 // Initialization
  55. #define TM_Misc 0x00000040 // Miscellaneous
  56. #define TM_Bcm 0x00000080 // BCM Algorithm
  57. #define TM_Pkt 0x00000100 // Dump packets
  58. #define TM_Reas 0x00000200 // Reassembly
  59. #define TM_Irp 0x00000400 // Irp Handling and Bus Interface routines
  60. #define TM_Ref 0x00010000 // References
  61. #define TM_Time 0x00020000 // Timer queue
  62. #define TM_Pool 0x00080000 // Buffer and packet pooling
  63. #define TM_Stat 0x00100000 // Call statistics
  64. #define TM_RemRef 0x00200000 // Remote Node Refs
  65. #define TM_Spec 0x01000000 // Special purpose temporary traces
  66. #define TM_Lock 0x02000000 // Lock Acquure / Release
  67. #define TM_Dbg 0x80000000 // Debug corruption checks
  68. #define TM_Wild 0xFFFFFFFF // Everything
  69. #define TM_All 0x7FFFFFFF // Everything except corruption checks
  70. #define TM_Base 0x000000FF // Base only
  71. // Bytes to appear on each line of dump output.
  72. //
  73. #define DUMP_BytesPerLine 16
  74. //-----------------------------------------------------------------------------
  75. // Debug global declarations (defined in debug.c)
  76. //-----------------------------------------------------------------------------
  77. // Active debug trace level and active trace set mask. Set these variables
  78. // with the debugger at startup to enable and filter the debug output. All
  79. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' and from
  80. // any (TM_*) set(s) present in 'g_ulTraceMask' are displayed.
  81. //
  82. extern ULONG g_ulTraceLevel;
  83. extern ULONG g_ulTraceMask;
  84. //-----------------------------------------------------------------------------
  85. // Debug macros
  86. //-----------------------------------------------------------------------------
  87. #if DBG
  88. // TRACE sends printf style output to the kernel debugger. Caller indicates a
  89. // "verbosity" level with the 'ulLevel' argument and associates the trace with
  90. // one or more trace sets with the 'ulMask' bit mask argument. Notice that
  91. // the variable count printf arguments 'Args' must be parenthesized. For
  92. // example...
  93. //
  94. // A "leave" routine message:
  95. // TRACE( TL_N, TM_Init, ( "DriverEntry=$%x", status ) );
  96. // An error condition occurred:
  97. // TRACE( TL_E, TM_Init, ( "NdisMRegisterMiniport=$%x", status ) );
  98. //
  99. //
  100. #define TRACE(ulLevel,ulMask,Args) \
  101. { \
  102. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  103. { \
  104. DbgPrint Args; \
  105. DbgPrint( "\n" ); \
  106. } \
  107. }
  108. // ASSERT checks caller's assertion expression and if false, prints a kernel
  109. // debugger message and breaks.
  110. //
  111. #undef ASSERT
  112. #define ASSERT(x) \
  113. { \
  114. if (!(x)) \
  115. { \
  116. DbgPrint( "N13: !ASSERT( %s ) at line %d of %s\n", \
  117. #x, __LINE__, __FILE__ ); \
  118. DbgBreakPoint(); \
  119. } \
  120. }
  121. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  122. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  123. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  124. // respectively. Note that the multi-byte dumps do not reflect little-endian
  125. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  126. //
  127. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  128. { \
  129. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  130. { \
  131. Dump( (CHAR* )p, cb, f, ul ); \
  132. } \
  133. }
  134. #define DUMPB(ulLevel,ulMask,p,cb) \
  135. { \
  136. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  137. { \
  138. Dump( (CHAR* )p, cb, 0, 1 ); \
  139. } \
  140. }
  141. #define DUMPW(ulLevel,ulMask,p,cb) \
  142. { \
  143. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  144. { \
  145. Dump( (CHAR* )p, cb, 0, 2 ); \
  146. } \
  147. }
  148. #define DUMPDW(ulLevel,ulMask,p,cb) \
  149. { \
  150. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  151. { \
  152. Dump( (CHAR* )p, cb, 0, 4 ); \
  153. } \
  154. }
  155. // Double-linked list corruption detector. Runs the test if 'ulMask' is
  156. // enabled, with TM_Dbg a suggested setting. Shows verbose output if
  157. // 'ulLevel' is at or above the current trace threshold.
  158. //
  159. #define CHECKLIST(ulMask,p,ulLevel) \
  160. { \
  161. if (g_ulTraceMask & ulMask) \
  162. { \
  163. CheckList( p, (BOOLEAN )(ulLevel <= g_ulTraceLevel) ); \
  164. } \
  165. }
  166. // DBG_if can be used to put in TRACE/DUMPs conditional on an expression that
  167. // need not be evaluated in non-DBG builds, e.g the statements below generate
  168. // no code in a non-DBG build, but in DBG builds print the TRACE if x<y and
  169. // asserts otherwise.
  170. //
  171. // DBG_if (x < y)
  172. // TRACE( TL_N, TM_Misc, ( "x < y" ) );
  173. // DBG_else
  174. // ASSERT( FALSE );
  175. //
  176. //
  177. #define DBG_if(x) if (x)
  178. #define DBG_else else
  179. #else // !DBG
  180. // Debug macros compile out of non-DBG builds.
  181. //
  182. #define TRACE(ulLevel,ulMask,Args)
  183. #undef ASSERT
  184. #define ASSERT(x)
  185. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  186. #define DUMPB(ulLevel,ulMask,p,cb)
  187. #define DUMPW(ulLevel,ulMask,p,cb)
  188. #define DUMPDW(ulLevel,ulMask,p,cb)
  189. #define CHECKLIST(ulMask,p,ulLevel)
  190. #define DBG_if(x)
  191. #define DBG_else
  192. #endif
  193. //-----------------------------------------------------------------------------
  194. // Prototypes
  195. //-----------------------------------------------------------------------------
  196. VOID
  197. CheckList(
  198. IN LIST_ENTRY* pList,
  199. IN BOOLEAN fShowLinks );
  200. #if DBG
  201. VOID
  202. Dump(
  203. CHAR* p,
  204. ULONG cb,
  205. BOOLEAN fAddress,
  206. ULONG ulGroup );
  207. #else
  208. #define Dump(p,cb,fAddress,ulGroup)
  209. #endif
  210. VOID
  211. DumpLine(
  212. CHAR* p,
  213. ULONG cb,
  214. BOOLEAN fAddress,
  215. ULONG ulGroup );
  216. #endif // _DEBUG_H_