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.

325 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Debug macros for the ARP module
  7. Revision History:
  8. Notes:
  9. --*/
  10. #ifndef __RT_DEBUG_H__
  11. #define __RT_DEBUG_H__
  12. VOID
  13. RtInitializeDebug();
  14. //
  15. // Tags for Pools
  16. //
  17. #define GROUP_TAG 'gmPI'
  18. #define SOURCE_TAG 'smPI'
  19. #define OIF_TAG 'omPI'
  20. #define MSG_TAG 'mmPI'
  21. #define FREE_TAG 'fmPI'
  22. //
  23. // File signatures for everyone
  24. //
  25. #define DEBUG_SIG 'gbed'
  26. #define INI_SIG 'tini'
  27. #define IOCT_SIG 'tcoi'
  28. #define MFE_SIG 'efmm'
  29. #define FWD_SIG 'dwfm'
  30. #define TMR_SIG 'rmit'
  31. //
  32. // We use the RT_XXX_DEBUG flags so that we can force to
  33. // different debug modes on free builds by changing sources.
  34. // On a checked build, all debugging is on
  35. //
  36. #if DBG
  37. #ifndef RT_TRACE_DEBUG
  38. #define RT_TRACE_DEBUG 1
  39. #endif
  40. #ifndef RT_LOCK_DEBUG
  41. #define RT_LOCK_DEBUG 1
  42. #endif
  43. #ifndef RT_ASSERT_ON
  44. #define RT_ASSERT_ON 1
  45. #endif
  46. #ifndef RT_MEM_DEBUG
  47. #define RT_MEM_DEBUG 1
  48. #endif
  49. #else // DBG
  50. #ifndef RT_TRACE_DEBUG
  51. #define RT_TRACE_DEBUG 0
  52. #endif
  53. #ifndef RT_LOCK_DEBUG
  54. #define RT_LOCK_DEBUG 0
  55. #endif
  56. #ifndef RT_ASSERT_ON
  57. #define RT_ASSERT_ON 0
  58. #endif
  59. #ifndef RT_MEM_DEBUG
  60. #define RT_MEM_DEBUG 0
  61. #endif
  62. #endif // DBG
  63. #if RT_ASSERT_ON
  64. #define RtAssert(X) \
  65. { \
  66. if(!(X)) \
  67. { \
  68. DbgPrint("[IPMCAST] Assertion failed in %s at line %d\n",\
  69. __FILE__,__LINE__); \
  70. DbgPrint("IPMCAST: Assertion " #X "\n"); \
  71. DbgBreakPoint(); \
  72. } \
  73. }
  74. #else // RT_ASSERT_ON
  75. #define RtAssert(X)
  76. #endif
  77. #if RT_TRACE_DEBUG
  78. BYTE g_byDebugLevel;
  79. DWORD g_fDebugComp;
  80. #define MCAST_STREAM_GLOBAL 0x00000001
  81. #define MCAST_STREAM_SEND 0x00000002
  82. #define MCAST_STREAM_RCV 0x00000004
  83. #define MCAST_STREAM_MFE 0x00000008
  84. #define MCAST_STREAM_MEMORY 0x00000010
  85. #define MCAST_STREAM_IF 0x00000020
  86. #define MCAST_STREAM_FWD 0x00000040
  87. #define MCAST_STREAM_TMR 0x00000080
  88. #define RT_DBG_LEVEL_NONE 0xFF
  89. #define RT_DBG_LEVEL_FATAL 0xF0
  90. #define RT_DBG_LEVEL_ERROR 0xE0
  91. #define RT_DBG_LEVEL_WARN 0xD0
  92. #define RT_DBG_LEVEL_INFO 0xC0
  93. #define RT_DBG_LEVEL_TRACE 0xB0
  94. #define Trace(Stream, Level, Str) \
  95. { \
  96. if ((RT_DBG_LEVEL_##Level >= RT_DBG_LEVEL_ERROR) || \
  97. ((RT_DBG_LEVEL_##Level >= g_byDebugLevel) && \
  98. ((g_fDebugComp & MCAST_STREAM_##Stream) == MCAST_STREAM_##Stream)))\
  99. { \
  100. DbgPrint("[IPMCAST] "); \
  101. DbgPrint Str; \
  102. } \
  103. }
  104. #define TraceEnter(Stream, Str) Trace(Stream, TRACE, ("Entering "Str"\n"))
  105. #define TraceLeave(Stream, Str) Trace(Stream, TRACE, ("Leaving "Str"\n"))
  106. #else // RT_TRACE_DEBUG
  107. #define Trace(Stream, Level, Str)
  108. #define TraceEnter(Stream, Str)
  109. #define TraceLeave(Stream, Str)
  110. #endif // RT_TRACE_DEBUG
  111. #if RT_LOCK_DEBUG
  112. extern KSPIN_LOCK g_ksLockLock;
  113. #ifndef __FILE_SIG__
  114. #error File signature not defined
  115. #endif
  116. typedef struct _RT_LOCK
  117. {
  118. ULONG ulLockSig;
  119. BOOLEAN bAcquired;
  120. PKTHREAD pktLastThread;
  121. ULONG ulFileSig;
  122. ULONG ulLineNumber;
  123. KSPIN_LOCK kslLock;
  124. }RT_LOCK, *PRT_LOCK;
  125. VOID
  126. RtpInitializeSpinLock(
  127. IN PRT_LOCK pLock,
  128. IN ULONG ulFileSig,
  129. IN ULONG ulLineNumber
  130. );
  131. VOID
  132. RtpAcquireSpinLock(
  133. IN PRT_LOCK pLock,
  134. OUT PKIRQL pkiIrql,
  135. IN ULONG ulFileSig,
  136. IN ULONG ulLineNumber,
  137. IN BOOLEAN bAtDpc
  138. );
  139. VOID
  140. RtpReleaseSpinLock(
  141. IN PRT_LOCK pLock,
  142. IN KIRQL kiIrql,
  143. IN ULONG ulFileSig,
  144. IN ULONG ulLineNumber,
  145. IN BOOLEAN bFromDpc
  146. );
  147. #define RT_LOCK_SIG 'KCOL'
  148. #define RtInitializeSpinLock(X) RtpInitializeSpinLock((X), __FILE_SIG__, __LINE__)
  149. #define RtAcquireSpinLock(X, Y) RtpAcquireSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  150. #define RtAcquireSpinLockAtDpcLevel(X) RtpAcquireSpinLock((X), NULL, __FILE_SIG__, __LINE__, TRUE)
  151. #define RtReleaseSpinLock(X, Y) RtpReleaseSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  152. #define RtReleaseSpinLockFromDpcLevel(X) RtpReleaseSpinLock((X), 0, __FILE_SIG__, __LINE__, TRUE)
  153. #else // RT_LOCK_DEBUG
  154. typedef KSPIN_LOCK RT_LOCK, *PRT_LOCK;
  155. #define RtInitializeSpinLock KeInitializeSpinLock
  156. #define RtAcquireSpinLock KeAcquireSpinLock
  157. #define RtAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
  158. #define RtReleaseSpinLock KeReleaseSpinLock
  159. #define RtReleaseSpinLockFromDpcLevel KeReleaseSpinLockFromDpcLevel
  160. #endif // RT_LOCK_DEBUG
  161. #if RT_MEM_DEBUG
  162. #ifndef __FILE_SIG__
  163. #error File signature not defined
  164. #endif
  165. //
  166. // Memory Allocation/Freeing Audit:
  167. //
  168. //
  169. // The RT_ALLOCATION structure stores all info about one allocation
  170. //
  171. typedef struct _RT_ALLOCATION
  172. {
  173. LIST_ENTRY leLink;
  174. ULONG ulMemSig;
  175. ULONG ulFileSig;
  176. ULONG ulLineNumber;
  177. ULONG ulSize;
  178. UCHAR pucData[1];
  179. }RT_ALLOCATION, *PRT_ALLOCATION;
  180. //
  181. // The RT_FREE structure stores info about an allocation
  182. // that was freed. Later if the memory is touched, the
  183. // free list can be scanned to see where the allocation was
  184. // freed
  185. //
  186. typedef struct _RT_FREE
  187. {
  188. LIST_ENTRY leLink;
  189. ULONG_PTR ulStartAddr;
  190. ULONG ulSize;
  191. ULONG ulMemSig;
  192. ULONG ulAllocFileSig;
  193. ULONG ulAllocLineNumber;
  194. ULONG ulFreeFileSig;
  195. ULONG ulFreeLineNumber;
  196. }RT_FREE, *PRT_FREE;
  197. #define RT_MEMORY_SIG 'YRMM'
  198. #define RT_FREE_SIG 'EERF'
  199. PVOID
  200. RtpAllocate(
  201. IN POOL_TYPE ptPool,
  202. IN ULONG ulSize,
  203. IN ULONG ulTag,
  204. IN ULONG ulFileSig,
  205. IN ULONG ulLineNumber
  206. );
  207. VOID
  208. RtpFree(
  209. PVOID pvPointer,
  210. IN ULONG ulFileSig,
  211. IN ULONG ulLineNumber
  212. );
  213. VOID
  214. RtAuditMemory();
  215. #define RtAllocate(X, Y, Z) RtpAllocate((X), (Y), (Z), __FILE_SIG__, __LINE__)
  216. #define RtFree(X) RtpFree((X), __FILE_SIG__, __LINE__)
  217. #else // RT_MEM_DEBUG
  218. #define RtAllocate ExAllocatePoolWithTag
  219. #define RtFree ExFreePool
  220. #define RtAuditMemory()
  221. #endif // RT_MEM_DEBUG
  222. #endif // __RT_DEBUG_H__