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.

282 lines
10 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_Res 0x00000040 // Resources such as memory allocs/frees
  60. #define TM_Misc 0x00000080 // Miscellaneous
  61. #define TM_CMsg 0x00000100 // Control messages and received AVPs
  62. #define TM_Msg 0x00000200 // Verbose message, address, Ns/Nr, payload
  63. #define TM_TWrk 0x00001000 // Tunnel work APC queuing
  64. #define TM_Ref 0x00010000 // References
  65. #define TM_Time 0x00020000 // Timer queue
  66. #define TM_Tdi 0x00040000 // TDI and extensions
  67. #define TM_Pool 0x00080000 // Buffer and packet pooling
  68. #define TM_Stat 0x00100000 // Call statistics
  69. #define TM_Spec 0x01000000 // Special purpose temporary traces
  70. #define TM_MDmp 0x10000000 // Message dumps
  71. #define TM_Dbg 0x80000000 // Debug corruption checks
  72. #define TM_Wild 0xFFFFFFFF // Everything
  73. #define TM_All 0x7FFFFFFF // Everything except corruption checks
  74. #define TM_BTWrk 0x00000FFF // Base with messages and tunnel work
  75. #define TM_BCMsg 0x000001FF // Base with control messages
  76. #define TM_XCMsg 0x001401FF // Base with control messages extended
  77. #define TM_Base 0x000000FF // Base only
  78. // Bytes to appear on each line of dump output.
  79. //
  80. #define DUMP_BytesPerLine 16
  81. //-----------------------------------------------------------------------------
  82. // Debug global declarations (defined in debug.c)
  83. //-----------------------------------------------------------------------------
  84. // Active debug trace level and active trace set mask. Set these variables
  85. // with the debugger at startup to enable and filter the debug output. All
  86. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' and from
  87. // any (TM_*) set(s) present in 'g_ulTraceMask' are displayed.
  88. //
  89. extern ULONG g_ulTraceLevel;
  90. extern ULONG g_ulTraceMask;
  91. //-----------------------------------------------------------------------------
  92. // Debug macros
  93. //-----------------------------------------------------------------------------
  94. #if DBG
  95. // TRACE sends printf style output to the kernel debugger. Caller indicates a
  96. // "verbosity" level with the 'ulLevel' argument and associates the trace with
  97. // one or more trace sets with the 'ulMask' bit mask argument. Notice that
  98. // the variable count printf arguments 'Args' must be parenthesized. For
  99. // example...
  100. //
  101. // A "leave" routine message:
  102. // TRACE( TL_N, TM_Init, ( "DriverEntry=$%x", status ) );
  103. // An error condition occurred:
  104. // TRACE( TL_E, TM_Init, ( "NdisMRegisterMiniport=$%x", status ) );
  105. //
  106. //
  107. #define TRACE(ulLevel,ulMask,Args) \
  108. { \
  109. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  110. { \
  111. DbgPrint( "L2TP: " ); \
  112. DbgPrint Args; \
  113. DbgPrint( "\n" ); \
  114. } \
  115. }
  116. // ASSERT checks caller's assertion expression and if false, prints a kernel
  117. // debugger message and breaks.
  118. //
  119. #undef ASSERT
  120. #define ASSERT(x) \
  121. { \
  122. if (!(x)) \
  123. { \
  124. DbgPrint( "L2TP: !ASSERT( %s ) at line %d of %s\n", \
  125. #x, __LINE__, __FILE__ ); \
  126. DbgBreakPoint(); \
  127. } \
  128. }
  129. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  130. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  131. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  132. // respectively. Note that the multi-byte dumps do not reflect little-endian
  133. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  134. //
  135. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  136. { \
  137. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  138. { \
  139. Dump( (CHAR* )p, cb, f, ul ); \
  140. } \
  141. }
  142. #define DUMPB(ulLevel,ulMask,p,cb) \
  143. { \
  144. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  145. { \
  146. Dump( (CHAR* )p, cb, 0, 1 ); \
  147. } \
  148. }
  149. #define DUMPW(ulLevel,ulMask,p,cb) \
  150. { \
  151. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  152. { \
  153. Dump( (CHAR* )p, cb, 0, 2 ); \
  154. } \
  155. }
  156. #define DUMPDW(ulLevel,ulMask,p,cb) \
  157. { \
  158. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  159. { \
  160. Dump( (CHAR* )p, cb, 0, 4 ); \
  161. } \
  162. }
  163. // Double-linked list corruption detector. Runs the test if 'ulMask' is
  164. // enabled, with TM_Dbg a suggested setting. Shows verbose output if
  165. // 'ulLevel' is at or above the current trace threshold.
  166. //
  167. #define CHECKLIST(ulMask,p,ulLevel) \
  168. { \
  169. if (g_ulTraceMask & ulMask) \
  170. { \
  171. CheckList( p, (BOOLEAN )(ulLevel <= g_ulTraceLevel) ); \
  172. } \
  173. }
  174. // DBG_if can be used to put in TRACE/DUMPs conditional on an expression that
  175. // need not be evaluated in non-DBG builds, e.g the statements below generate
  176. // no code in a non-DBG build, but in DBG builds print the TRACE if x<y and
  177. // asserts otherwise.
  178. //
  179. // DBG_if (x < y)
  180. // TRACE( TL_N, TM_Misc, ( "x < y" ) );
  181. // DBG_else
  182. // ASSERT( FALSE );
  183. //
  184. //
  185. #define DBG_if(x) if (x)
  186. #define DBG_else else
  187. #else // !DBG
  188. // Debug macros compile out of non-DBG builds.
  189. //
  190. #define TRACE(ulLevel,ulMask,Args)
  191. #undef ASSERT
  192. #define ASSERT(x)
  193. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  194. #define DUMPB(ulLevel,ulMask,p,cb)
  195. #define DUMPW(ulLevel,ulMask,p,cb)
  196. #define DUMPDW(ulLevel,ulMask,p,cb)
  197. #define CHECKLIST(ulMask,p,ulLevel)
  198. #define DBG_if(x)
  199. #define DBG_else
  200. #endif
  201. //-----------------------------------------------------------------------------
  202. // Prototypes
  203. //-----------------------------------------------------------------------------
  204. VOID
  205. CheckList(
  206. IN LIST_ENTRY* pList,
  207. IN BOOLEAN fShowLinks );
  208. VOID
  209. Dump(
  210. CHAR* p,
  211. ULONG cb,
  212. BOOLEAN fAddress,
  213. ULONG ulGroup );
  214. VOID
  215. DumpLine(
  216. CHAR* p,
  217. ULONG cb,
  218. BOOLEAN fAddress,
  219. ULONG ulGroup );
  220. //-----------------------------------------------------------------------------
  221. // WPP Tracing
  222. //-----------------------------------------------------------------------------
  223. #define LL_A 1
  224. #define LL_M 2
  225. #define LL_I 3
  226. #define LL_V 4
  227. #define WPP_CONTROL_GUIDS \
  228. WPP_DEFINE_CONTROL_GUID(CtlGuid,(d58c126e, b309, 11d1, 969e, 0000f875a5bc), \
  229. WPP_DEFINE_BIT(LM_Res) \
  230. WPP_DEFINE_BIT(LM_CMsg) \
  231. WPP_DEFINE_BIT(LM_Cm) \
  232. WPP_DEFINE_BIT(LM_Fsm) \
  233. WPP_DEFINE_BIT(LM_Send) \
  234. WPP_DEFINE_BIT(LM_Recv) \
  235. WPP_DEFINE_BIT(LM_Tdi) \
  236. WPP_DEFINE_BIT(LM_Pool) \
  237. WPP_DEFINE_BIT(LM_Misc) \
  238. WPP_DEFINE_BIT(LM_Mp) )
  239. #define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) WPP_LEVEL_LOGGER(flags)
  240. #define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl)
  241. #endif // _DEBUG_H_