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.

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