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.

684 lines
21 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. This module contains debug-specific declarations.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #ifndef _DEBUG_H_
  12. #define _DEBUG_H_
  13. // #if DBG
  14. #if 0
  15. //
  16. // Initialization/termination functions.
  17. //
  18. VOID
  19. UlDbgInitializeDebugData(
  20. VOID
  21. );
  22. VOID
  23. UlDbgTerminateDebugData(
  24. VOID
  25. );
  26. //
  27. // Driver entry/exit notifications.
  28. //
  29. VOID
  30. UlDbgEnterDriver(
  31. IN PSTR pFunctionName,
  32. IN PIRP pIrp OPTIONAL,
  33. IN PSTR pFileName,
  34. IN USHORT LineNumber
  35. );
  36. VOID
  37. UlDbgLeaveDriver(
  38. IN PSTR pFunctionName,
  39. IN PSTR pFileName,
  40. IN USHORT LineNumber
  41. );
  42. #define UL_ENTER_DRIVER( function, pirp ) \
  43. UlDbgEnterDriver( \
  44. (function), \
  45. (pirp), \
  46. __FILE__, \
  47. __LINE__ \
  48. )
  49. #define UL_LEAVE_DRIVER( function ) \
  50. UlDbgLeaveDriver( \
  51. (function), \
  52. __FILE__, \
  53. __LINE__ \
  54. )
  55. //
  56. // An instrumented resource.
  57. //
  58. #define MAX_RESOURCE_NAME_LENGTH 64
  59. typedef struct _UL_ERESOURCE
  60. {
  61. //
  62. // The actual resource.
  63. //
  64. // N.B. This must be the first entry in the structure to make the
  65. // debugger extension work properly!
  66. //
  67. ERESOURCE Resource;
  68. //
  69. // Links onto the global resource list.
  70. //
  71. LIST_ENTRY GlobalResourceListEntry;
  72. //
  73. // Pointer to the thread that owns this lock exclusively.
  74. //
  75. PETHREAD pExclusiveOwner;
  76. //
  77. // Statistics.
  78. //
  79. LONG ExclusiveCount;
  80. LONG SharedCount;
  81. LONG ReleaseCount;
  82. //
  83. // The name of the resource, for display purposes.
  84. //
  85. UCHAR ResourceName[MAX_RESOURCE_NAME_LENGTH];
  86. } UL_ERESOURCE, *PUL_ERESOURCE;
  87. NTSTATUS
  88. UlDbgInitializeResource(
  89. IN PUL_ERESOURCE pResource,
  90. IN PSTR pResourceName,
  91. IN ULONG_PTR Parameter,
  92. IN PSTR pFileName,
  93. IN USHORT LineNumber
  94. );
  95. NTSTATUS
  96. UlDbgDeleteResource(
  97. IN PUL_ERESOURCE pResource,
  98. IN PSTR pFileName,
  99. IN USHORT LineNumber
  100. );
  101. BOOLEAN
  102. UlDbgAcquireResourceExclusive(
  103. IN PUL_ERESOURCE pResource,
  104. IN BOOLEAN Wait,
  105. IN PSTR pFileName,
  106. IN USHORT LineNumber
  107. );
  108. BOOLEAN
  109. UlDbgAcquireResourceShared(
  110. IN PUL_ERESOURCE pResource,
  111. IN BOOLEAN Wait,
  112. IN PSTR pFileName,
  113. IN USHORT LineNumber
  114. );
  115. VOID
  116. UlDbgReleaseResource(
  117. IN PUL_ERESOURCE pResource,
  118. IN PSTR pFileName,
  119. IN USHORT LineNumber
  120. );
  121. BOOLEAN
  122. UlDbgResourceOwnedExclusive(
  123. IN PUL_ERESOURCE pResource
  124. );
  125. BOOLEAN
  126. UlDbgResourceUnownedExclusive(
  127. IN PUL_ERESOURCE pResource
  128. );
  129. #define UlInitializeResource( resource, name, param ) \
  130. UlDbgInitializeResource( \
  131. (resource), \
  132. (name), \
  133. (ULONG_PTR)(param), \
  134. __FILE__, \
  135. __LINE__ \
  136. )
  137. #define UlDeleteResource( resource ) \
  138. UlDbgDeleteResource( \
  139. (resource), \
  140. __FILE__, \
  141. __LINE__ \
  142. )
  143. #define UlAcquireResourceExclusive( resource, wait ) \
  144. UlDbgAcquireResourceExclusive( \
  145. (resource), \
  146. (wait), \
  147. __FILE__, \
  148. __LINE__ \
  149. )
  150. #define UlAcquireResourceShared( resource, wait ) \
  151. UlDbgAcquireResourceShared( \
  152. (resource), \
  153. (wait), \
  154. __FILE__, \
  155. __LINE__ \
  156. )
  157. #define UlReleaseResource( resource ) \
  158. UlDbgReleaseResource( \
  159. (resource), \
  160. __FILE__, \
  161. __LINE__ \
  162. )
  163. #define IS_RESOURCE_INITIALIZED( resource ) \
  164. ((resource)->Resource.SystemResourcesList.Flink != NULL)
  165. //
  166. // An instrumented spinlock.
  167. //
  168. typedef struct _UL_SPIN_LOCK // SpinLock
  169. {
  170. //
  171. // The actual lock.
  172. //
  173. // N.B. This must be the first entry in the structure to make the
  174. // debugger extension work properly!
  175. //
  176. KSPIN_LOCK KSpinLock;
  177. //
  178. // The name of the spinlock, for display purposes.
  179. //
  180. PSTR pSpinLockName;
  181. //
  182. // Pointer to the thread that owns this lock.
  183. //
  184. PETHREAD pOwnerThread;
  185. //
  186. // Statistics.
  187. //
  188. PSTR pLastAcquireFileName;
  189. PSTR pLastReleaseFileName;
  190. USHORT LastAcquireLineNumber;
  191. USHORT LastReleaseLineNumber;
  192. ULONG OwnerProcessor;
  193. LONG Acquisitions;
  194. LONG Releases;
  195. LONG AcquisitionsAtDpcLevel;
  196. LONG ReleasesFromDpcLevel;
  197. LONG Spare;
  198. } UL_SPIN_LOCK, *PUL_SPIN_LOCK;
  199. #define KSPIN_LOCK_FROM_UL_SPIN_LOCK( pLock ) \
  200. &((pLock)->KSpinLock)
  201. VOID
  202. UlDbgInitializeSpinLock(
  203. IN PUL_SPIN_LOCK pSpinLock,
  204. IN PSTR pSpinLockName,
  205. IN PSTR pFileName,
  206. IN USHORT LineNumber
  207. );
  208. VOID
  209. UlDbgAcquireSpinLock(
  210. IN PUL_SPIN_LOCK pSpinLock,
  211. OUT PKIRQL pOldIrql,
  212. IN PSTR pFileName,
  213. IN USHORT LineNumber
  214. );
  215. VOID
  216. UlDbgReleaseSpinLock(
  217. IN PUL_SPIN_LOCK pSpinLock,
  218. IN KIRQL OldIrql,
  219. IN PSTR pFileName,
  220. IN USHORT LineNumber
  221. );
  222. VOID
  223. UlDbgAcquireSpinLockAtDpcLevel(
  224. IN PUL_SPIN_LOCK pSpinLock,
  225. IN PSTR pFileName,
  226. IN USHORT LineNumber
  227. );
  228. VOID
  229. UlDbgReleaseSpinLockFromDpcLevel(
  230. IN PUL_SPIN_LOCK pSpinLock,
  231. IN PSTR pFileName,
  232. IN USHORT LineNumber
  233. );
  234. BOOLEAN
  235. UlDbgSpinLockOwned(
  236. IN PUL_SPIN_LOCK pSpinLock
  237. );
  238. BOOLEAN
  239. UlDbgSpinLockUnowned(
  240. IN PUL_SPIN_LOCK pSpinLock
  241. );
  242. #define UlInitializeSpinLock( spinlock, name ) \
  243. UlDbgInitializeSpinLock( \
  244. (spinlock), \
  245. (name), \
  246. __FILE__, \
  247. __LINE__ \
  248. )
  249. #define UlAcquireSpinLock( spinlock, oldirql ) \
  250. UlDbgAcquireSpinLock( \
  251. (spinlock), \
  252. (oldirql), \
  253. __FILE__, \
  254. __LINE__ \
  255. )
  256. #define UlReleaseSpinLock( spinlock, oldirql ) \
  257. UlDbgReleaseSpinLock( \
  258. (spinlock), \
  259. (oldirql), \
  260. __FILE__, \
  261. __LINE__ \
  262. )
  263. #define UlAcquireSpinLockAtDpcLevel( spinlock ) \
  264. UlDbgAcquireSpinLockAtDpcLevel( \
  265. (spinlock), \
  266. __FILE__, \
  267. __LINE__ \
  268. )
  269. #define UlReleaseSpinLockFromDpcLevel( spinlock ) \
  270. UlDbgReleaseSpinLockFromDpcLevel( \
  271. (spinlock), \
  272. __FILE__, \
  273. __LINE__ \
  274. )
  275. //
  276. // Debug spew control.
  277. // If you change or add a flag, please update the FlagTable
  278. // in ul\test\dll\tul.c.
  279. //
  280. #undef IF_DEBUG
  281. #define IF_DEBUG(a) if ( (UL_DEBUG_ ## a & g_UlDebug) != 0 )
  282. #define UL_DEBUG_OPEN_CLOSE 0x00000001
  283. #define UL_DEBUG_SEND_RESPONSE 0x00000002
  284. #define UL_DEBUG_SEND_BUFFER 0x00000004
  285. #define UL_DEBUG_TDI 0x00000008
  286. #define UL_DEBUG_FILE_CACHE 0x00000010
  287. #define UL_DEBUG_CONFIG_GROUP_FNC 0x00000020
  288. #define UL_DEBUG_CONFIG_GROUP_TREE 0x00000040
  289. #define UL_DEBUG_REFCOUNT 0x00000080
  290. #define UL_DEBUG_HTTP_IO 0x00000100
  291. #define UL_DEBUG_ROUTING 0x00000200
  292. #define UL_DEBUG_URI_CACHE 0x00000400
  293. #define UL_DEBUG_PARSER 0x00000800
  294. #define UL_DEBUG_SITE 0x00001000
  295. #define UL_DEBUG_WORK_ITEM 0x00002000
  296. #define UL_DEBUG_PARSER2 0x80000000
  297. #define DEBUG
  298. //
  299. // Tracing.
  300. //
  301. #define UlTrace(a, _b_) \
  302. do \
  303. { \
  304. IF_DEBUG(##a) \
  305. { \
  306. DbgPrint _b_ ; \
  307. } \
  308. } while (FALSE)
  309. //
  310. // Debug pool allocator.
  311. //
  312. PVOID
  313. UlDbgAllocatePool (
  314. IN POOL_TYPE PoolType,
  315. IN SIZE_T NumberOfBytes,
  316. IN ULONG Tag,
  317. IN PSTR pFileName,
  318. IN USHORT LineNumber
  319. );
  320. VOID
  321. UlDbgFreePool (
  322. IN PVOID pPointer,
  323. IN ULONG Tag
  324. );
  325. #define UL_ALLOCATE_POOL( type, len, tag ) \
  326. UlDbgAllocatePool( \
  327. (type), \
  328. (len), \
  329. (tag), \
  330. __FILE__, \
  331. __LINE__ \
  332. )
  333. #define UL_FREE_POOL( ptr, tag ) \
  334. UlDbgFreePool( \
  335. (ptr), \
  336. (tag) \
  337. )
  338. //
  339. // Exception filter.
  340. //
  341. LONG
  342. UlDbgExceptionFilter(
  343. IN PEXCEPTION_POINTERS pExceptionPointers,
  344. IN PSTR pFileName,
  345. IN USHORT LineNumber
  346. );
  347. #define UL_EXCEPTION_FILTER() \
  348. UlDbgExceptionFilter( \
  349. GetExceptionInformation(), \
  350. (PSTR)__FILE__, \
  351. (USHORT)__LINE__ \
  352. )
  353. //
  354. // Invalid completion routine for catching incomplete IRP contexts.
  355. //
  356. VOID
  357. UlDbgInvalidCompletionRoutine(
  358. IN PVOID pCompletionContext,
  359. IN NTSTATUS Status,
  360. IN ULONG_PTR Information
  361. );
  362. //
  363. // Error handlers.
  364. //
  365. NTSTATUS
  366. UlDbgStatus(
  367. IN NTSTATUS Status,
  368. IN PSTR pFileName,
  369. IN USHORT LineNumber
  370. );
  371. #define RETURN(status) \
  372. return UlDbgStatus( \
  373. (status), \
  374. __FILE__, \
  375. __LINE__ \
  376. )
  377. #define CHECK_STATUS(status) \
  378. UlDbgStatus( \
  379. (status), \
  380. (PSTR)__FILE__, \
  381. (USHORT)__LINE__ \
  382. )
  383. //
  384. // Random structure dumpers.
  385. //
  386. VOID
  387. UlDbgDumpRequestBuffer(
  388. IN struct _UL_REQUEST_BUFFER *pBuffer,
  389. IN PSTR pName
  390. );
  391. VOID
  392. UlDbgDumpHttpConnection(
  393. IN struct _HTTP_CONNECTION *pConnection,
  394. IN PSTR pName
  395. );
  396. //
  397. // IO wrappers.
  398. //
  399. PIRP
  400. UlDbgAllocateIrp(
  401. IN CCHAR StackSize,
  402. IN BOOLEAN ChargeQuota,
  403. IN PSTR pFileName,
  404. IN USHORT LineNumber
  405. );
  406. VOID
  407. UlDbgFreeIrp(
  408. IN PIRP pIrp,
  409. IN PSTR pFileName,
  410. IN USHORT LineNumber
  411. );
  412. NTSTATUS
  413. UlDbgCallDriver(
  414. IN PDEVICE_OBJECT pDeviceObject,
  415. IN OUT PIRP pIrp,
  416. IN PSTR pFileName,
  417. IN USHORT LineNumber
  418. );
  419. VOID
  420. UlDbgCompleteRequest(
  421. IN PIRP pIrp,
  422. IN CCHAR PriorityBoost,
  423. IN PSTR pFileName,
  424. IN USHORT LineNumber
  425. );
  426. #define UlAllocateIrp( stack, quota ) \
  427. UlDbgAllocateIrp( \
  428. (stack), \
  429. (quota), \
  430. (PSTR)__FILE__, \
  431. (USHORT)__LINE__ \
  432. )
  433. #define UlFreeIrp( pirp ) \
  434. UlDbgFreeIrp( \
  435. (pirp), \
  436. (PSTR)__FILE__, \
  437. (USHORT)__LINE__ \
  438. )
  439. #define UlCallDriver( pdevice, pirp ) \
  440. UlDbgCallDriver( \
  441. (pdevice), \
  442. (pirp), \
  443. (PSTR)__FILE__, \
  444. (USHORT)__LINE__ \
  445. )
  446. #define UlCompleteRequest( pirp, boost ) \
  447. UlDbgCompleteRequest( \
  448. (pirp), \
  449. (boost), \
  450. (PSTR)__FILE__, \
  451. (USHORT)__LINE__ \
  452. )
  453. #else // !DBG
  454. //
  455. // Disable all of the above.
  456. //
  457. #define UL_ENTER_DRIVER( function, pirp )
  458. #define UL_LEAVE_DRIVER( function )
  459. #define UL_ERESOURCE ERESOURCE
  460. #define PUL_ERESOURCE PERESOURCE
  461. #define UlInitializeResource( resource, name, param ) \
  462. ExInitializeResource( (resource) )
  463. #define UlDeleteResource( resource ) \
  464. ExDeleteResource( (resource) )
  465. #define UlAcquireResourceExclusive( resource, wait ) \
  466. do \
  467. { \
  468. KeEnterCriticalRegion(); \
  469. ExAcquireResourceExclusive( (resource), (wait) ); \
  470. } while (FALSE)
  471. #define UlAcquireResourceShared( resource, wait ) \
  472. do \
  473. { \
  474. KeEnterCriticalRegion(); \
  475. ExAcquireResourceShared( (resource), (wait) ); \
  476. } while (FALSE)
  477. #define UlReleaseResource( resource ) \
  478. do \
  479. { \
  480. ExReleaseResource( (resource) ); \
  481. KeLeaveCriticalRegion(); \
  482. } while (FALSE)
  483. #define IS_RESOURCE_INITIALIZED( resource ) \
  484. ((resource)->SystemResourcesList.Flink != NULL)
  485. #define UL_SPIN_LOCK KSPIN_LOCK
  486. #define PUL_SPIN_LOCK PKSPIN_LOCK
  487. #define KSPIN_LOCK_FROM_UL_SPIN_LOCK( pLock ) (pLock)
  488. #define UlInitializeSpinLock( spinlock, name ) \
  489. KeInitializeSpinLock( (spinlock) )
  490. #define UlAcquireSpinLock( spinlock, oldirql ) \
  491. KeAcquireSpinLock( (spinlock), (oldirql) )
  492. #define UlReleaseSpinLock( spinlock, oldirql ) \
  493. KeReleaseSpinLock( (spinlock), (oldirql) )
  494. #define UlAcquireSpinLockAtDpcLevel( spinlock ) \
  495. KeAcquireSpinLockAtDpcLevel( (spinlock) )
  496. #define UlReleaseSpinLockFromDpcLevel( spinlock ) \
  497. KeReleaseSpinLockFromDpcLevel( (spinlock) )
  498. #undef IF_DEBUG
  499. #define IF_DEBUG(a) if (FALSE)
  500. #define DEBUG if ( FALSE )
  501. #define UlTrace(a, _b_) \
  502. // do {printf _b_; printf( " - line #%d.\n", __LINE__ ); } while(0)
  503. #define UL_ALLOCATE_POOL( type, len, tag ) \
  504. HeapAlloc( GetProcessHeap(), 0 , (len) )
  505. #define UL_FREE_POOL( ptr, tag ) \
  506. HeapFree( GetProcessHeap(), 0 , (ptr) )
  507. #define UL_EXCEPTION_FILTER() EXCEPTION_EXECUTE_HANDLER
  508. #define RETURN(status) return (status)
  509. #define CHECK_STATUS(Status)
  510. #define UlAllocateIrp( stack, quota ) \
  511. IoAllocateIrp( (stack), (quota) )
  512. #define UlFreeIrp( pirp ) \
  513. IoFreeIrp( (pirp) )
  514. #define UlCallDriver( pdevice, pirp ) \
  515. IoCallDriver( (pdevice), (pirp) )
  516. #define UlCompleteRequest( pirp, boost ) \
  517. IoCompleteRequest( (pirp), (boost) )
  518. #endif // DBG
  519. // BUGBUG: ALIGN_UP(PVOID) won't work, it needs to be the type of the first entry of the
  520. // following data (paulmcd 4/29/99)
  521. #define UL_ALLOCATE_STRUCT_WITH_SPACE(pt,ot,cb,t) \
  522. (ot *)(UL_ALLOCATE_POOL(pt,ALIGN_UP(sizeof(ot),PVOID)+(cb),t))
  523. #define UL_ALLOCATE_STRUCT(pt,ot,t) \
  524. (ot *)(UL_ALLOCATE_POOL(pt,sizeof(ot),t))
  525. #define UL_ALLOCATE_ARRAY(pt,et,c,t) \
  526. (et *)(UL_ALLOCATE_POOL(pt,sizeof(et)*(c),t))
  527. #define UL_FREE_POOL_WITH_SIG(a,t) \
  528. do { \
  529. (a)->Signature = MAKE_FREE_TAG(t); \
  530. UL_FREE_POOL(a,t); \
  531. (a) = NULL; \
  532. } while (0)
  533. #endif // _DEBUG_H_