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.

424 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. vs_trace.hxx
  5. Abstract:
  6. This header declares the global debug\trace structures used by the
  7. Long Term Storage service. This file should be included in all other files
  8. in the project, so that debugging and trace features can be used.
  9. Former name: BsDebug.hxx
  10. Author:
  11. Revision History:
  12. Name Date Comments
  13. ssteiner 06/03/98 Made numerious changes and removed iostream
  14. dependencies, added a few new registry entries and
  15. added serialization.
  16. aoltean 07/06/99 Removed ATL support
  17. brianb 04/19/2000 Added Assertion code
  18. --*/
  19. #ifndef _VSS_TRACE_H_
  20. #define _VSS_TRACE_H_
  21. /////////////////////////////////////////////////////////////////////////////
  22. // Useful macros
  23. #define WSTR_GUID_FMT L"{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}"
  24. #define GUID_PRINTF_ARG( X ) \
  25. (X).Data1, \
  26. (X).Data2, \
  27. (X).Data3, \
  28. (X).Data4[0], (X).Data4[1], (X).Data4[2], (X).Data4[3], \
  29. (X).Data4[4], (X).Data4[5], (X).Data4[6], (X).Data4[7]
  30. /*
  31. #define WSTR_LONGLONG_FMT L"0x%08lx%08lx"
  32. #define LONGLONG_PRINTF_ARG( X ) \
  33. (LONG)( ((X) >> 32) & 0xFFFFFFFF), \
  34. (LONG)( (X) & 0xFFFFFFFF )
  35. */
  36. #define WSTR_LONGLONG_FMT L"0x%016I64x"
  37. #define LONGLONG_PRINTF_ARG( X ) \
  38. ( X )
  39. #define VSS_EVAL(X) X
  40. #define VSS_STRINGIZE_ARG(X) #X
  41. #define VSS_STRINGIZE(X) VSS_EVAL(VSS_STRINGIZE_ARG(X))
  42. #define VSS_MERGE(A, B) A##B
  43. #define VSS_MAKE_W(A) VSS_MERGE(L, A)
  44. #define VSS_WSTRINGIZE(X) VSS_MAKE_W(VSS_STRINGIZE(X))
  45. #define __WFILE__ VSS_MAKE_W(VSS_EVAL(__FILE__))
  46. #include <WTYPES.H>
  47. #include <time.h>
  48. #include "bsconcur.hxx"
  49. ////////////////////////////////////////////////////////////////////////
  50. // Standard foo for file name aliasing. This code block must be after
  51. // all includes of VSS header files.
  52. //
  53. #ifdef VSS_FILE_ALIAS
  54. #undef VSS_FILE_ALIAS
  55. #endif
  56. #define VSS_FILE_ALIAS "INCVTRCH"
  57. //
  58. ////////////////////////////////////////////////////////////////////////
  59. //
  60. // LTSS trace levels that can be individually enabled
  61. //
  62. const DWORD DEBUG_TRACE_ALWAYS = 0x00000000;
  63. const DWORD DEBUG_TRACE_ERROR = 0x00000001;
  64. const DWORD DEBUG_TRACE_CATCH_EXCEPTIONS = 0x00000002;
  65. const DWORD DEBUG_TRACE_DB = 0x00000004;
  66. const DWORD DEBUG_TRACE_ADMIN = 0x00000008;
  67. const DWORD DEBUG_TRACE_LTSS = 0x00000010;
  68. const DWORD DEBUG_TRACE_MEDIA = 0x00000020;
  69. const DWORD DEBUG_TRACE_LMS = 0x00000040;
  70. const DWORD DEBUG_TRACE_SAS = 0x00000080;
  71. const DWORD DEBUG_TRACE_LTSS_DLL = 0x00000100;
  72. const DWORD DEBUG_TRACE_VSS_COORD = 0x00000200;
  73. const DWORD DEBUG_TRACE_VSS_SWPRV = 0x00000400;
  74. const DWORD DEBUG_TRACE_VSS_TEST = 0x00000800;
  75. const DWORD DEBUG_TRACE_VSS_TESTPRV = 0x00001000;
  76. const DWORD DEBUG_TRACE_VSS_DEMO = 0x00002000;
  77. const DWORD DEBUG_TRACE_VSS_GEN = 0x00004000;
  78. const DWORD DEBUG_TRACE_VSS_SHIM = 0x00008000;
  79. const DWORD DEBUG_TRACE_USN_RAW = 0x00010000;
  80. const DWORD DEBUG_TRACE_USN_ARCHIVE = 0x00020000;
  81. const DWORD DEBUG_TRACE_USN_GEN = 0x00040000;
  82. const DWORD DEBUG_TRACE_VSS_XML = 0x00080000;
  83. const DWORD DEBUG_TRACE_VSS_WRITER = 0x00100000;
  84. const DWORD DEBUG_TRACE_VSS_IOCTL = 0x00200000;
  85. const DWORD DEBUG_TRACE_VSS_SQLLIB = 0x00400000;
  86. const DWORD DEBUG_TRACE_VSS_ADMIN = 0x00800000;
  87. const DWORD DEBUG_TRACE_BS_LIB = 0x01000000;
  88. const DWORD DEBUG_TRACE_STSWRITER = 0x02000000;
  89. const DWORD DEBUG_TRACE_SQLWRITER = 0x04000000;
  90. const DWORD DEBUG_TRACE_VSSAPI = 0x08000000;
  91. const DWORD DEBUG_TRACE_WRTCOMMON = 0x10000000;
  92. const DWORD DEBUG_TRACE_ALL = 0xFFFFFFFF;
  93. //
  94. // Registry value names
  95. //
  96. #define BS_DBG_TRACE_TO_FILE_REG ( L"TraceToFile" )
  97. #define BS_DBG_TRACE_TO_DEBUGGER_REG ( L"TraceToDebugger" )
  98. #define BS_DBG_TRACE_ENTER_EXIT_REG ( L"TraceEnterExit" )
  99. #define BS_DBG_TRACE_FILE_NAME_REG ( L"TraceFile" )
  100. #define BS_DBG_TRACE_FILE_LINE_INFO_REG ( L"TraceFileLineInfo" )
  101. #define BS_DBG_TRACE_TIMESTAMP_REG ( L"TraceTimestamp" )
  102. #define BS_DBG_TRACE_LEVEL_REG ( L"TraceLevel" )
  103. #define BS_DBG_TRACE_FORCE_FLUSH_REG ( L"TraceForceFlush" )
  104. //
  105. // Default trace values
  106. //
  107. #define BS_DBG_TRACE_TO_FILE_DFLT ( FALSE )
  108. #define BS_DBG_TRACE_TO_DEBUGGER_DFLT ( FALSE )
  109. #define BS_DBG_TRACE_ENTER_EXIT_DFLT ( TRUE )
  110. #define BS_DBG_TRACE_FILE_NAME_DFLT ( L"" )
  111. #define BS_DBG_TRACE_FILE_LINE_INFO_DFLT ( TRUE )
  112. #define BS_DBG_TRACE_TIMESTAMP_DFLT ( TRUE )
  113. #define BS_DBG_TRACE_LEVEL_DFLT ( DEBUG_TRACE_ALL )
  114. #define BS_DBG_TRACE_FORCE_FLUSH_DFLT ( FALSE )
  115. //
  116. // The following defines specify non-session contexts
  117. //
  118. #define LTS_CONTEXT_GEN ( 0x00FFF000 ) // general LTSS operation context
  119. #define VSS_CONTEXT_GEN ( 0x00000001 ) // used by VSS
  120. #define LTS_CONTEXT_ADMIN ( 0x00AAAAAA ) // used by LTSS Administrative operations
  121. #define LTS_CONTEXT_INTENTION_LIST ( 0x00BBBBBB ) // used by LTSS background intention list thread
  122. #define LTS_CONTEXT_QUERY ( 0x00EEEEEE ) // LTSS query operations
  123. #define USN_CONTEXT_GEN ( 0x00CCCCCC ) // general USN service context
  124. #define USN_CONTEXT_ARCHIVE_THREAD ( 0x00DDDDDD ) // USN archive service read thread
  125. #define LTS_CONTEXT_DELAYED_DLL ( 0xFFFFFFFF ) // Practically, no context. Used in LTSS DLL inproc server
  126. #define VSS_CONTEXT_DELAYED_DLL ( 0xFFFFFFFF ) // Practically, no context. Used in SWPRV inproc server a.o.
  127. #define BS_DBG_OUT_BUF_SIZE 2048
  128. class CBsDbgTrace // : public CBsBase - Can't do this since debug statements in CBsBase
  129. {
  130. public :
  131. // constructors & destructors
  132. //
  133. // Constructor for class. All default values are set here.
  134. //
  135. CBsDbgTrace();
  136. ~CBsDbgTrace();
  137. VOID Initialize(
  138. IN BOOL bInConstructor = FALSE
  139. );
  140. HRESULT PrePrint(
  141. IN LPCWSTR pszSourceFileName,
  142. IN DWORD dwLineNum,
  143. IN DWORD dwIndent,
  144. IN DWORD dwLevel,
  145. IN LPCWSTR pwszFunctionName = NULL,
  146. IN BOOL bTraceEnter = FALSE
  147. );
  148. HRESULT PostPrint(
  149. IN DWORD dwIndent
  150. );
  151. HRESULT _cdecl Print(
  152. IN LPCWSTR pwszFormatStr,
  153. IN ...
  154. );
  155. HRESULT _cdecl PrintEnterExit(
  156. IN LPCWSTR pwszFormatStr,
  157. IN ...
  158. );
  159. HRESULT ReadRegistry();
  160. DWORD GetTraceLevel() { return m_dwTraceLevel; }
  161. DWORD GetTraceEnterExit() { return m_bTraceEnterExit; }
  162. VOID SetContextNum(
  163. IN DWORD dwContextNum
  164. );
  165. BOOL IsTracingEnabled() { return m_bTracingEnabled; }
  166. BOOL IsDuringSetup();
  167. private :
  168. HRESULT OutputString();
  169. BOOL m_bTracingEnabled; // Set when tracing is enabled
  170. HANDLE m_hTraceFile;
  171. LPWSTR m_pwszTraceFileName;
  172. BOOL m_bTraceToFile;
  173. BOOL m_bTraceToDebugger;
  174. BOOL m_bTraceEnterExit;
  175. BOOL m_bTraceFileLineInfo;
  176. BOOL m_bTraceTimestamp;
  177. BOOL m_bForceFlush;
  178. DWORD m_dwTraceLevel;
  179. DWORD m_dwTraceIndent;
  180. DWORD m_dwCurrentProcessId;
  181. time_t m_lTimeStarted;
  182. BOOL m_bInitialized; // TRUE if the object is initialized.
  183. DWORD m_dwContextId; // Used to keep track of trace object instances
  184. //
  185. // Set when PrePrint() is called and the trace level is set
  186. //
  187. BOOL m_bInTrace;
  188. BOOL m_bTraceEnter; // Set if this is an enter trace print
  189. DWORD m_dwLineNum; // From __LINE__
  190. LPCWSTR m_pwszSourceFileName; // From __FILE__
  191. LPCWSTR m_pwszFunctionName; // For enter and exit traces
  192. CBsCritSec *m_pcs; // Used to serialize access to the trace facility
  193. WCHAR m_pwszOutBuf[ BS_DBG_OUT_BUF_SIZE ]; // Used for temporary storage of output strings
  194. BOOL m_bIsDuringSetup;
  195. };
  196. //
  197. // g_cDbgTrace is the one instance of the CBsDbgTrace class used process wide
  198. //
  199. extern CBsDbgTrace g_cDbgTrace;
  200. //
  201. // The following debug macros\inlines are used in LTSS and defined in
  202. // debug builds. BsDebugTraceAlways() is defined in debug and retail builds.
  203. //
  204. // BsDebugTrace( INDENT, LEVEL, (LPCTSTR pFormat, ...) ) - Prints a trace message, third parameter includes the outer parentheses.
  205. //
  206. // BsDebugTraceAlways( INDENT, LEVEL, (LPCTSTR pFormat, ...) ) - Prints a trace message in debug AND retail builds, third parameter includes the outer parentheses.
  207. //
  208. // BsDebugTraceEnter( INDENT, LEVEL, FUNCTION_NAME, (LPCTSTR pFormat, ...) ) - Prints function entry information, fourth parameter includes the outer parentheses.
  209. //
  210. // BsDebugTraceExit( INDENT, LEVEL, FUNCTION_NAME, (LPCTSTR pFormat, ...) ) - Prints function exit information, fourth parameter includes the outer parentheses.
  211. //
  212. // BsDebugExec( Statement ) - Executes a statement
  213. //
  214. // BsDebugSetContext( dwNumber ) - sets the global index to identify
  215. // an instance of theLTS service, or
  216. // an intention list processing thread.
  217. //
  218. #define BsDebugSetContext( CONTEXT_NUM ) ( g_cDbgTrace.SetContextNum( CONTEXT_NUM ) )
  219. /*++
  220. Macro Description:
  221. BsDebugTrace macro calls trace functions to output the header,
  222. the debug data, and any footer data, for the debug statement. It
  223. only does this if necessary when LEVEL matches an active trace
  224. level. Not enabled in retail builds.
  225. Arguments:
  226. IN INDENT - this is the indentation indicator
  227. IN LEVEL - the debug level
  228. IN M - the format string & the parameter list
  229. Return Value:
  230. None.
  231. --*/
  232. #ifdef _DEBUG
  233. #define BsDebugTrace( INDENT, LEVEL, M ) { \
  234. if ( g_cDbgTrace.IsTracingEnabled() && \
  235. ( LEVEL == 0 || ( g_cDbgTrace.GetTraceLevel() & LEVEL ) ) ) { \
  236. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL) ); \
  237. g_cDbgTrace.Print M; \
  238. g_cDbgTrace.PostPrint( (INDENT) ); \
  239. } \
  240. }
  241. #else
  242. #define BsDebugTrace( INDENT, LEVEL, M )
  243. #endif
  244. /*++
  245. Macro Description:
  246. BsDebugTraceAlways macro calls trace functions to output the header,
  247. the debug data, and any footer data, for the debug statement. It is
  248. the same as BsDebugTrace() except that it IS enabled in the retail
  249. builds along with the debug builds. Only use this trace macro for
  250. traces that happen infrequently or in severe error cases. It should
  251. not be in execution paths that are hot because of the additional
  252. overhead of checking trace flags.
  253. Arguments:
  254. Indent - this is the indentation indicator
  255. LEVEL - the debug level
  256. M - the format string & the parameter list
  257. Return Value:
  258. None.
  259. --*/
  260. #define BsDebugTraceAlways( INDENT, LEVEL, M ) { \
  261. if ( g_cDbgTrace.IsTracingEnabled() ) { \
  262. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL) ); \
  263. g_cDbgTrace.Print M; \
  264. g_cDbgTrace.PostPrint( (INDENT) ); \
  265. } \
  266. }
  267. /*++
  268. Macro Description:
  269. These macros will dump the parameters to a function at entry, if enter/exit
  270. tracing is enabled.
  271. BsDebugTraceEnterAlways() is enabled in both retail and debug builds.
  272. BsDebugTraceEnter() is enabled in debug builds but not in retail builds
  273. Arguments:
  274. IN INDENT - this is the indentation indicator
  275. IN LEVEL - the debug level
  276. IN FUNCTION_NAME - name of the function that being entered
  277. IN M - the format string & the parameter list
  278. Return Value:
  279. None.
  280. --*/
  281. #define BsDebugTraceEnterAlways( INDENT, LEVEL, FUNCTION_NAME, M ){ \
  282. if ( g_cDbgTrace.IsTracingEnabled() && g_cDbgTrace.GetTraceEnterExit() ) { \
  283. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL), (FUNCTION_NAME), TRUE ); \
  284. g_cDbgTrace.PrintEnterExit M; \
  285. g_cDbgTrace.PostPrint( (INDENT) ); \
  286. } \
  287. }
  288. #ifdef _DEBUG
  289. #define BsDebugTraceEnter( INDENT, LEVEL, FUNCTION_NAME, M ) \
  290. BsDebugTraceEnterAlways( INDENT, LEVEL, FUNCTION_NAME, M )
  291. #else
  292. #define BsDebugTraceEnter( INDENT, LEVEL, FUNCTION_NAME, M)
  293. #endif
  294. /*++
  295. Macro Description:
  296. These macros will dump the return results of a function at function exit,
  297. if enter/exit tracing is enabled.
  298. BsDebugTraceExitAlways() is enabled in both retail and debug builds.
  299. BsDebugTraceExit() is enabled in debug builds but not in retail builds
  300. Arguments:
  301. IN INDENT - this is the indentation indicator
  302. IN LEVEL - the debug level
  303. IN FUNCTION_NAME - name of the function that's exiting
  304. IN M - the format string & the parameter list
  305. Return Value:
  306. None.
  307. --*/
  308. #define BsDebugTraceExitAlways( INDENT, LEVEL, FUNCTION_NAME, M ){ \
  309. if ( g_cDbgTrace.IsTracingEnabled() && g_cDbgTrace.GetTraceEnterExit() ) { \
  310. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL), (FUNCTION_NAME), FALSE ); \
  311. g_cDbgTrace.PrintEnterExit M; \
  312. g_cDbgTrace.PostPrint( (INDENT) ); \
  313. } \
  314. }
  315. #ifdef _DEBUG
  316. #define BsDebugTraceExit( INDENT, LEVEL, FUNCTION_NAME, M ) \
  317. BsDebugTraceExitAlways( INDENT, LEVEL, FUNCTION_NAME, M )
  318. #else
  319. #define BsDebugTraceExit( INDENT, LEVEL, FUNCTION_NAME, M)
  320. #endif
  321. //
  322. // BsDebugExec will execute a statement at runtime
  323. //
  324. #define BsDebugExec(X) (X)
  325. #endif // _VSS_TRACE_H_