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.

156 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Implements macros and declares functions for:
  7. - Resource allocation tracking
  8. - Logging
  9. - Definition of DEBUG
  10. Author:
  11. Jim Schmidt (jimschm) 01-Jan-1997
  12. Revision History:
  13. Ovidiu Temereanca (ovidiut) 06-Nov-1998
  14. Took out log related function declarations and put them in log.h file
  15. --*/
  16. #pragma once
  17. #ifdef _cplusplus
  18. extern "C" {
  19. #endif
  20. //
  21. // If either DBG or DEBUG defined, use debug mode
  22. //
  23. #ifdef DBG
  24. #ifndef DEBUG
  25. #define DEBUG
  26. #endif
  27. #endif
  28. #ifdef DEBUG
  29. #ifndef DBG
  30. #define DBG
  31. #endif
  32. #endif
  33. //
  34. // Debug-only constants
  35. //
  36. #ifdef DEBUG
  37. // This option makes fat, slow binaries
  38. //#define MEMORY_TRACKING
  39. #include <stdarg.h>
  40. typedef enum {
  41. MERGE_OBJECT,
  42. POOLMEM_POINTER,
  43. POOLMEM_POOL,
  44. INF_HANDLE
  45. } ALLOCTYPE;
  46. VOID InitAllocationTracking (VOID);
  47. VOID FreeAllocationTracking (VOID);
  48. VOID DebugRegisterAllocation (ALLOCTYPE Type, PVOID Ptr, PCSTR File, UINT Line);
  49. VOID DebugUnregisterAllocation (ALLOCTYPE Type, PVOID Ptr);
  50. #define ALLOCATION_TRACKING_DEF , PCSTR File, UINT Line
  51. #define ALLOCATION_TRACKING_CALL ,__FILE__,__LINE__
  52. #define ALLOCATION_INLINE_CALL , File, Line
  53. extern PCSTR g_TrackComment;
  54. extern INT g_UseCount;
  55. extern PCSTR g_TrackFile;
  56. extern UINT g_TrackLine;
  57. DWORD SetTrackComment (PCSTR Msg, PCSTR File, UINT Line);
  58. DWORD ClrTrackComment (VOID);
  59. VOID DisableTrackComment (VOID);
  60. VOID EnableTrackComment (VOID);
  61. #define SETTRACKCOMMENT(RetType, Msg,File,Line) ((RetType)(SetTrackComment(Msg,File,Line) | (DWORD) (
  62. #define CLRTRACKCOMMENT ) | ClrTrackComment()))
  63. #define SETTRACKCOMMENT_VOID(Msg,File,Line) SetTrackComment(Msg,File,Line), (
  64. #define CLRTRACKCOMMENT_VOID ), ClrTrackComment()
  65. #define DISABLETRACKCOMMENT() DisableTrackComment()
  66. #define ENABLETRACKCOMMENT() EnableTrackComment()
  67. VOID InitLog (BOOL DeleteLog);
  68. //
  69. // Memory debug option
  70. //
  71. #define MemAlloc(heap,flags,size) DebugHeapAlloc(__FILE__,__LINE__,heap,flags,size)
  72. #define MemReAlloc(heap,flags,ptr,size) DebugHeapReAlloc(__FILE__,__LINE__,heap,flags,ptr,size)
  73. #define MemFree(heap,flags,ptr) DebugHeapFree(__FILE__,__LINE__,heap,flags,ptr)
  74. #define MemCheck(heap) DebugHeapCheck(__FILE__,__LINE__,heap)
  75. PVOID DebugHeapAlloc (PCSTR File, DWORD Line, HANDLE hHeap, DWORD dwFlags, DWORD dwSize);
  76. PVOID DebugHeapReAlloc (PCSTR File, DWORD Line, HANDLE hHeap, DWORD dwFlags, PCVOID pMem, DWORD dwSize);
  77. BOOL DebugHeapFree (PCSTR File, DWORD Line, HANDLE hHeap, DWORD dwFlags, PCVOID pMem);
  78. VOID DebugHeapCheck (PCSTR File, DWORD Line, HANDLE hHeap);
  79. void DumpHeapStats ();
  80. #else
  81. //
  82. // No-debug constants
  83. //
  84. #define SETTRACKCOMMENT(RetType,Msg,File,Line)
  85. #define CLRTRACKCOMMENT
  86. #define SETTRACKCOMMENT_VOID(Msg,File,Line)
  87. #define CLRTRACKCOMMENT_VOID
  88. #define DISABLETRACKCOMMENT()
  89. #define ENABLETRACKCOMMENT()
  90. #define MemAlloc SafeHeapAlloc
  91. #define MemReAlloc SafeHeapReAlloc
  92. #define MemFree(x,y,z) HeapFree(x,y,(LPVOID) z)
  93. #define MemCheck(x)
  94. #define DebugHeapCheck(x,y,z)
  95. #define DumpHeapStats()
  96. #define ALLOCATION_TRACKING_DEF
  97. #define ALLOCATION_TRACKING_CALL
  98. #define ALLOCATION_INLINE_CALL
  99. #define InitAllocationTracking()
  100. #define FreeAllocationTracking()
  101. #define DebugRegisterAllocation(t,p,f,l)
  102. #define DebugUnregisterAllocation(t,p)
  103. #endif
  104. #define MemAllocUninit(size) MemAlloc(g_hHeap,0,size)
  105. #define MemAllocZeroed(size) MemAlloc(g_hHeap,HEAP_ZERO_MEMORY,size)
  106. #define FreeMem(ptr) MemFree(g_hHeap,0,ptr)
  107. #ifdef _cplusplus
  108. }
  109. #endif