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) 1997, Microsoft Corporation, all rights reserved
  2. //
  3. // debug.h
  4. // RAS L2TP WAN mini-port/call-manager driver
  5. // Debug helper header
  6. //
  7. // 01/07/97 Steve Cobb
  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 L2TP 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.
  18. //
  19. #define MTAG_FREED '0T2L'
  20. #define MTAG_ADAPTERCB '1T2L'
  21. #define MTAG_TUNNELCB '2T2L'
  22. #define MTAG_VCCB '3T2L'
  23. #define MTAG_VCTABLE '4T2L'
  24. #define MTAG_WORKITEM '5T2L'
  25. #define MTAG_TIMERQ '6T2L'
  26. #define MTAG_TIMERQITEM '7T2L'
  27. #define MTAG_PACKETPOOL '8T2L'
  28. #define MTAG_FBUFPOOL '9T2L'
  29. #define MTAG_HBUFPOOL 'aT2L'
  30. #define MTAG_TDIXRDG 'bT2L'
  31. #define MTAG_TDIXSDG 'cT2L'
  32. #define MTAG_CTRLRECD 'dT2L'
  33. #define MTAG_CTRLSENT 'eT2L'
  34. #define MTAG_PAYLRECD 'fT2L'
  35. #define MTAG_PAYLSENT 'gT2L'
  36. #define MTAG_INCALL 'hT2L'
  37. #define MTAG_UTIL 'iT2L'
  38. #define MTAG_ROUTEQUERY 'jT2L'
  39. #define MTAG_ROUTESET 'kT2L'
  40. #define MTAG_L2TPPARAMS 'lT2L'
  41. #define MTAG_TUNNELWORK 'mT2L'
  42. #define MTAG_TDIXROUTE 'nT2L'
  43. #define MTAG_CTRLMSGINFO 'oT2L'
  44. // Trace levels.
  45. //
  46. #define TL_None 0 // Trace disabled
  47. #define TL_A 0x10 // Alert
  48. #define TL_I 0x18 // Interface (highest level workable for general use)
  49. #define TL_N 0x20 // Normal
  50. #define TL_V 0x30 // Verbose
  51. // Trace mask bits.
  52. //
  53. #define TM_Cm 0x00000001 // Call manager general
  54. #define TM_Mp 0x00000002 // Mini-port general
  55. #define TM_Send 0x00000004 // Send path
  56. #define TM_Recv 0x00000008 // Receive path
  57. #define TM_Fsm 0x00000010 // Finite state machines
  58. #define TM_Init 0x00000020 // Initialization
  59. #define TM_Misc 0x00000040 // Miscellaneous
  60. #define TM_CMsg 0x00000100 // Control messages and received AVPs
  61. #define TM_Msg 0x00000200 // Verbose message, address, Ns/Nr, payload
  62. #define TM_TWrk 0x00001000 // Tunnel work APC queuing
  63. #define TM_Ref 0x00010000 // References
  64. #define TM_Time 0x00020000 // Timer queue
  65. #define TM_Tdi 0x00040000 // TDI and extensions
  66. #define TM_Pool 0x00080000 // Buffer and packet pooling
  67. #define TM_Stat 0x00100000 // Call statistics
  68. #define TM_Spec 0x01000000 // Special purpose temporary traces
  69. #define TM_MDmp 0x10000000 // Message dumps
  70. #define TM_Dbg 0x80000000 // Debug corruption checks
  71. #define TM_Wild 0xFFFFFFFF // Everything
  72. #define TM_All 0x7FFFFFFF // Everything except corruption checks
  73. #define TM_BTWrk 0x00000FFF // Base with messages and tunnel work
  74. #define TM_BCMsg 0x000001FF // Base with control messages
  75. #define TM_XCMsg 0x001401FF // Base with control messages extended
  76. #define TM_Base 0x000000FF // Base only
  77. // Bytes to appear on each line of dump output.
  78. //
  79. #define DUMP_BytesPerLine 16
  80. //-----------------------------------------------------------------------------
  81. // Debug global declarations (defined in debug.c)
  82. //-----------------------------------------------------------------------------
  83. // Active debug trace level and active trace set mask. Set these variables
  84. // with the debugger at startup to enable and filter the debug output. All
  85. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' and from
  86. // any (TM_*) set(s) present in 'g_ulTraceMask' are displayed.
  87. //
  88. extern ULONG g_ulTraceLevel;
  89. extern ULONG g_ulTraceMask;
  90. //-----------------------------------------------------------------------------
  91. // Debug macros
  92. //-----------------------------------------------------------------------------
  93. #if DBG
  94. // TRACE sends printf style output to the kernel debugger. Caller indicates a
  95. // "verbosity" level with the 'ulLevel' argument and associates the trace with
  96. // one or more trace sets with the 'ulMask' bit mask argument. Notice that
  97. // the variable count printf arguments 'Args' must be parenthesized. For
  98. // example...
  99. //
  100. // A "leave" routine message:
  101. // TRACE( TL_N, TM_Init, ( "DriverEntry=$%x", status ) );
  102. // An error condition occurred:
  103. // TRACE( TL_E, TM_Init, ( "NdisMRegisterMiniport=$%x", status ) );
  104. //
  105. //
  106. #define TRACE(ulLevel,ulMask,Args) \
  107. { \
  108. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  109. { \
  110. DbgPrint( "L2TP: " ); \
  111. DbgPrint Args; \
  112. DbgPrint( "\n" ); \
  113. } \
  114. }
  115. // ASSERT checks caller's assertion expression and if false, prints a kernel
  116. // debugger message and breaks.
  117. //
  118. #undef ASSERT
  119. #define ASSERT(x) \
  120. { \
  121. if (!(x)) \
  122. { \
  123. DbgPrint( "L2TP: !ASSERT( %s ) at line %d of %s\n", \
  124. #x, __LINE__, __FILE__ ); \
  125. DbgBreakPoint(); \
  126. } \
  127. }
  128. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  129. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  130. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  131. // respectively. Note that the multi-byte dumps do not reflect little-endian
  132. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  133. //
  134. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  135. { \
  136. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  137. { \
  138. Dump( (CHAR* )p, cb, f, ul ); \
  139. } \
  140. }
  141. #define DUMPB(ulLevel,ulMask,p,cb) \
  142. { \
  143. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  144. { \
  145. Dump( (CHAR* )p, cb, 0, 1 ); \
  146. } \
  147. }
  148. #define DUMPW(ulLevel,ulMask,p,cb) \
  149. { \
  150. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  151. { \
  152. Dump( (CHAR* )p, cb, 0, 2 ); \
  153. } \
  154. }
  155. #define DUMPDW(ulLevel,ulMask,p,cb) \
  156. { \
  157. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  158. { \
  159. Dump( (CHAR* )p, cb, 0, 4 ); \
  160. } \
  161. }
  162. // Double-linked list corruption detector. Runs the test if 'ulMask' is
  163. // enabled, with TM_Dbg a suggested setting. Shows verbose output if
  164. // 'ulLevel' is at or above the current trace threshold.
  165. //
  166. #define CHECKLIST(ulMask,p,ulLevel) \
  167. { \
  168. if (g_ulTraceMask & ulMask) \
  169. { \
  170. CheckList( p, (BOOLEAN )(ulLevel <= g_ulTraceLevel) ); \
  171. } \
  172. }
  173. // DBG_if can be used to put in TRACE/DUMPs conditional on an expression that
  174. // need not be evaluated in non-DBG builds, e.g the statements below generate
  175. // no code in a non-DBG build, but in DBG builds print the TRACE if x<y and
  176. // asserts otherwise.
  177. //
  178. // DBG_if (x < y)
  179. // TRACE( TL_N, TM_Misc, ( "x < y" ) );
  180. // DBG_else
  181. // ASSERT( FALSE );
  182. //
  183. //
  184. #define DBG_if(x) if (x)
  185. #define DBG_else else
  186. #else // !DBG
  187. // Debug macros compile out of non-DBG builds.
  188. //
  189. #define TRACE(ulLevel,ulMask,Args)
  190. #undef ASSERT
  191. #define ASSERT(x)
  192. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  193. #define DUMPB(ulLevel,ulMask,p,cb)
  194. #define DUMPW(ulLevel,ulMask,p,cb)
  195. #define DUMPDW(ulLevel,ulMask,p,cb)
  196. #define CHECKLIST(ulMask,p,ulLevel)
  197. #define DBG_if(x)
  198. #define DBG_else
  199. #endif
  200. //-----------------------------------------------------------------------------
  201. // Prototypes
  202. //-----------------------------------------------------------------------------
  203. VOID
  204. CheckList(
  205. IN LIST_ENTRY* pList,
  206. IN BOOLEAN fShowLinks );
  207. VOID
  208. Dump(
  209. CHAR* p,
  210. ULONG cb,
  211. BOOLEAN fAddress,
  212. ULONG ulGroup );
  213. VOID
  214. DumpLine(
  215. CHAR* p,
  216. ULONG cb,
  217. BOOLEAN fAddress,
  218. ULONG ulGroup );
  219. #endif // _DEBUG_H_