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.

288 lines
6.7 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: ltdebug.h
  4. // Copyright (C) 1994-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Debugging facilities for Espresso 2.x. Included are augmented TRACE
  8. // and ASSERT facilities.
  9. //
  10. //-----------------------------------------------------------------------------
  11. #ifndef MITUTIL_LtDebug_h_INCLUDED
  12. #define MITUTIL_LtDebug_h_INCLUDED
  13. #pragma once
  14. #if defined(_DEBUG)
  15. #define LTTRACE_ACTIVE
  16. #define LTASSERT_ACTIVE
  17. #define new DEBUG_NEW
  18. #define LTGetAllocNumber() LTGetAllocNumberImpl()
  19. //
  20. // Executes code only in a DEBUG build.
  21. //
  22. #define DEBUGONLY(x) x
  23. #define LTDebugBreak() LTBreak()
  24. #else // _DEBUG
  25. #define DEBUGONLY(x)
  26. #define LTDebugBreak() (void) 0
  27. #define LTGetAllocNumber() 0
  28. #endif // _DEBUG
  29. #if defined(LTASSERT_ACTIVE) || defined (ASSERT_ALWAYS)
  30. #ifdef ASSERT
  31. #undef ASSERT
  32. #endif
  33. #ifdef VERIFY
  34. #undef VERIFY
  35. #endif
  36. #define ASSERT LTASSERT
  37. #define VERIFY LTVERIFY
  38. #ifndef _DEBUG
  39. #pragma message("Warning: LTASSERT Active in non-debug build")
  40. #endif
  41. //
  42. // The multilevel assert macros ensure that the line numbers get expanded to
  43. // something like "115" instead of "line" or "__LINE__"
  44. //
  45. // This will evaluate the expression only once, UNLESS to ask it to 'Retry'.
  46. // Then it will re-evaluate the expression after the return from the debugger.
  47. //
  48. #define LTASSERTONLY(x) x
  49. #define LTASSERT(x) LTASSERT2(x, TEXT(__FILE__), __LINE__)
  50. #define LTASSERT2(exp, file, line) \
  51. while (!(exp) && LTFailedAssert(TEXT(#exp), file, line)) (void) 0
  52. #define LTVERIFY(x) LTASSERT(x)
  53. #else // defined(_DEBUG) || defined(ASSERT_ALWAYS)
  54. #define LTASSERTONLY(x)
  55. #define LTASSERT(x) (void) 0
  56. #define LTVERIFY(x) x
  57. #endif // defined(_DEBUG) || defined(ASSERT_ALWAYS)
  58. #ifndef MIT_NO_DEBUG
  59. //
  60. // Name of the project
  61. //
  62. #ifndef LTTRACEPROJECT
  63. #define LTTRACEPROJECT "Borg"
  64. #endif
  65. //
  66. // Default value for the exe name if one was not supplied.
  67. //
  68. #ifndef LTTRACEEXE
  69. #define LTTRACEEXE MSLOC
  70. #endif
  71. //
  72. // Used to put quotes around the LTTRACEEXE macro.
  73. //
  74. #define __stringify2(x) #x
  75. #define __stringify(x) __stringify2(x)
  76. //
  77. // TODO - find a better place for this
  78. LTAPIENTRY void CopyToClipboard(const char *szMessage);
  79. struct LTModuleInfo
  80. {
  81. UINT uiPreferredLoadAddress;
  82. UINT uiActualLoadAddress;
  83. UINT uiModuleSize;
  84. char szName[MAX_PATH];
  85. };
  86. LTAPIENTRY void LTInitDebug(void);
  87. LTAPIENTRY void LTInstallIMallocTracking();
  88. LTAPIENTRY void LTDumpIMallocs(void);
  89. LTAPIENTRY void LTTrackIMalloc(BOOL f);
  90. LTAPIENTRY void LTRevokeIMallocTracking();
  91. LTAPIENTRY void LTShutdownDebug(void);
  92. LTAPIENTRY BOOL LTSetAssertSilent(BOOL);
  93. LTAPIENTRY BOOL LTFailedAssert(const TCHAR *, const TCHAR *, int);
  94. LTAPIENTRY void LTBreak(void);
  95. LTAPIENTRY LONG LTGetAllocNumberImpl(void);
  96. LTAPIENTRY void LTBreakOnAlloc(const char *szFilename, int nLineNum, long nAllocNum);
  97. LTAPIENTRY BOOL LTCheckBaseAddress(HMODULE);
  98. LTAPIENTRY BOOL LTCheckAllBaseAddresses(void);
  99. LTAPIENTRY void LTCheckPagesFor(HINSTANCE);
  100. LTAPIENTRY void LTCheckPagesForAll(void);
  101. LTAPIENTRY void LTDumpAllModules(void);
  102. LTAPIENTRY BOOL LTLocateModule(DWORD dwAddress, HMODULE *pInstance);
  103. LTAPIENTRY BOOL LTGetModuleInfo(HMODULE, LTModuleInfo *);
  104. LTAPIENTRY UINT LTGenStackTrace(TCHAR *szBuffer, UINT nBuffSize,
  105. UINT nSkip, UINT nTotal);
  106. LTAPIENTRY void LTSetBoringModules(const char *aszBoring[]);
  107. LTAPIENTRY void LTTrackAllocations(BOOL);
  108. LTAPIENTRY void LTDumpAllocations(void);
  109. LTAPIENTRY BOOL LTCheckResourceRange(HINSTANCE, WORD UniqueStart, WORD UniqueEnd,
  110. WORD SharedStart, WORD SharedEnd);
  111. LTAPIENTRY BOOL LTCheckAllResRanges(WORD, WORD);
  112. #pragma warning(disable:4275)
  113. class LTAPIENTRY CAssertFailedException : public CException
  114. {
  115. public:
  116. CAssertFailedException(const TCHAR *);
  117. CAssertFailedException(const TCHAR *, BOOL);
  118. BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  119. PUINT pnHelpContext = NULL);
  120. ~CAssertFailedException();
  121. private:
  122. CAssertFailedException();
  123. CAssertFailedException(const CAssertFailedException &);
  124. TCHAR *m_pszAssert;
  125. };
  126. class LTAPIENTRY LTTracePoint
  127. {
  128. public:
  129. LTTracePoint(const TCHAR *);
  130. ~LTTracePoint();
  131. private:
  132. LTTracePoint();
  133. const TCHAR *m_psz;
  134. };
  135. #pragma warning(default:4275)
  136. //
  137. // Comment this out to remove ASSERTs from retail builds
  138. // #define LTASSERT_ACTIVE
  139. #if defined(LTTRACE_ACTIVE)
  140. static const TCHAR *szLTTRACEEXE = TEXT(__stringify(LTTRACEEXE));
  141. //
  142. // The following let us control the output dynamically. We use a function
  143. // pointer to route our debug output, and change the function pointer to
  144. // enable/disable tracing.
  145. //
  146. static void LTTRACEINIT(const TCHAR *, ...);
  147. static void (*LTTRACE)(const TCHAR *, ...) = LTTRACEINIT;
  148. void LTAPIENTRY LTTRACEOUT(const TCHAR *szFormat, va_list args);
  149. void LTAPIENTRY LTTRACEON(const TCHAR *szFormat, ...);
  150. void LTAPIENTRY LTTRACEOFF(const TCHAR *szFormat, ...);
  151. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  152. //
  153. // LTTRACE is initialized to point to this function. When first called, it
  154. // determines if tracing should be enabled, then routes LTTRACE through the
  155. // right handler.
  156. //
  157. //-----------------------------------------------------------------------------
  158. static
  159. void
  160. LTTRACEINIT(
  161. const TCHAR *szFormat, // printf style formatting string
  162. ...) // Variable argument list to format
  163. {
  164. BOOL fDoTrace = 1;
  165. va_list args;
  166. const TCHAR * const szTraceProfile = TEXT("lttrace.ini");
  167. fDoTrace = GetPrivateProfileInt(
  168. TEXT("ProjectTracing"),
  169. TEXT("Default"),
  170. fDoTrace,
  171. szTraceProfile);
  172. fDoTrace = GetPrivateProfileInt(
  173. TEXT("ProjectTracing"),
  174. TEXT(LTTRACEPROJECT),
  175. fDoTrace,
  176. szTraceProfile);
  177. if (fDoTrace)
  178. {
  179. fDoTrace = GetPrivateProfileInt(
  180. TEXT("ExecutableTracing"),
  181. szLTTRACEEXE,
  182. fDoTrace,
  183. szTraceProfile);
  184. }
  185. if (fDoTrace)
  186. {
  187. LTTRACE = LTTRACEON;
  188. va_start(args, szFormat);
  189. LTTRACEOUT(szFormat, args);
  190. }
  191. else
  192. {
  193. LTTRACE = LTTRACEOFF;
  194. }
  195. }
  196. #define LTTRACEPOINT(sz) LTTracePoint lttp##__LINE__(TEXT(sz))
  197. #else // defined(LTTRACE_ACTIVE)
  198. //
  199. // Retail version of the debugging macros. Everything
  200. // just 'goes away'. We use (void) 0 so that these things
  201. // are statements in both the debug and retail builds.
  202. //
  203. static inline void LTNOTRACE(const TCHAR *, ...)
  204. {}
  205. #define LTTRACE 1 ? (void) 0 : (void) LTNOTRACE
  206. #define LTTRACEPOINT(x) (void) 0
  207. #endif // defined(LTTRACE_ACTIVE)
  208. #endif // MIT_NO_DEBUG
  209. #endif // #ifndef MITUTIL_LtDebug_h_INCLUDED