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.

240 lines
6.7 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1998-1999 Microsoft Corporation
  4. *
  5. * DEBUG.H - debugging macros, etc.
  6. *
  7. * Author: Stan Adermann (stana)
  8. *
  9. * Created: 9/2/1998
  10. *
  11. *****************************************************************************/
  12. #ifndef DEBUG_H
  13. #define DEBUG_H
  14. #include "dbgapi.h"
  15. // Compile time debug flags
  16. #ifndef MEM_CHECKING
  17. #if DBG
  18. #define MEM_CHECKING 1
  19. #else
  20. #define MEM_CHECKING 0
  21. #endif
  22. #endif
  23. #ifndef LIST_CHECKING
  24. #if DBG
  25. #define LIST_CHECKING 1
  26. #else
  27. #define LIST_CHECKING 0
  28. #endif
  29. #endif
  30. #ifndef LOCK_CHECKING
  31. #define LOCK_CHECKING 0
  32. #endif
  33. #define DBG_ERR(Status) (((Status)!=NDIS_STATUS_SUCCESS && (Status)!=NDIS_STATUS_PENDING)? DBG_ERROR : 0)
  34. #define DBG_ERROR DEBUGZONE(0)
  35. #define DBG_WARN DEBUGZONE(1)
  36. #define DBG_FUNC DEBUGZONE(2)
  37. #define DBG_INIT DEBUGZONE(3)
  38. #define DBG_TX DEBUGZONE(4)
  39. #define DBG_RX DEBUGZONE(5)
  40. #define DBG_TDI DEBUGZONE(6)
  41. #define DBG_TUNNEL DEBUGZONE(7)
  42. #define DBG_CALL DEBUGZONE(8)
  43. #define DBG_PACKET DEBUGZONE(9)
  44. #define DBG_NDIS DEBUGZONE(10)
  45. #define DBG_TAPI DEBUGZONE(11)
  46. #define DBG_THREAD DEBUGZONE(12)
  47. #define DBG_POOL DEBUGZONE(13)
  48. #define DBG_REF DEBUGZONE(14)
  49. #define DBG_LOG DEBUGZONE(15)
  50. #define DBG_X(dbgs, x) DEBUGMSG(dbgs, (DTEXT(#x"==0x%x\n"), (x)))
  51. #define DBG_D(dbgs, d) DEBUGMSG(dbgs, (DTEXT(#d"==%d\n"), (d)))
  52. #define DBG_S(dbgs, s) DEBUGMSG(dbgs, (DTEXT(#s"==\"%hs\"\n"), (s)))
  53. #if LOCK_CHECKING
  54. typedef struct MY_SPIN_LOCK {
  55. NDIS_SPIN_LOCK;
  56. CHAR File[12];
  57. ULONG Line;
  58. } MY_SPIN_LOCK, *PMY_SPIN_LOCK;
  59. VOID FASTCALL _MyAcquireSpinLock(PMY_SPIN_LOCK pLock, PUCHAR file, UINT line);
  60. #define MyAcquireSpinLock(Lock) _MyAcquireSpinLock((Lock), __FILE__, __LINE__)
  61. #define MyReleaseSpinLock(Lock) NdisReleaseSpinLock((PNDIS_SPIN_LOCK)(Lock))
  62. #else
  63. typedef NDIS_SPIN_LOCK MY_SPIN_LOCK, *PMY_SPIN_LOCK;
  64. #define MyAcquireSpinLock NdisAcquireSpinLock
  65. #define MyReleaseSpinLock NdisReleaseSpinLock
  66. #endif
  67. #if MEM_CHECKING
  68. #define MyMemAlloc(size, tag) _MyMemAlloc((size), (tag), __FILE__,__LINE__)
  69. PVOID _MyMemAlloc(UINT, ULONG, PUCHAR, UINT);
  70. VOID InitMemory();
  71. VOID DeinitMemory();
  72. #else
  73. #define InitMemory()
  74. #define DeinitMemory()
  75. PVOID
  76. MyMemAlloc(UINT size, ULONG tag);
  77. #endif
  78. VOID
  79. MyMemFree(
  80. PVOID memptr,
  81. UINT size);
  82. PLIST_ENTRY FASTCALL MyInterlockedInsertHeadList(PLIST_ENTRY Head, PLIST_ENTRY Entry, PNDIS_SPIN_LOCK SpinLock);
  83. PLIST_ENTRY FASTCALL MyInterlockedInsertTailList(PLIST_ENTRY Head, PLIST_ENTRY Entry, PNDIS_SPIN_LOCK SpinLock);
  84. PLIST_ENTRY FASTCALL MyInterlockedRemoveHeadList(PLIST_ENTRY Head, PNDIS_SPIN_LOCK SpinLock);
  85. #if LIST_CHECKING
  86. VOID FASTCALL CheckList(PLIST_ENTRY ListHead);
  87. BOOLEAN FASTCALL CheckListEntry(PLIST_ENTRY ListHead, PLIST_ENTRY Entry);
  88. #define CheckedRemoveEntryList(Entry) {\
  89. PLIST_ENTRY _EX_Blink;\
  90. PLIST_ENTRY _EX_Flink;\
  91. PLIST_ENTRY _EX_Entry;\
  92. CheckList(Entry);\
  93. _EX_Entry = (Entry);\
  94. _EX_Flink = _EX_Entry->Flink;\
  95. _EX_Blink = _EX_Entry->Blink;\
  96. _EX_Blink->Flink = _EX_Flink;\
  97. _EX_Flink->Blink = _EX_Blink;\
  98. _EX_Entry->Flink = _EX_Entry->Blink = NULL; \
  99. }
  100. #ifdef RemoveEntryList
  101. #undef RemoveEntryList
  102. #endif
  103. #define RemoveEntryList CheckedRemoveEntryList
  104. #define CheckedInsertHeadList(ListHead,Entry) {\
  105. PLIST_ENTRY _EX_Flink;\
  106. PLIST_ENTRY _EX_ListHead;\
  107. CheckList(ListHead);\
  108. _EX_ListHead = (ListHead);\
  109. _EX_Flink = _EX_ListHead->Flink;\
  110. (Entry)->Flink = _EX_Flink;\
  111. (Entry)->Blink = _EX_ListHead;\
  112. _EX_Flink->Blink = (Entry);\
  113. _EX_ListHead->Flink = (Entry);\
  114. CheckList(ListHead);\
  115. }
  116. #ifdef InsertHeadList
  117. #undef InsertHeadList
  118. #endif
  119. #define InsertHeadList CheckedInsertHeadList
  120. #define CheckedInsertTailList(ListHead,Entry) {\
  121. PLIST_ENTRY _EX_Blink;\
  122. PLIST_ENTRY _EX_ListHead;\
  123. CheckList(ListHead);\
  124. _EX_ListHead = (ListHead);\
  125. _EX_Blink = _EX_ListHead->Blink;\
  126. (Entry)->Flink = _EX_ListHead;\
  127. (Entry)->Blink = _EX_Blink;\
  128. _EX_Blink->Flink = (Entry);\
  129. _EX_ListHead->Blink = (Entry);\
  130. CheckList(ListHead);\
  131. }
  132. #ifdef InsertTailList
  133. #undef InsertTailList
  134. #endif
  135. #define InsertTailList CheckedInsertTailList
  136. #define CheckedRemoveHeadList(ListHead) \
  137. (ListHead)->Flink;\
  138. if(!IsListEmpty(ListHead)){ \
  139. RemoveEntryList((ListHead)->Flink);\
  140. CheckList(ListHead);\
  141. }
  142. #ifdef RemoveHeadList
  143. #undef RemoveHeadList
  144. #endif
  145. #define RemoveHeadList CheckedRemoveHeadList
  146. #define CheckedRemoveTailList(ListHead) \
  147. (ListHead)->Blink;\
  148. if(!IsListEmpty(ListHead)){ \
  149. RemoveEntryList((ListHead)->Blink);\
  150. CheckList(ListHead);\
  151. }
  152. #ifdef RemoveTailList
  153. #undef RemoveTailList
  154. #endif
  155. #define RemoveTailList CheckedRemoveTailList
  156. #else // ! LIST_CHECKING
  157. #define CheckList(h)
  158. #define CheckListEntry(h, e)
  159. #endif
  160. #define MyInterlockedRemoveEntryList(Entry, Lock) \
  161. { \
  162. NdisAcquireSpinLock(Lock); \
  163. RemoveEntryList(Entry); \
  164. NdisReleaseSpinLock(Lock); \
  165. }
  166. #if DBG
  167. char *ControlStateToString(ULONG State);
  168. char *CallStateToString(ULONG State);
  169. #endif
  170. #if DBG
  171. #define DBGTRACE(_a) \
  172. if(pCall->TraceIndex < 60) \
  173. { \
  174. pCall->DbgTrace[pCall->TraceIndex] = _a; \
  175. ++pCall->TraceIndex; \
  176. }
  177. #define DBGTRACE_INIT(_pcall) \
  178. NdisZeroMemory(_pcall->DbgTrace, 64); \
  179. _pcall->TraceIndex = 0
  180. #else
  181. #define DBGTRACE(_a)
  182. #define DBGTRACE_INIT(_pcall)
  183. #endif
  184. //-----------------------------------------------------------------------------
  185. // WPP Tracing
  186. //-----------------------------------------------------------------------------
  187. #define LL_A 1
  188. #define LL_M 2
  189. #define LL_I 3
  190. #define LL_V 4
  191. #define WPP_CONTROL_GUIDS \
  192. WPP_DEFINE_CONTROL_GUID(CtlGuid,(d58c126f, b309, 11d1, 969e, 0000f875a5bc), \
  193. WPP_DEFINE_BIT(LM_Res) \
  194. WPP_DEFINE_BIT(LM_CMsg) \
  195. WPP_DEFINE_BIT(LM_TDI) \
  196. WPP_DEFINE_BIT(LM_TUNNEL) \
  197. WPP_DEFINE_BIT(LM_CALL) \
  198. WPP_DEFINE_BIT(LM_PACKET) \
  199. WPP_DEFINE_BIT(LM_NDIS) \
  200. WPP_DEFINE_BIT(LM_TAPI) \
  201. WPP_DEFINE_BIT(LM_POOL) \
  202. WPP_DEFINE_BIT(LM_REF) )
  203. #define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) WPP_LEVEL_LOGGER(flags)
  204. #define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl)
  205. #endif //DEBUG_H