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.

223 lines
6.2 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1996-1999 Microsoft Corporation
  4. *
  5. * @doc
  6. * @module debug.h | IrSIR NDIS Miniport Driver
  7. * @comm
  8. *
  9. *-----------------------------------------------------------------------------
  10. *
  11. * Author: Scott Holden (sholden)
  12. *
  13. * Date: 10/4/1996 (created)
  14. *
  15. * Contents: debug output
  16. *
  17. *****************************************************************************/
  18. #ifndef _DEBUG_H_
  19. #define _DEBUG_H_
  20. #if DBG
  21. #define DEBUG
  22. #define DEBUG_IRSIR
  23. #endif
  24. #ifdef DEBUG
  25. extern int DbgSettings;
  26. #define DEBUGMSG(dbgs,format) (((dbgs) & DbgSettings)? DbgPrint format:0)
  27. #define DBG_PNP (1 << 24)
  28. #define DBG_TIME (1 << 25)
  29. #define DBG_DBG (1 << 26)
  30. #define DBG_OUT (1 << 27)
  31. #define DBG_STAT (1 << 28)
  32. #define DBG_FUNCTION (1 << 29)
  33. #define DBG_FUNC (1 << 29)
  34. #define DBG_WARN (1 << 30)
  35. #define DBG_ERROR (1 << 31)
  36. #define DBG_ERR (1 << 31)
  37. #define DBGDBG(_dbgPrint) \
  38. DbgPrint(_dbgPrint)
  39. #ifdef DEBUG_IRSIR
  40. #define DBG_D(dbgs, i) (((dbgs) & DbgSettings)? DbgPrint("IRSIR:"#i"==%d\n", (i)):0)
  41. #define DBG_X(dbgs, x) (((dbgs) & DbgSettings)? DbgPrint("IRSIR:"#x"==0x%0*X\n", sizeof(x)*2, ((ULONG_PTR)(x))&((1<<(sizeof(x)*8))-1) ):0)
  42. #define DBG_UNISTR(dbgs, s) (((dbgs) & DbgSettings)? DbgPrint("IRSIR:"#s"==%wZ\n", (s) ):0))
  43. #define DBGTIME(_str) \
  44. { \
  45. LARGE_INTEGER Time; \
  46. \
  47. KeQuerySystemTime(&Time); \
  48. DEBUGMSG(DBG_TIME, (_str " %d:%d\n", \
  49. Time.HighPart, \
  50. Time.LowPart/10000)); \
  51. }
  52. #else // DEBUG_IRSIR
  53. #define DBGTIME(_str)
  54. #define DBGFUNC(_dbgPrint)
  55. #define DBGOUT(_dbgPrint)
  56. #define DBGERR(_dbgPrint)
  57. #define DBGWARN(_dbgPrint)
  58. #define DBGSTAT(_dbgPrint)
  59. #define DBGTIME(_dbgPrint)
  60. #define DEBUGMSG(dbgs,format)
  61. #endif // DEBUG_IRSIR
  62. #else // DEBUG
  63. #define DBGTIME(_str)
  64. #define DBGFUNC(_dbgPrint)
  65. #define DBGDBG(_dbgPrint)
  66. #define DBGOUT(_dbgPrint)
  67. #define DBGERR(_dbgPrint)
  68. #define DBGWARN(_dbgPrint)
  69. #define DBGSTAT(_dbgPrint)
  70. #define DEBUGMSG(dbgs,format)
  71. #define DBG_D(dbgs, ivar)
  72. #define DBG_X(dbgs, xvar)
  73. #define DBG_UNISTR(dbgs, svar)
  74. #endif // DEBUG
  75. #ifndef LIST_CHECKING
  76. #define LIST_CHECKING 0
  77. #endif
  78. #ifndef MEM_CHECKING
  79. #define MEM_CHECKING 0
  80. #endif
  81. #ifndef LOGGING
  82. #define LOGGING 0
  83. #endif
  84. #if LOGGING
  85. typedef struct {
  86. UHALF_PTR Tag;
  87. UHALF_PTR Line;
  88. ULONG_PTR Data[3];
  89. } LOG;
  90. #define NUM_LOG 1024
  91. extern ULONG LogIndex;
  92. extern LOG Log[NUM_LOG];
  93. #define NextLog() ((NdisInterlockedIncrement(&LogIndex)-1)&(NUM_LOG-1))
  94. #define LOG_ENTRY(tag, d1, d2, d3) \
  95. { \
  96. ULONG ThisLog = NextLog(); \
  97. Log[ThisLog].Tag = (tag); \
  98. Log[ThisLog].Line = __LINE__; \
  99. Log[ThisLog].Data[0] = (ULONG_PTR)(d1); \
  100. Log[ThisLog].Data[1] = (ULONG_PTR)(d2); \
  101. Log[ThisLog].Data[2] = (ULONG_PTR)(d3); \
  102. }
  103. #else
  104. #define LOG_ENTRY(tag, d1, d2, d3)
  105. #endif
  106. #if LIST_CHECKING
  107. PLIST_ENTRY FASTCALL MyInterlockedInsertHeadList(PLIST_ENTRY Head, PLIST_ENTRY Entry, PNDIS_SPIN_LOCK SpinLock);
  108. PLIST_ENTRY FASTCALL MyInterlockedInsertTailList(PLIST_ENTRY Head, PLIST_ENTRY Entry, PNDIS_SPIN_LOCK SpinLock);
  109. PLIST_ENTRY FASTCALL MyInterlockedRemoveHeadList(PLIST_ENTRY Head, PNDIS_SPIN_LOCK SpinLock);
  110. VOID FASTCALL CheckList(PLIST_ENTRY ListHead);
  111. #define CheckedRemoveEntryList(Entry) {\
  112. PLIST_ENTRY _EX_Blink;\
  113. PLIST_ENTRY _EX_Flink;\
  114. PLIST_ENTRY _EX_Entry;\
  115. CheckList(Entry);\
  116. _EX_Entry = (Entry);\
  117. _EX_Flink = _EX_Entry->Flink;\
  118. _EX_Blink = _EX_Entry->Blink;\
  119. _EX_Blink->Flink = _EX_Flink;\
  120. _EX_Flink->Blink = _EX_Blink;\
  121. _EX_Entry->Flink = _EX_Entry->Blink = NULL; \
  122. }
  123. #ifdef RemoveEntryList
  124. #undef RemoveEntryList
  125. #endif
  126. #define RemoveEntryList CheckedRemoveEntryList
  127. #define CheckedInsertHeadList(ListHead,Entry) {\
  128. PLIST_ENTRY _EX_Flink;\
  129. PLIST_ENTRY _EX_ListHead;\
  130. CheckList(ListHead);\
  131. _EX_ListHead = (ListHead);\
  132. _EX_Flink = _EX_ListHead->Flink;\
  133. (Entry)->Flink = _EX_Flink;\
  134. (Entry)->Blink = _EX_ListHead;\
  135. _EX_Flink->Blink = (Entry);\
  136. _EX_ListHead->Flink = (Entry);\
  137. CheckList(ListHead);\
  138. }
  139. #ifdef InsertHeadList
  140. #undef InsertHeadList
  141. #endif
  142. #define InsertHeadList CheckedInsertHeadList
  143. #define CheckedInsertTailList(ListHead,Entry) {\
  144. PLIST_ENTRY _EX_Blink;\
  145. PLIST_ENTRY _EX_ListHead;\
  146. CheckList(ListHead);\
  147. _EX_ListHead = (ListHead);\
  148. _EX_Blink = _EX_ListHead->Blink;\
  149. (Entry)->Flink = _EX_ListHead;\
  150. (Entry)->Blink = _EX_Blink;\
  151. _EX_Blink->Flink = (Entry);\
  152. _EX_ListHead->Blink = (Entry);\
  153. CheckList(ListHead);\
  154. }
  155. #ifdef InsertTailList
  156. #undef InsertTailList
  157. #endif
  158. #define InsertTailList CheckedInsertTailList
  159. #define CheckedRemoveHeadList(ListHead) \
  160. (ListHead)->Flink;\
  161. if(!IsListEmpty(ListHead)){ \
  162. RemoveEntryList((ListHead)->Flink);\
  163. CheckList(ListHead);\
  164. }
  165. #ifdef RemoveHeadList
  166. #undef RemoveHeadList
  167. #endif
  168. #define RemoveHeadList CheckedRemoveHeadList
  169. #define CheckedRemoveTailList(ListHead) \
  170. (ListHead)->Blink;\
  171. if(!IsListEmpty(ListHead)){ \
  172. RemoveEntryList((ListHead)->Blink);\
  173. CheckList(ListHead);\
  174. }
  175. #ifdef RemoveTailList
  176. #undef RemoveTailList
  177. #endif
  178. #define RemoveTailList CheckedRemoveTailList
  179. #else // ! LIST_CHECKING
  180. #define CheckList(h)
  181. #define MyInterlockedInsertHeadList NdisInterlockedInsertHeadList
  182. #define MyInterlockedInsertTailList NdisInterlockedInsertTailList
  183. #define MyInterlockedRemoveHeadList NdisInterlockedRemoveHeadList
  184. #endif
  185. #if MEM_CHECKING
  186. #define MyMemAlloc(size) _MyMemAlloc((size),__FILE__,__LINE__)
  187. PVOID _MyMemAlloc(UINT, PUCHAR, UINT);
  188. VOID InitMemory();
  189. VOID DeinitMemory();
  190. #else
  191. PVOID MyMemAlloc(UINT);
  192. #endif
  193. #endif // _DEBUG_H_