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.

222 lines
3.7 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. Split from old debug.h
  8. Author:
  9. Marc R. Whitten (marcw) 09-Sep-1999
  10. Revision History:
  11. --*/
  12. #ifndef RC_INVOKED
  13. #pragma once
  14. #ifdef _cplusplus
  15. extern "C" {
  16. #endif
  17. //
  18. // If either DBG or DEBUG defined, use debug mode
  19. //
  20. #ifdef DBG
  21. #ifndef DEBUG
  22. #define DEBUG
  23. #endif
  24. #endif
  25. #ifdef DEBUG
  26. #ifndef DBG
  27. #define DBG
  28. #endif
  29. #endif
  30. //
  31. // Includes
  32. //
  33. // None
  34. //
  35. // Strings
  36. //
  37. // None
  38. //
  39. // Constants
  40. //
  41. //
  42. // Debug-only constants
  43. //
  44. #ifdef DEBUG
  45. // This option makes fat, slow binaries
  46. #define MEMORY_TRACKING
  47. #define ALLOCATION_TRACKING_DEF , PCSTR File, UINT Line
  48. #define ALLOCATION_TRACKING_CALL ,__FILE__,__LINE__
  49. #define ALLOCATION_TRACKING_INLINE_CALL ,File,Line
  50. #endif
  51. //
  52. // Macros
  53. //
  54. #ifdef DEBUG
  55. #define DISABLETRACKCOMMENT() DisableTrackComment()
  56. #define ENABLETRACKCOMMENT() EnableTrackComment()
  57. #define TRACK_BEGIN(type,name) Track##type(TrackPush(#name,__FILE__,__LINE__) ? (type) 0 : (
  58. #define TRACK_END() ))
  59. #define INVALID_POINTER(x) x=NULL
  60. #else
  61. #define DISABLETRACKCOMMENT()
  62. #define ENABLETRACKCOMMENT()
  63. #define TRACK_BEGIN(type,name)
  64. #define TRACK_END()
  65. #define INVALID_POINTER(x)
  66. #define ALLOCATION_TRACKING_DEF
  67. #define ALLOCATION_TRACKING_CALL
  68. #define ALLOCATION_TRACKING_INLINE_CALL
  69. #define InitAllocationTracking()
  70. #define FreeAllocationTracking()
  71. #define DebugRegisterAllocationEx(t,p,f,l,a)
  72. #define DebugRegisterAllocation(t,p,f,l)
  73. #define DebugUnregisterAllocation(t,p)
  74. #endif
  75. //
  76. // Types
  77. //
  78. typedef enum {
  79. MERGE_OBJECT,
  80. POOLMEM_POINTER,
  81. POOLMEM_POOL,
  82. INF_HANDLE
  83. } ALLOCTYPE;
  84. //
  85. // Globals
  86. //
  87. extern PCSTR g_TrackComment;
  88. extern INT g_UseCount;
  89. extern PCSTR g_TrackFile;
  90. extern UINT g_TrackLine;
  91. extern BOOL g_TrackAlloc;
  92. //
  93. // Macro expansion list
  94. //
  95. #define TRACK_WRAPPERS \
  96. DEFMAC(PBYTE) \
  97. DEFMAC(DWORD) \
  98. DEFMAC(BOOL) \
  99. DEFMAC(UINT) \
  100. DEFMAC(PCSTR) \
  101. DEFMAC(PCWSTR) \
  102. DEFMAC(PVOID) \
  103. DEFMAC(PSTR) \
  104. DEFMAC(PWSTR) \
  105. DEFMAC(HINF) \
  106. DEFMAC(PMHANDLE) \
  107. DEFMAC(PGROWBUFFER) \
  108. DEFMAC(PPARSEDPATTERNA) \
  109. DEFMAC(PPARSEDPATTERNW) \
  110. DEFMAC(POBSPARSEDPATTERNA) \
  111. DEFMAC(POBSPARSEDPATTERNW) \
  112. DEFMAC(HASHTABLE) \
  113. //
  114. // Public function prototypes
  115. //
  116. #ifdef DEBUG
  117. VOID InitAllocationTracking (VOID);
  118. VOID FreeAllocationTracking (VOID);
  119. VOID DebugRegisterAllocationEx (ALLOCTYPE Type, PVOID Ptr, PCSTR File, UINT Line, BOOL Alloc);
  120. VOID DebugRegisterAllocation (ALLOCTYPE Type, PVOID Ptr, PCSTR File, UINT Line);
  121. VOID DebugUnregisterAllocation (ALLOCTYPE Type, PVOID Ptr);
  122. VOID DisableTrackComment (VOID);
  123. VOID EnableTrackComment (VOID);
  124. INT TrackPush (PCSTR Name, PCSTR File, UINT Line);
  125. INT TrackPushEx (PCSTR Name, PCSTR File, UINT Line, BOOL Alloc);
  126. INT TrackPop (VOID);
  127. VOID
  128. TrackDump (
  129. VOID
  130. );
  131. #define TRACKPUSH(n,f,l) TrackPush(n,f,l)
  132. #define TRACKPUSHEX(n,f,l,a) TrackPushEx(n,f,l,a)
  133. #define TRACKPOP() TrackPop()
  134. #define TRACKDUMP() TrackDump()
  135. //
  136. // Macro expansion definition
  137. //
  138. #define DEFMAC(type) __inline type Track##type (type Arg) {TrackPop(); return Arg;}
  139. TRACK_WRAPPERS
  140. #undef DEFMAC
  141. #else // i.e., if !DEBUG
  142. #define TRACKPUSH(n,f,l)
  143. #define TRACKPUSHEX(n,f,l,a)
  144. #define TRACKPOP()
  145. #define TRACKDUMP()
  146. #endif
  147. #ifdef _cplusplus
  148. }
  149. #endif
  150. #endif