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.

201 lines
5.4 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. #if LIST_CHECKING
  83. PLIST_ENTRY FASTCALL MyInterlockedInsertHeadList(PLIST_ENTRY Head, PLIST_ENTRY Entry, PNDIS_SPIN_LOCK SpinLock);
  84. PLIST_ENTRY FASTCALL MyInterlockedInsertTailList(PLIST_ENTRY Head, PLIST_ENTRY Entry, PNDIS_SPIN_LOCK SpinLock);
  85. PLIST_ENTRY FASTCALL MyInterlockedRemoveHeadList(PLIST_ENTRY Head, PNDIS_SPIN_LOCK SpinLock);
  86. VOID FASTCALL CheckList(PLIST_ENTRY ListHead);
  87. #define CheckedRemoveEntryList(Entry) {\
  88. PLIST_ENTRY _EX_Blink;\
  89. PLIST_ENTRY _EX_Flink;\
  90. PLIST_ENTRY _EX_Entry;\
  91. CheckList(Entry);\
  92. _EX_Entry = (Entry);\
  93. _EX_Flink = _EX_Entry->Flink;\
  94. _EX_Blink = _EX_Entry->Blink;\
  95. _EX_Blink->Flink = _EX_Flink;\
  96. _EX_Flink->Blink = _EX_Blink;\
  97. _EX_Entry->Flink = _EX_Entry->Blink = NULL; \
  98. }
  99. #ifdef RemoveEntryList
  100. #undef RemoveEntryList
  101. #endif
  102. #define RemoveEntryList CheckedRemoveEntryList
  103. #define CheckedInsertHeadList(ListHead,Entry) {\
  104. PLIST_ENTRY _EX_Flink;\
  105. PLIST_ENTRY _EX_ListHead;\
  106. CheckList(ListHead);\
  107. _EX_ListHead = (ListHead);\
  108. _EX_Flink = _EX_ListHead->Flink;\
  109. (Entry)->Flink = _EX_Flink;\
  110. (Entry)->Blink = _EX_ListHead;\
  111. _EX_Flink->Blink = (Entry);\
  112. _EX_ListHead->Flink = (Entry);\
  113. CheckList(ListHead);\
  114. }
  115. #ifdef InsertHeadList
  116. #undef InsertHeadList
  117. #endif
  118. #define InsertHeadList CheckedInsertHeadList
  119. #define CheckedInsertTailList(ListHead,Entry) {\
  120. PLIST_ENTRY _EX_Blink;\
  121. PLIST_ENTRY _EX_ListHead;\
  122. CheckList(ListHead);\
  123. _EX_ListHead = (ListHead);\
  124. _EX_Blink = _EX_ListHead->Blink;\
  125. (Entry)->Flink = _EX_ListHead;\
  126. (Entry)->Blink = _EX_Blink;\
  127. _EX_Blink->Flink = (Entry);\
  128. _EX_ListHead->Blink = (Entry);\
  129. CheckList(ListHead);\
  130. }
  131. #ifdef InsertTailList
  132. #undef InsertTailList
  133. #endif
  134. #define InsertTailList CheckedInsertTailList
  135. #define CheckedRemoveHeadList(ListHead) \
  136. (ListHead)->Flink;\
  137. if(!IsListEmpty(ListHead)){ \
  138. RemoveEntryList((ListHead)->Flink);\
  139. CheckList(ListHead);\
  140. }
  141. #ifdef RemoveHeadList
  142. #undef RemoveHeadList
  143. #endif
  144. #define RemoveHeadList CheckedRemoveHeadList
  145. #define CheckedRemoveTailList(ListHead) \
  146. (ListHead)->Blink;\
  147. if(!IsListEmpty(ListHead)){ \
  148. RemoveEntryList((ListHead)->Blink);\
  149. CheckList(ListHead);\
  150. }
  151. #ifdef RemoveTailList
  152. #undef RemoveTailList
  153. #endif
  154. #define RemoveTailList CheckedRemoveTailList
  155. #else // ! LIST_CHECKING
  156. #define CheckList(h)
  157. #define MyInterlockedInsertHeadList NdisInterlockedInsertHeadList
  158. #define MyInterlockedInsertTailList NdisInterlockedInsertTailList
  159. #define MyInterlockedRemoveHeadList NdisInterlockedRemoveHeadList
  160. #endif
  161. #define MyInterlockedRemoveEntryList(Entry, Lock) \
  162. { \
  163. NdisAcquireSpinLock(Lock); \
  164. RemoveEntryList(Entry); \
  165. NdisReleaseSpinLock(Lock); \
  166. }
  167. #if DBG
  168. struct PPTP_ADAPTER * gAdapter;
  169. #endif
  170. #if DBG
  171. char *ControlStateToString(ULONG State);
  172. char *CallStateToString(ULONG State);
  173. #endif
  174. #endif //DEBUG_H