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.

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