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
8.1 KiB

  1. // Copyright (c) 2000-2001, Microsoft Corporation, all rights reserved
  2. //
  3. // debug.h
  4. // ATM - Ethernet Encapsulation Intermediate Driver
  5. // Debug helper header
  6. //
  7. // 03/23/2000 Adube Created.
  8. #ifndef _DEBUG_H_
  9. #define _DEBUG_H_
  10. //-----------------------------------------------------------------------------
  11. // Debug constants
  12. //-----------------------------------------------------------------------------
  13. #define MODULE_DRIVER 1
  14. #define MODULE_MINIPORT 2
  15. #define MODULE_PROTOCOL 3
  16. //
  17. // These are the tags used in the allocation routines
  18. // so that the memory dumps will identify what structure
  19. // follows the tag.
  20. //
  21. //
  22. #define TAG_FREED 'FvpE'
  23. #define TAG_PROTOCOL 'PvpE'
  24. #define TAG_ADAPTER 'AvpE'
  25. #define TAG_TASK 'TvpE'
  26. #define TAG_MINIPORT 'MvpE'
  27. #define TAG_DEFAULT 'ZvpE'
  28. #define TAG_WORKITEM 'WvpE'
  29. #define TAG_RCV 'RvpE'
  30. //
  31. // Trace Modules used in debugging.
  32. // Each module has its own number.
  33. //
  34. #define TM_Dr 0x1 // Driver Entry
  35. #define TM_Mp 0x2 // Miniport
  36. #define TM_Pt 0x4 // Protocol
  37. #define TM_Cl 0x20 // Client
  38. #define TM_Rq 0x40 // Requests
  39. #define TM_Send 0x200 // Sends
  40. #define TM_Recv 0x100 // Receive
  41. #define TM_RM 0x400 // Resource Manager
  42. //
  43. // Trace levels.
  44. //
  45. #define TL_None 0 // Trace disabled
  46. #define TL_A 0x10 // Alert
  47. #define TL_I 0x18 // Interface (highest level workable for general use)
  48. #define TL_N 0x20 // Normal
  49. #define TL_T 0x25 // Displays Entry and Exit points of all functions
  50. #define TL_V 0x30 // Verbose
  51. #define TL_D 0x40 // Dump packets
  52. // Trace mask bits.
  53. //
  54. #define TM_Wild 0xFFFFFFFF // Everything
  55. #define TM_All 0x7FFFFFFF // Everything except corruption checks
  56. #define TM_Base 0x000000FF // Base only
  57. #define TM_NoRM (TM_Base & (~(TM_RM|TM_Rq)))
  58. // Bytes to appear on each line of dump output.
  59. //
  60. #define DUMP_BytesPerLine 16
  61. //-----------------------------------------------------------------------------
  62. // Debug global declarations (defined in debug.c)
  63. //-----------------------------------------------------------------------------
  64. // Active debug trace level and active trace set mask. Set these variables
  65. // with the debugger at startup to enable and filter the debug output. All
  66. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' and from
  67. // any (TM_*) set(s) present in 'g_ulTraceMask' are displayed.
  68. //
  69. extern ULONG g_ulTraceLevel;
  70. extern ULONG g_ulTraceMask;
  71. //-----------------------------------------------------------------------------
  72. // Debug macros
  73. //-----------------------------------------------------------------------------
  74. #if DBG
  75. // TRACE sends printf style output to the kernel debugger. Caller indicates a
  76. // "verbosity" level with the 'ulLevel' argument and associates the trace with
  77. // one or more trace sets with the 'ulMask' bit mask argument. Notice that
  78. // the variable count printf arguments 'Args' must be parenthesized. For
  79. // example...
  80. //
  81. // A "leave" routine message:
  82. // TRACE( TL_N, TM_Init, ( "DriverEntry=$%x", status ) );
  83. // An error condition occurred:
  84. // TRACE( TL_E, TM_Init, ( "NdisMRegisterMiniport=$%x", status ) );
  85. //
  86. //
  87. #define TRACE( ulLevel, ulMask, Args) \
  88. { \
  89. if ((ulLevel <= g_ulTraceLevel) && ((g_ulTraceMask & ulMask) )) \
  90. { \
  91. DbgPrint Args; \
  92. DbgPrint( "\n" ); \
  93. } \
  94. }
  95. // ASSERT checks caller's assertion expression and if false, prints a kernel
  96. // debugger message and breaks.
  97. //
  98. #undef ASSERT
  99. #define ASSERT(x) \
  100. { \
  101. if (!(x)) \
  102. { \
  103. DbgPrint( "EPVC: !ASSERT( %s ) at line %d of %s\n", \
  104. #x, __LINE__, __FILE__ ); \
  105. DbgBreakPoint(); \
  106. } \
  107. }
  108. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  109. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  110. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  111. // respectively. Note that the multi-byte dumps do not reflect little-endian
  112. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  113. //
  114. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  115. { \
  116. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  117. { \
  118. Dump( (CHAR* )p, cb, f, ul ); \
  119. } \
  120. }
  121. #define DUMPB(ulLevel,ulMask,p,cb) \
  122. { \
  123. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  124. { \
  125. Dump( (CHAR* )p, cb, 0, 1 ); \
  126. } \
  127. }
  128. #define DUMPW(ulLevel,ulMask,p,cb) \
  129. { \
  130. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  131. { \
  132. Dump( (CHAR* )p, cb, 0, 2 ); \
  133. } \
  134. }
  135. #define DUMPDW(ulLevel,ulMask,p,cb) \
  136. { \
  137. if (ulLevel == g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  138. { \
  139. Dump( (CHAR* )p, cb, 0, 4 ); \
  140. } \
  141. }
  142. // Double-linked list corruption detector. Runs the test if 'ulMask' is
  143. // enabled, with TM_Dbg a suggested setting. Shows verbose output if
  144. // 'ulLevel' is at or above the current trace threshold.
  145. //
  146. #define CHECKLIST(ulMask,p,ulLevel) \
  147. { \
  148. if (g_ulTraceMask & ulMask) \
  149. { \
  150. CheckList( p, (BOOLEAN )(ulLevel <= g_ulTraceLevel) ); \
  151. } \
  152. }
  153. // DBG_if can be used to put in TRACE/DUMPs conditional on an expression that
  154. // need not be evaluated in non-DBG builds, e.g the statements below generate
  155. // no code in a non-DBG build, but in DBG builds print the TRACE if x<y and
  156. // asserts otherwise.
  157. //
  158. // DBG_if (x < y)
  159. // TRACE( TL_N, TM_Misc, ( "x < y" ) );
  160. // DBG_else
  161. // ASSERT( FALSE );
  162. //
  163. //
  164. #define DBG_if(x) if (x)
  165. #define DBG_else else
  166. extern ULONG g_ulTraceLevel;
  167. extern ULONG g_ulTraceMask;
  168. #if TESTMODE
  169. #define epvcBreakPoint() DbgBreakPoint();
  170. #else
  171. #define epvcBreakPoint()
  172. #endif
  173. #else // !DBG
  174. // Debug macros compile out of non-DBG builds.
  175. //
  176. #define TRACE(ulLevel,ulMask,Args)
  177. #undef ASSERT
  178. #define ASSERT(x)
  179. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  180. #define DUMPB(ulLevel,ulMask,p,cb)
  181. #define DUMPW(ulLevel,ulMask,p,cb)
  182. #define DUMPDW(ulLevel,ulMask,p,cb)
  183. #define CHECKLIST(ulMask,p,ulLevel)
  184. #define DBG_if(x)
  185. #define DBG_else
  186. #define epvcBreakPoint()
  187. #endif
  188. //-----------------------------------------------------------------------------
  189. // Prototypes
  190. //-----------------------------------------------------------------------------
  191. VOID
  192. CheckList(
  193. IN LIST_ENTRY* pList,
  194. IN BOOLEAN fShowLinks );
  195. VOID
  196. Dump(
  197. CHAR* p,
  198. ULONG cb,
  199. BOOLEAN fAddress,
  200. ULONG ulGroup );
  201. VOID
  202. DumpLine(
  203. CHAR* p,
  204. ULONG cb,
  205. BOOLEAN fAddress,
  206. ULONG ulGroup );
  207. #endif // _DEBUG_H_