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.

320 lines
12 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. debug defines shared between the KD extensions and the driver
  7. Author:
  8. Charlie Wickham (charlwi) 11-May-1995
  9. Revision History:
  10. --*/
  11. #ifndef _DEBUG_
  12. #define _DEBUG_
  13. //
  14. //
  15. // Debug Level and Mask definitions.
  16. //
  17. #define DBG_DEATH 1
  18. #define DBG_CRITICAL_ERROR 2
  19. #define DBG_FAILURE 4
  20. #define DBG_INFO 6
  21. #define DBG_TRACE 8
  22. #define DBG_VERBOSE 10
  23. #define DBG_INIT 0x00000001
  24. #define DBG_MINIPORT 0x00000002
  25. #define DBG_PROTOCOL 0x00000004
  26. #define DBG_SEND 0x00000008
  27. #define DBG_RECEIVE 0x00000010
  28. #define DBG_IO 0x00000020
  29. #define DBG_MEMORY 0x00000040
  30. #define DBG_CM 0x00000080
  31. #define DBG_REFCNTS 0x00000100
  32. #define DBG_VC 0x00000200
  33. #define DBG_GPC_QOS 0x00000400
  34. #define DBG_WAN 0x00000800
  35. #define DBG_STATE 0x00001000
  36. #define DBG_ROUTINEOIDS 0x00002000
  37. #define DBG_SCHED_TBC 0x00004000
  38. #define DBG_SCHED_SHAPER 0x00008000
  39. #define DBG_SCHED_DRR 0x00010000
  40. #define DBG_WMI 0x00020000
  41. #define DBG_ZAW 0x00040000
  42. #define DBG_ALL 0xFFFFFFFF
  43. //
  44. // these tags are used in Lookaside lists therefore need to be
  45. // available regardless of the type of build
  46. //
  47. extern ULONG NdisRequestTag;
  48. extern ULONG GpcClientVcTag;
  49. extern ULONG WanLinkTag;
  50. extern ULONG PsMiscTag;
  51. extern ULONG WMITag;
  52. #define NDIS_PACKET_POOL_TAG_FOR_PSCHED 'pPDN'
  53. // We mark all memory allocated via PsAllocateXXX with a signature
  54. // immediately following allocation, and with another signature
  55. // immediately preceeding freeing.
  56. #define ALLOCATED_MARK (UCHAR) 0xDD
  57. #define FREED_MARK (UCHAR) 0xBB
  58. //
  59. // NT Debugging routines
  60. //
  61. //
  62. // signatures for data structures
  63. //
  64. extern ULONG AdapterTag;
  65. extern ULONG CmParamsTag;
  66. extern ULONG PipeContextTag;
  67. extern ULONG FlowContextTag;
  68. extern ULONG ClassMapContextTag;
  69. extern ULONG ProfileTag;
  70. extern ULONG ComponentTag;
  71. extern ULONG WanTableTag;
  72. #if DBG
  73. extern CHAR VersionNumber[];
  74. extern CHAR VersionHerald[];
  75. extern CHAR VersionTimestamp[];
  76. #define DEBUGCHK DbgBreakPoint()
  77. #define STATIC
  78. //
  79. // these correspond to DebugLevel and DebugMask in Psched\Parameters
  80. //
  81. extern ULONG DbgTraceLevel;
  82. extern ULONG DbgTraceMask;
  83. extern ULONG LogTraceLevel;
  84. extern ULONG LogTraceMask;
  85. extern ULONG LogId;
  86. extern ULONG DbgTraceControl;
  87. #define PsDbgSched(_DebugLevel, _DebugMask, _r, _s, _t, _u, _v, _w, _x1, _x2, _y, _z){\
  88. if ((LogTraceLevel >= _DebugLevel) && \
  89. ((_DebugMask) & LogTraceMask)){ \
  90. DbugSched(_r, _s, _t, _u, _v, _w, (_x1), (_x2), _y, _z);\
  91. }\
  92. }
  93. #define PsDbgRecv(_DebugLevel, _DebugMask, _event, _action, _a, _p1, _p2) {\
  94. if ((LogTraceLevel >= _DebugLevel) && \
  95. ((_DebugMask) & LogTraceMask)){ \
  96. DbugRecv(_event, _action, _a, _p1, _p2); \
  97. } \
  98. }
  99. #define PsDbgSend(_DebugLevel, _DebugMask, _event, _action, _a, _v, _p1, _p2) {\
  100. if ((LogTraceLevel >= _DebugLevel) && \
  101. ((_DebugMask) & LogTraceMask)){ \
  102. DbugSend(_event, _action, _a, _v, _p1, _p2); \
  103. } \
  104. }
  105. #define PsDbgOid(_DebugLevel, _DebugMask, Action, Local, PTState, MPState, Adapter, Oid, Status) {\
  106. if ((LogTraceLevel >= _DebugLevel) && \
  107. ((_DebugMask) & LogTraceMask)){ \
  108. DbugOid(Action, Local, PTState, MPState, Adapter, Oid, Status); \
  109. } \
  110. }
  111. #define PsDbgOut(_DebugLevel, _DebugMask, _Out){ \
  112. if ((DbgTraceLevel >= _DebugLevel) && \
  113. ((_DebugMask) & DbgTraceMask)){ \
  114. DbgPrint("PSched: "); \
  115. DbgPrint _Out; \
  116. } \
  117. if ((LogTraceLevel >= _DebugLevel) && \
  118. ((_DebugMask) & LogTraceMask)){ \
  119. DbugSchedString _Out; \
  120. } \
  121. }
  122. #define PsDbgOutNoID(_DebugLevel, _DebugMask, _Out) { \
  123. if ((DbgTraceLevel >= _DebugLevel) && \
  124. ((_DebugMask) & DbgTraceMask)){ \
  125. DbgPrint _Out; \
  126. } \
  127. if ((LogTraceLevel >= _DebugLevel) && \
  128. ((_DebugMask) & LogTraceMask)){ \
  129. DbugSchedString _Out; \
  130. } \
  131. }
  132. #define PS_LOCK(_s) { \
  133. NdisAcquireSpinLock(&((_s)->Lock)); \
  134. PsAssert((_s)->LockAcquired == FALSE); \
  135. (_s)->LockAcquired = TRUE; \
  136. (_s)->LastAcquiredLine = __LINE__; \
  137. strncpy((_s)->LastAcquiredFile, strrchr(__FILE__, '\\')+1, 7); \
  138. }
  139. #define PS_UNLOCK(_s) \
  140. { \
  141. PsAssert((_s)->LockAcquired == TRUE); \
  142. (_s)->LockAcquired = FALSE; \
  143. (_s)->LastReleasedLine = __LINE__; \
  144. strncpy((_s)->LastReleasedFile, strrchr(__FILE__, '\\')+1, 7); \
  145. NdisReleaseSpinLock(&((_s)->Lock)); \
  146. }
  147. #define PS_LOCK_DPC(_s) { \
  148. PsAssert(KeGetCurrentIrql() == DISPATCH_LEVEL); \
  149. NdisDprAcquireSpinLock(&((_s)->Lock)); \
  150. PsAssert((_s)->LockAcquired == FALSE); \
  151. (_s)->LockAcquired = TRUE; \
  152. (_s)->LastAcquiredLine = __LINE__; \
  153. strncpy((_s)->LastAcquiredFile, strrchr(__FILE__, '\\')+1, 7); \
  154. }
  155. #define PS_UNLOCK_DPC(_s) \
  156. { \
  157. PsAssert(KeGetCurrentIrql() == DISPATCH_LEVEL); \
  158. PsAssert((_s)->LockAcquired == TRUE); \
  159. (_s)->LockAcquired = FALSE; \
  160. (_s)->LastReleasedLine = __LINE__; \
  161. strncpy((_s)->LastReleasedFile, strrchr(__FILE__, '\\')+1, 7); \
  162. NdisDprReleaseSpinLock(&((_s)->Lock)); \
  163. }
  164. #define PS_INIT_SPIN_LOCK(_s) { \
  165. (_s)->LockAcquired = FALSE; \
  166. (_s)->LastAcquiredLine = __LINE__; \
  167. strncpy((_s)->LastAcquiredFile, strrchr(__FILE__, '\\')+1, 7); \
  168. NdisAllocateSpinLock(&((_s)->Lock)); \
  169. }
  170. #define KdPrint( x ) DbgPrint x
  171. #define STRUCT_LLTAG ULONG LLTag
  172. #define PsStructAssert(_tag) if ((_tag) != NULL && *(PULONG)((PUCHAR)_tag - sizeof(ULONG)) != _tag##Tag) {\
  173. DbgPrint( "PSched: structure assertion failure for type " #_tag " in file " __FILE__ " line %d\n", __LINE__ );\
  174. DEBUGCHK;\
  175. }
  176. #define PsAssert(c) if (!(c)) {\
  177. DbgPrint( "PSched: assertion @ line %d in file " __FILE__ " \n", __LINE__ );\
  178. DEBUGCHK;\
  179. }
  180. //
  181. // allocate memory from nonpaged pool and set the tag in the checked
  182. // version of the structure
  183. //
  184. #define PsAllocatePool( _addr, _size, _tag ) \
  185. { \
  186. PCHAR _Temp; \
  187. ULONG _Size = (_size) + 2 * sizeof(ULONG); \
  188. _Temp = ExAllocatePoolWithTag( NonPagedPool, (_Size), (_tag)); \
  189. if ( _Temp ) { \
  190. NdisFillMemory( _Temp, _Size, ALLOCATED_MARK); \
  191. *(PULONG)_Temp = _Size; \
  192. *(PULONG)(_Temp + sizeof(ULONG)) = _tag; \
  193. (PCHAR)(_addr) = _Temp + 2 * sizeof(ULONG); \
  194. } \
  195. else{ \
  196. (PCHAR)(_addr) = _Temp; \
  197. } \
  198. }
  199. #define PsFreePool(_addr) \
  200. { \
  201. PCHAR _Temp = (PCHAR)(_addr) - 2 * sizeof(ULONG); \
  202. ULONG _Size = *(PULONG)_Temp; \
  203. NdisFillMemory( _Temp, _Size, FREED_MARK); \
  204. ExFreePool(_Temp); \
  205. }
  206. //
  207. // structures allocated from lookaside lists don't go through PsAllocateXXX.
  208. // so - if we wanna tag these, we'll have to macro the LL routines.
  209. //
  210. #define PsAllocFromLL(_ptr, _list, _tag) \
  211. *_ptr = NdisAllocateFromNPagedLookasideList(_list); \
  212. if(*_ptr != 0) {\
  213. *_ptr->LLTag = _tag##Tag; \
  214. }
  215. #define PsFreeToLL(_ptr, _list, _tag) \
  216. PsAssert(_ptr->LLTag == _tag##Tag); \
  217. _ptr->LLTag = (ULONG)0; \
  218. NdisFreeToNPagedLookasideList(_list, _ptr); \
  219. #define CheckLLTag(_ptr, _tag) \
  220. PsAssert(_ptr->LLTag == _tag##Tag);
  221. #define SetLLTag(_ptr, _tag) (_ptr)->LLTag = _tag##Tag;
  222. #else // DBG
  223. #define DEBUGCHK
  224. #define PsDbgSched(_DebugLevel, _DebugMask, _r, _s, _t, _u, _v, _w, _x1, _x2, _y, _z)
  225. #define PsDbgRecv(_DebugLevel, _DebugMask, _event, _action, _a, _p1, _p2)
  226. #define PsDbgSend(_DebugLevel, _DebugMask, _event, _action, _a, _v, _p1, _p2)
  227. #define PsDbgOut(s,t,u)
  228. #define PsDbgOid(p,q,s,t,u,v,w,x,y)
  229. #define PsDbgOutNoID(s,t,u)
  230. #define PsDbg(r, s, t, u)
  231. #define KdPrint( x )
  232. #define STRUCT_LLTAG /##/
  233. #define PsStructAssert( t )
  234. #define PsAssert(c)
  235. #define PS_LOCK(_s) NdisAcquireSpinLock(&((_s)->Lock))
  236. #define PS_UNLOCK(_s) NdisReleaseSpinLock(&((_s)->Lock))
  237. #define PS_LOCK_DPC(_s) NdisDprAcquireSpinLock(&((_s)->Lock))
  238. #define PS_UNLOCK_DPC(_s) NdisDprReleaseSpinLock(&((_s)->Lock))
  239. #define PS_INIT_SPIN_LOCK(_s) NdisAllocateSpinLock(&((_s)->Lock))
  240. #define PsAllocatePool( _addr, _size, _tag ) \
  241. _addr = ExAllocatePoolWithTag( NonPagedPool, (_size), (_tag)); \
  242. if ( _addr ) { \
  243. NdisZeroMemory( _addr, _size ); \
  244. }
  245. #define PsFreePool(_addr) ExFreePool(_addr)
  246. //
  247. // structures allocated from lookaside lists don't go through PsAllocateXXX.
  248. // so - if we wanna tag these, we'll have to macro the LL routines.
  249. //
  250. #define PsAllocFromLL(_ptr, _list, _tag) \
  251. *_ptr = (PVOID)NdisAllocateFromNPagedLookasideList(_list); \
  252. #define PsFreeToLL(_ptr, _list, _tag) \
  253. NdisFreeToNPagedLookasideList(_list, _ptr);
  254. #define CheckLLTag(_ptr, _tag)
  255. #define SetLLTag(_ptr, _tag)
  256. #define STATIC static
  257. #endif // DBG
  258. #endif /* _DEBUG_ */
  259. /* end debug.h */