Leaked source code of windows server 2003
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.

206 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. dbgtrack.h
  5. Abstract:
  6. Implements macros and declares functions for resource tracking apis.
  7. Author:
  8. Jim Schmidt (jimschm) 18-Jun-2001
  9. Revision History:
  10. --*/
  11. #ifndef RC_INVOKED
  12. #pragma once
  13. #ifdef _cplusplus
  14. extern "C" {
  15. #endif
  16. //
  17. // Macros
  18. //
  19. #ifdef DEBUG
  20. #undef INITIALIZE_DBGTRACK_CODE
  21. #define INITIALIZE_DBGTRACK_CODE if (!DbgInitTracking()) { __leave; }
  22. #undef TERMINATE_DBGTRACK_CODE
  23. #define TERMINATE_DBGTRACK_CODE DbgTerminateTracking();
  24. #define ALLOCATION_TRACKING_DEF , PCSTR File, UINT Line
  25. #define ALLOCATION_TRACKING_CALL ,__FILE__,__LINE__
  26. #define ALLOCATION_TRACKING_INLINE_CALL ,File,Line
  27. #define DISABLETRACKCOMMENT() DbgDisableTrackComment()
  28. #define ENABLETRACKCOMMENT() DbgEnableTrackComment()
  29. #define DBGTRACK_BEGIN(type,name) DbgTrack##type(DbgTrackPush(#name,__FILE__,__LINE__) ? (type) 0 : (
  30. #define DBGTRACK_END() ))
  31. #define DBGTRACK(type,fnname,fnargs) (DBGTRACK_BEGIN(type,logname) Real##fnname fnargs DBGTRACK_END())
  32. #else
  33. #undef INITIALIZE_DBGTRACK_CODE
  34. #define INITIALIZE_DBGTRACK_CODE
  35. #undef TERMINATE_DBGTRACK_CODE
  36. #define TERMINATE_DBGTRACK_CODE
  37. #define DISABLETRACKCOMMENT()
  38. #define ENABLETRACKCOMMENT()
  39. #define DBGTRACK_BEGIN(type,name)
  40. #define DBGTRACK_END()
  41. #define DBGTRACK(type,fnname,fnargs) (Real##fnname fnargs)
  42. #define ALLOCATION_TRACKING_DEF
  43. #define ALLOCATION_TRACKING_CALL
  44. #define ALLOCATION_TRACKING_INLINE_CALL
  45. #define DbgInitTracking()
  46. #define DbgTerminateTracking()
  47. #define DbgRegisterAllocation(t,p,f,l)
  48. #define DbgUnregisterAllocation(t,p)
  49. #endif
  50. //
  51. // Types
  52. //
  53. typedef enum {
  54. //
  55. // Add types here if you call DbgRegisterAllocation yourself
  56. // (for example, you are wrapping acess to a handle).
  57. //
  58. RAW_MEMORY
  59. } ALLOCTYPE;
  60. //
  61. // List of the basic types for the routines that are tracked.
  62. // This list generates inline functions for the tracking macros.
  63. // Inline functions for other types are defined in the header
  64. // file.
  65. //
  66. //
  67. // include this for HINF
  68. //
  69. #include <setupapi.h>
  70. #define TRACK_WRAPPERS \
  71. DBGTRACK_DECLARE(PBYTE) \
  72. DBGTRACK_DECLARE(DWORD) \
  73. DBGTRACK_DECLARE(BOOL) \
  74. DBGTRACK_DECLARE(UINT) \
  75. DBGTRACK_DECLARE(PCSTR) \
  76. DBGTRACK_DECLARE(PCWSTR) \
  77. DBGTRACK_DECLARE(PVOID) \
  78. DBGTRACK_DECLARE(PSTR) \
  79. DBGTRACK_DECLARE(PWSTR) \
  80. DBGTRACK_DECLARE(HINF) \
  81. //
  82. // Public function prototypes
  83. //
  84. #ifdef DEBUG
  85. BOOL
  86. DbgInitTracking (
  87. VOID
  88. );
  89. VOID
  90. DbgTerminateTracking (
  91. VOID
  92. );
  93. VOID
  94. DbgRegisterAllocation (
  95. IN ALLOCTYPE Type,
  96. IN PVOID Ptr,
  97. IN PCSTR File,
  98. IN UINT Line
  99. );
  100. VOID
  101. DbgUnregisterAllocation (
  102. ALLOCTYPE Type,
  103. PCVOID Ptr
  104. );
  105. VOID
  106. DbgDisableTrackComment (
  107. VOID
  108. );
  109. VOID
  110. DbgEnableTrackComment (
  111. VOID
  112. );
  113. INT
  114. DbgTrackPushEx (
  115. IN PCSTR Name,
  116. IN PCSTR File,
  117. IN UINT Line,
  118. IN BOOL DupFileString
  119. );
  120. #define DbgTrackPush(name,file,line) DbgTrackPushEx(name,file,line,FALSE)
  121. INT
  122. DbgTrackPop (
  123. VOID
  124. );
  125. VOID
  126. DbgTrackDump (
  127. VOID
  128. );
  129. #define DBGTRACKPUSH(n,f,l) DbgTrackPush(n,f,l)
  130. #define DBGTRACKPUSHEX(n,f,l,d) DbgTrackPushEx(n,f,l,d)
  131. #define DBGTRACKPOP() DbgTrackPop()
  132. #define DBGTRACKDUMP() DbgTrackDump()
  133. //
  134. // Macro expansion definition
  135. //
  136. #define DBGTRACK_DECLARE(type) __inline type DbgTrack##type (type Arg) {DbgTrackPop(); return Arg;}
  137. TRACK_WRAPPERS
  138. #else // i.e., if !DEBUG
  139. #define DBGTRACKPUSH(n,f,l)
  140. #define DBGTRACKPUSHEX(n,f,l,d)
  141. #define DBGTRACKPOP()
  142. #define DBGTRACKDUMP()
  143. #define DBGTRACK_DECLARE(type)
  144. #endif
  145. #ifdef _cplusplus
  146. }
  147. #endif
  148. #endif