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.

183 lines
5.7 KiB

  1. /*
  2. * C A L D B G . H
  3. *
  4. * Debugging support header
  5. * Support functions are implemented in CALDBG.C.
  6. *
  7. * Copyright 1986-1997 Microsoft Corporation. All Rights Reserved.
  8. */
  9. #ifndef _CALDBG_H_
  10. #define _CALDBG_H_
  11. /*
  12. * Debugging Macros -------------------------------------------------------
  13. *
  14. * IFDBG(x) Results in the expression x if DEBUG is defined, or
  15. * to nothing if DEBUG is not defined
  16. *
  17. * IFNDBG(x) Results in the expression x if DEBUG is not defined,
  18. * or to nothing if DEBUG is defined
  19. *
  20. * Unreferenced(a) Causes a to be referenced so that the compiler
  21. * doesn't issue warnings about unused local variables
  22. * which exist but are reserved for future use (eg
  23. * ulFlags in many cases)
  24. */
  25. #if defined(DEBUG)
  26. #define IFDBG(x) x
  27. #define IFNDBG(x)
  28. #else
  29. #define IFDBG(x)
  30. #define IFNDBG(x) x
  31. #endif
  32. #ifdef __cplusplus
  33. #define EXTERN_C_BEGIN extern "C" {
  34. #define EXTERN_C_END }
  35. #else
  36. #define EXTERN_C_BEGIN
  37. #define EXTERN_C_END
  38. #endif
  39. /*
  40. * Assert Macros ------------------------------------------------------------
  41. *
  42. * Assert(a) Displays a message indicating the file and line number
  43. * of this Assert() if a == 0. OK'ing an assert traps
  44. * into the debugger.
  45. *
  46. * AssertSz(a,sz) Works like an Assert(), but displays the string sz
  47. * along with the file and line number.
  48. *
  49. * Side asserts A side assert works like an Assert(), but evaluates
  50. * 'a' even when asserts are not enabled.
  51. */
  52. #if defined(DEBUG) || defined(ASSERTS_ENABLED)
  53. #define IFTRAP(x) x
  54. #else
  55. #define IFTRAP(x) 0
  56. #endif
  57. #define Trap() IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,"Trap"))
  58. #define TrapSz(psz) IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,psz))
  59. #define Assert(t) IFTRAP(((t) ? 0 : DebugTrapFn(1,__FILE__,__LINE__,"Assertion Failure: " #t),0))
  60. #define AssertSz(t,psz) IFTRAP(((t) ? 0 : DebugTrapFn(1,__FILE__,__LINE__,psz),0))
  61. #define SideAssert(t) ((t) ? 0 : IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,"Assertion Failure: " #t)),0)
  62. #define SideAssertSz(t,psz) ((t) ? 0 : IFTRAP(DebugTrapFn(1,__FILE__,__LINE__,psz)),0)
  63. /*
  64. * Trace Macros -------------------------------------------------------------
  65. *
  66. * DebugTrace Use for arbitrary formatted output. It
  67. * takes exactly the same arguments as the
  68. * Windows wsprintf() function.
  69. */
  70. #if defined(DEBUG) || defined(TRACES_ENABLED)
  71. #define IFTRACE(x) x
  72. #define DebugTrace DebugTraceFn
  73. #define DEBUG_WSZ __wsz
  74. #define MK_DEBUG_WSZ(_s,_c) \
  75. LPWSTR __wsz; \
  76. __wsz = static_cast<LPWSTR>(_alloca(((_c) + 1) * sizeof(WCHAR))); \
  77. wcsncpy (__wsz, _s, (_c) + 1); \
  78. __wsz[_c] = 0 \
  79. #else
  80. #define IFTRACE(x) 0
  81. #define DebugTrace
  82. #define DEBUG_WSZ NULL
  83. #define MK_DEBUG_WSZ(_s,_c)
  84. #endif
  85. /* ------------------------------------------------------------------------
  86. *
  87. * .INI triggered traces
  88. */
  89. #ifdef DEBUG
  90. #define DEFINE_TRACE(trace) int g_fTrace##trace
  91. #define DECLARE_TRACE(trace) extern DEFINE_TRACE(trace)
  92. #define DO_TRACE(trace) !g_fTrace##trace ? 0 : DebugTraceFn
  93. #define INIT_TRACE(trace) g_fTrace##trace = GetPrivateProfileInt( gc_szDbgTraces, #trace, FALSE, gc_szDbgIni )
  94. // Convenience macro for DEBUG code. Will cause an error on non-debug builds.
  95. #define DEBUG_TRACE_TEST(trace) g_fTrace##trace
  96. #else
  97. #define DEFINE_TRACE(trace)
  98. #define DECLARE_TRACE(trace)
  99. #define DO_TRACE(trace) DebugTrace
  100. #define INIT_TRACE(trace)
  101. //#define DEBUG_TRACETEST(trace) // Purposefully cause an error on non-debug builds
  102. #endif
  103. /* Debugging Functions ---------------------------------------------------- */
  104. #define EXPORTDBG
  105. EXTERN_C_BEGIN
  106. INT EXPORTDBG __cdecl DebugTrapFn(int fFatal, char *pszFile, int iLine, char *pszFormat, ...);
  107. INT EXPORTDBG __cdecl DebugTraceFn(char *pszFormat, ...);
  108. VOID EXPORTDBG __cdecl GetCallStack (DWORD *pdwCaller, int cSkip, int cFind);
  109. BOOL EXPORTDBG __cdecl GetSymbolName (DWORD dwAddr, LPSTR szMod, LPSTR szFn, DWORD * pdwDisp);
  110. EXTERN_C_END
  111. // Symbolic names ------------------------------------------------------------
  112. //
  113. #include <imagehlp.h>
  114. enum { CB_SYM_MAX = 256 };
  115. enum { CB_MOD_MAX = 64 };
  116. enum { NCALLERS = 10 };
  117. EXTERN_C_BEGIN
  118. typedef BOOL (__stdcall SYMINITIALIZE) (HANDLE hProc, LPSTR lpszSynPath, BOOL fInvadeProc);
  119. typedef BOOL (__stdcall SYMGETMODULE) (HANDLE hProc, DWORD dwAddr, PIMAGEHLP_MODULE pmod);
  120. typedef BOOL (__stdcall SYMGETSYMBOL) (HANDLE hProc, DWORD dwAddr, PDWORD pdwDisp, PIMAGEHLP_SYMBOL psym);
  121. typedef BOOL (__stdcall SYMUNDECORATE) (PIMAGEHLP_SYMBOL psym, LPSTR lpszUnDecName, DWORD cbBuf);
  122. EXTERN_C_END
  123. /* Debugging Strings ------------------------------------------------------ */
  124. EXTERN_C_BEGIN
  125. // Inifile name -- must be set by calling code!
  126. extern const CHAR gc_szDbgIni[];
  127. // Strings set in caldbg.c for use in calling code.
  128. extern const CHAR gc_szDbgAssertLeaks[];
  129. extern const CHAR gc_szDbgAssertCloses[];
  130. extern const CHAR gc_szDbgDebugTrace[];
  131. extern const CHAR gc_szDbgEventLog[];
  132. extern const CHAR gc_szDbgGeneral[];
  133. extern const CHAR gc_szDbgLeakLogging[];
  134. extern const CHAR gc_szDbgLogFile[];
  135. extern const CHAR gc_szDbgRecordResources[];
  136. extern const CHAR gc_szDbgSymbolicDumps[];
  137. extern const CHAR gc_szDbgTraces[];
  138. extern const CHAR gc_szDbgUseVirtual[];
  139. extern const CHAR gc_szDbgUseExchmem[];
  140. EXTERN_C_END
  141. /* Virtual Allocations ---------------------------------------------------- */
  142. EXTERN_C_BEGIN
  143. VOID * EXPORTDBG __cdecl VMAlloc(ULONG);
  144. VOID * EXPORTDBG __cdecl VMAllocEx(ULONG, ULONG);
  145. VOID * EXPORTDBG __cdecl VMRealloc(VOID *, ULONG);
  146. VOID * EXPORTDBG __cdecl VMReallocEx(VOID *, ULONG, ULONG);
  147. ULONG EXPORTDBG __cdecl VMGetSize(VOID *);
  148. ULONG EXPORTDBG __cdecl VMGetSizeEx(VOID *, ULONG);
  149. VOID EXPORTDBG __cdecl VMFree(VOID *);
  150. VOID EXPORTDBG __cdecl VMFreeEx(VOID *, ULONG);
  151. EXTERN_C_END
  152. #endif