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.

236 lines
8.6 KiB

  1. // Copyright (c) 1997, Microsoft Corporation, all rights reserved
  2. // Copyright (c) 1997, Parallel Technologies, Inc., all rights reserved
  3. //
  4. //
  5. // debug.h
  6. // DirectParallel WAN mini-port/call-manager driver
  7. // Debug helper header
  8. //
  9. // 01/07/97 Steve Cobb
  10. // 09/15/97 Jay Lowe, Parallel Technologies, Inc.
  11. #ifndef _DEBUG_H_
  12. #define _DEBUG_H_
  13. //-----------------------------------------------------------------------------
  14. // Debug constants
  15. //-----------------------------------------------------------------------------
  16. // Memory tags used with NdisAllocateMemoryWithTag to identify allocations
  17. // made by the L2TP driver. Also, several context blocks define a first field
  18. // of 'ulTag' set to these values for ASSERT sanity checking and eased memory
  19. // dump browsing. Such tags are set to MTAG_FREED just before NdisFreeMemory
  20. // is called.
  21. //
  22. #define MTAG_FREED 'fITP'
  23. #define MTAG_ADAPTERCB 'aITP'
  24. #define MTAG_VCCB 'vITP'
  25. #define MTAG_UTIL 'uITP'
  26. #define MTAG_VCTABLE 'tITP'
  27. #define MTAG_PTIPARAMS 'pITP'
  28. #define MTAG_PACKETPOOL 'pITP'
  29. #define MTAG_FBUFPOOL 'bITP'
  30. #define MTAG_INCALLBUF 'iITP'
  31. #define MTAG_WORKITEM 'wITP'
  32. // Trace levels.
  33. //
  34. #define TL_None 0 // Trace disabled
  35. #define TL_A 0x10 // Alert
  36. #define TL_I 0x20 // Interface
  37. #define TL_N 0x30 // Normal
  38. #define TL_V 0x40 // Verbose
  39. // Trace mask bits.
  40. //
  41. #define TM_Cm 0x00000001 // Call manager general
  42. #define TM_Mp 0x00000002 // Mini-port general
  43. #define TM_Send 0x00000004 // Send path
  44. #define TM_Recv 0x00000008 // Receive path
  45. #define TM_Fsm 0x00000010 // Finite state machines
  46. #define TM_Init 0x00000020 // Initialization
  47. #define TM_Misc 0x00000040 // Miscellaneous
  48. #define TM_Msg 0x00000100 // Messages
  49. #define TM_Ref 0x00010000 // References
  50. #define TM_Data 0x00020000 // Dump data under TESTMODE
  51. #define TM_Pool 0x00080000 // Buffer and packet pooling
  52. #define TM_MDmp 0x10000000 // Message dumps
  53. #define TM_Dbg 0x80000000 // Debug corruption checks
  54. #define TM_Spec 0x01000000 // Special
  55. #define TM_Wild 0xFFFFFFFF // Everything
  56. #define TM_All 0x7FFFFFFF // Everything except corruption checks
  57. #define TM_Test 0x0001FFF3 // Base w/ messages and references
  58. #define TM_Base 0x000000F3 // Base w/o send and receive
  59. // Bytes to appear on each line of dump output.
  60. //
  61. #define DUMP_BytesPerLine 16
  62. //-----------------------------------------------------------------------------
  63. // Debug global declarations (defined in debug.c)
  64. //-----------------------------------------------------------------------------
  65. // Active debug trace level and active trace set mask. Set these variables
  66. // with the debugger at startup to enable and filter the debug output. All
  67. // messages with (TL_*) level less than or equal to 'g_ulTraceLevel' and from
  68. // any (TM_*) set(s) present in 'g_ulTraceMask' are displayed.
  69. //
  70. extern ULONG g_ulTraceLevel;
  71. extern ULONG g_ulTraceMask;
  72. //-----------------------------------------------------------------------------
  73. // Debug macros
  74. //-----------------------------------------------------------------------------
  75. #if DBG
  76. // TRACE sends printf style output to the kernel debugger. Caller indicates a
  77. // "verbosity" level with the 'ulLevel' argument and associates the trace with
  78. // one or more trace sets with the 'ulMask' bit mask argument. Notice that
  79. // the variable count printf arguments 'Args' must be parenthesized. For
  80. // example...
  81. //
  82. // A "leave" routine message:
  83. // TRACE( TL_N, TM_Init, ( "DriverEntry=$%x", status ) );
  84. // An error condition occurred:
  85. // TRACE( TL_E, TM_Init, ( "NdisMRegisterMiniport=$%x", status ) );
  86. //
  87. //
  88. #define TRACE(ulLevel,ulMask,Args) \
  89. { \
  90. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  91. { \
  92. DbgPrint( "RASPTI: " ); \
  93. DbgPrint Args; \
  94. DbgPrint( "\n" ); \
  95. } \
  96. }
  97. // ASSERT checks caller's assertion expression and if false, prints a kernel
  98. // debugger message and breaks.
  99. //
  100. #undef ASSERT
  101. #define ASSERT(x) \
  102. { \
  103. if (!(x)) \
  104. { \
  105. DbgPrint( "RASPTI: !ASSERT( %s ) at line %d of %s\n", \
  106. #x, __LINE__, __FILE__ ); \
  107. DbgBreakPoint(); \
  108. } \
  109. }
  110. // DUMP prints to the kernel debugger a hex dump of 'cb' bytes starting at 'p'
  111. // in groups of 'ul'. If 'f' is set the address of each line in shown before
  112. // the dump. DUMPB, DUMPW, and DUMPDW are BYTE, WORD, and DWORD dumps
  113. // respectively. Note that the multi-byte dumps do not reflect little-endian
  114. // (Intel) byte order. The 'ulLevel' and 'ulMask' are described for TRACE.
  115. //
  116. #define DUMP(ulLevel,ulMask,p,cb,f,ul) \
  117. { \
  118. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  119. { \
  120. Dump( (CHAR* )p, cb, f, ul ); \
  121. } \
  122. }
  123. #define DUMPB(ulLevel,ulMask,p,cb) \
  124. { \
  125. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  126. { \
  127. Dump( (CHAR* )p, cb, 0, 1 ); \
  128. } \
  129. }
  130. #define DUMPW(ulLevel,ulMask,p,cb) \
  131. { \
  132. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  133. { \
  134. Dump( (CHAR* )p, cb, 0, 2 ); \
  135. } \
  136. }
  137. #define DUMPDW(ulLevel,ulMask,p,cb) \
  138. { \
  139. if (ulLevel <= g_ulTraceLevel && (g_ulTraceMask & ulMask)) \
  140. { \
  141. Dump( (CHAR* )p, cb, 0, 4 ); \
  142. } \
  143. }
  144. // Double-linked list corruption detector. Runs the test if 'ulMask' is
  145. // enabled, with TM_Dbg a suggested setting. Shows verbose output if
  146. // 'ulLevel' is at or above the current trace threshold.
  147. //
  148. #define CHECKLIST(ulMask,p,ulLevel) \
  149. { \
  150. if (g_ulTraceMask & ulMask) \
  151. { \
  152. CheckList( p, (BOOLEAN )(ulLevel <= g_ulTraceLevel) ); \
  153. } \
  154. }
  155. // DBG_if can be used to put in TRACE/DUMPs conditional on an expression that
  156. // need not be evaluated in non-DBG builds, e.g the statements below generate
  157. // no code in a non-DBG build, but in DBG builds print the TRACE if x<y and
  158. // asserts otherwise.
  159. //
  160. // DBG_if (x < y)
  161. // TRACE( TL_N, TM_Misc, ( "x < y" ) );
  162. // DBG_else
  163. // ASSERT( FALSE );
  164. //
  165. //
  166. #define DBG_if(x) if (x)
  167. #define DBG_else else
  168. #else // !DBG
  169. // Debug macros compile out of non-DBG builds.
  170. //
  171. #define TRACE(ulLevel,ulMask,Args)
  172. #undef ASSERT
  173. #define ASSERT(x)
  174. #define DUMP(ulLevel,ulMask,p,cb,f,dw)
  175. #define DUMPB(ulLevel,ulMask,p,cb)
  176. #define DUMPW(ulLevel,ulMask,p,cb)
  177. #define DUMPDW(ulLevel,ulMask,p,cb)
  178. #define CHECKLIST(ulMask,p,ulLevel)
  179. #define DBG_if(x)
  180. #define DBG_else
  181. #endif
  182. //-----------------------------------------------------------------------------
  183. // Prototypes
  184. //-----------------------------------------------------------------------------
  185. VOID
  186. CheckList(
  187. IN LIST_ENTRY* pList,
  188. IN BOOLEAN fShowLinks );
  189. VOID
  190. Dump(
  191. CHAR* p,
  192. ULONG cb,
  193. BOOLEAN fAddress,
  194. ULONG ulGroup );
  195. VOID
  196. DumpLine(
  197. CHAR* p,
  198. ULONG cb,
  199. BOOLEAN fAddress,
  200. ULONG ulGroup );
  201. #endif // _DEBUG_H_