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.

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