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.

422 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_ALL = 0xFFFFFFFF;
  91. //
  92. // Registry value names
  93. //
  94. #define BS_DBG_TRACE_TO_FILE_REG ( L"TraceToFile" )
  95. #define BS_DBG_TRACE_TO_DEBUGGER_REG ( L"TraceToDebugger" )
  96. #define BS_DBG_TRACE_ENTER_EXIT_REG ( L"TraceEnterExit" )
  97. #define BS_DBG_TRACE_FILE_NAME_REG ( L"TraceFile" )
  98. #define BS_DBG_TRACE_FILE_LINE_INFO_REG ( L"TraceFileLineInfo" )
  99. #define BS_DBG_TRACE_TIMESTAMP_REG ( L"TraceTimestamp" )
  100. #define BS_DBG_TRACE_LEVEL_REG ( L"TraceLevel" )
  101. #define BS_DBG_TRACE_FORCE_FLUSH_REG ( L"TraceForceFlush" )
  102. //
  103. // Default trace values
  104. //
  105. #define BS_DBG_TRACE_TO_FILE_DFLT ( FALSE )
  106. #define BS_DBG_TRACE_TO_DEBUGGER_DFLT ( FALSE )
  107. #define BS_DBG_TRACE_ENTER_EXIT_DFLT ( TRUE )
  108. #define BS_DBG_TRACE_FILE_NAME_DFLT ( L"" )
  109. #define BS_DBG_TRACE_FILE_LINE_INFO_DFLT ( TRUE )
  110. #define BS_DBG_TRACE_TIMESTAMP_DFLT ( TRUE )
  111. #define BS_DBG_TRACE_LEVEL_DFLT ( DEBUG_TRACE_ALL )
  112. #define BS_DBG_TRACE_FORCE_FLUSH_DFLT ( FALSE )
  113. //
  114. // The following defines specify non-session contexts
  115. //
  116. #define LTS_CONTEXT_GEN ( 0x00FFF000 ) // general LTSS operation context
  117. #define VSS_CONTEXT_GEN ( 0x00000001 ) // used by VSS
  118. #define LTS_CONTEXT_ADMIN ( 0x00AAAAAA ) // used by LTSS Administrative operations
  119. #define LTS_CONTEXT_INTENTION_LIST ( 0x00BBBBBB ) // used by LTSS background intention list thread
  120. #define LTS_CONTEXT_QUERY ( 0x00EEEEEE ) // LTSS query operations
  121. #define USN_CONTEXT_GEN ( 0x00CCCCCC ) // general USN service context
  122. #define USN_CONTEXT_ARCHIVE_THREAD ( 0x00DDDDDD ) // USN archive service read thread
  123. #define LTS_CONTEXT_DELAYED_DLL ( 0xFFFFFFFF ) // Practically, no context. Used in LTSS DLL inproc server
  124. #define VSS_CONTEXT_DELAYED_DLL ( 0xFFFFFFFF ) // Practically, no context. Used in SWPRV inproc server a.o.
  125. #define BS_DBG_OUT_BUF_SIZE 2048
  126. class CBsDbgTrace // : public CBsBase - Can't do this since debug statements in CBsBase
  127. {
  128. public :
  129. // constructors & destructors
  130. //
  131. // Constructor for class. All default values are set here.
  132. //
  133. CBsDbgTrace();
  134. ~CBsDbgTrace();
  135. VOID Initialize(
  136. IN BOOL bInConstructor = FALSE
  137. );
  138. HRESULT PrePrint(
  139. IN LPCWSTR pszSourceFileName,
  140. IN DWORD dwLineNum,
  141. IN DWORD dwIndent,
  142. IN DWORD dwLevel,
  143. IN LPCWSTR pwszFunctionName = NULL,
  144. IN BOOL bTraceEnter = FALSE
  145. );
  146. HRESULT PostPrint(
  147. IN DWORD dwIndent
  148. );
  149. HRESULT _cdecl Print(
  150. IN LPCWSTR pwszFormatStr,
  151. IN ...
  152. );
  153. HRESULT _cdecl PrintEnterExit(
  154. IN LPCWSTR pwszFormatStr,
  155. IN ...
  156. );
  157. HRESULT ReadRegistry();
  158. DWORD GetTraceLevel() { return m_dwTraceLevel; }
  159. DWORD GetTraceEnterExit() { return m_bTraceEnterExit; }
  160. VOID SetContextNum(
  161. IN DWORD dwContextNum
  162. );
  163. BOOL IsTracingEnabled() { return m_bTracingEnabled; }
  164. BOOL IsDuringSetup();
  165. private :
  166. HRESULT OutputString();
  167. BOOL m_bTracingEnabled; // Set when tracing is enabled
  168. HANDLE m_hTraceFile;
  169. LPWSTR m_pwszTraceFileName;
  170. BOOL m_bTraceToFile;
  171. BOOL m_bTraceToDebugger;
  172. BOOL m_bTraceEnterExit;
  173. BOOL m_bTraceFileLineInfo;
  174. BOOL m_bTraceTimestamp;
  175. BOOL m_bForceFlush;
  176. DWORD m_dwTraceLevel;
  177. DWORD m_dwTraceIndent;
  178. DWORD m_dwCurrentProcessId;
  179. time_t m_lTimeStarted;
  180. BOOL m_bInitialized; // TRUE if the object is initialized.
  181. DWORD m_dwContextId; // Used to keep track of trace object instances
  182. //
  183. // Set when PrePrint() is called and the trace level is set
  184. //
  185. BOOL m_bInTrace;
  186. BOOL m_bTraceEnter; // Set if this is an enter trace print
  187. DWORD m_dwLineNum; // From __LINE__
  188. LPCWSTR m_pwszSourceFileName; // From __FILE__
  189. LPCWSTR m_pwszFunctionName; // For enter and exit traces
  190. CBsCritSec *m_pcs; // Used to serialize access to the trace facility
  191. WCHAR m_pwszOutBuf[ BS_DBG_OUT_BUF_SIZE ]; // Used for temporary storage of output strings
  192. BOOL m_bIsDuringSetup;
  193. };
  194. //
  195. // g_cDbgTrace is the one instance of the CBsDbgTrace class used process wide
  196. //
  197. extern CBsDbgTrace g_cDbgTrace;
  198. //
  199. // The following debug macros\inlines are used in LTSS and defined in
  200. // debug builds. BsDebugTraceAlways() is defined in debug and retail builds.
  201. //
  202. // BsDebugTrace( INDENT, LEVEL, (LPCTSTR pFormat, ...) ) - Prints a trace message, third parameter includes the outer parentheses.
  203. //
  204. // BsDebugTraceAlways( INDENT, LEVEL, (LPCTSTR pFormat, ...) ) - Prints a trace message in debug AND retail builds, third parameter includes the outer parentheses.
  205. //
  206. // BsDebugTraceEnter( INDENT, LEVEL, FUNCTION_NAME, (LPCTSTR pFormat, ...) ) - Prints function entry information, fourth parameter includes the outer parentheses.
  207. //
  208. // BsDebugTraceExit( INDENT, LEVEL, FUNCTION_NAME, (LPCTSTR pFormat, ...) ) - Prints function exit information, fourth parameter includes the outer parentheses.
  209. //
  210. // BsDebugExec( Statement ) - Executes a statement
  211. //
  212. // BsDebugSetContext( dwNumber ) - sets the global index to identify
  213. // an instance of theLTS service, or
  214. // an intention list processing thread.
  215. //
  216. #define BsDebugSetContext( CONTEXT_NUM ) ( g_cDbgTrace.SetContextNum( CONTEXT_NUM ) )
  217. /*++
  218. Macro Description:
  219. BsDebugTrace macro calls trace functions to output the header,
  220. the debug data, and any footer data, for the debug statement. It
  221. only does this if necessary when LEVEL matches an active trace
  222. level. Not enabled in retail builds.
  223. Arguments:
  224. IN INDENT - this is the indentation indicator
  225. IN LEVEL - the debug level
  226. IN M - the format string & the parameter list
  227. Return Value:
  228. None.
  229. --*/
  230. #ifdef _DEBUG
  231. #define BsDebugTrace( INDENT, LEVEL, M ) { \
  232. if ( g_cDbgTrace.IsTracingEnabled() && \
  233. ( LEVEL == 0 || ( g_cDbgTrace.GetTraceLevel() & LEVEL ) ) ) { \
  234. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL) ); \
  235. g_cDbgTrace.Print M; \
  236. g_cDbgTrace.PostPrint( (INDENT) ); \
  237. } \
  238. }
  239. #else
  240. #define BsDebugTrace( INDENT, LEVEL, M )
  241. #endif
  242. /*++
  243. Macro Description:
  244. BsDebugTraceAlways macro calls trace functions to output the header,
  245. the debug data, and any footer data, for the debug statement. It is
  246. the same as BsDebugTrace() except that it IS enabled in the retail
  247. builds along with the debug builds. Only use this trace macro for
  248. traces that happen infrequently or in severe error cases. It should
  249. not be in execution paths that are hot because of the additional
  250. overhead of checking trace flags.
  251. Arguments:
  252. Indent - this is the indentation indicator
  253. LEVEL - the debug level
  254. M - the format string & the parameter list
  255. Return Value:
  256. None.
  257. --*/
  258. #define BsDebugTraceAlways( INDENT, LEVEL, M ) { \
  259. if ( g_cDbgTrace.IsTracingEnabled() ) { \
  260. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL) ); \
  261. g_cDbgTrace.Print M; \
  262. g_cDbgTrace.PostPrint( (INDENT) ); \
  263. } \
  264. }
  265. /*++
  266. Macro Description:
  267. These macros will dump the parameters to a function at entry, if enter/exit
  268. tracing is enabled.
  269. BsDebugTraceEnterAlways() is enabled in both retail and debug builds.
  270. BsDebugTraceEnter() is enabled in debug builds but not in retail builds
  271. Arguments:
  272. IN INDENT - this is the indentation indicator
  273. IN LEVEL - the debug level
  274. IN FUNCTION_NAME - name of the function that being entered
  275. IN M - the format string & the parameter list
  276. Return Value:
  277. None.
  278. --*/
  279. #define BsDebugTraceEnterAlways( INDENT, LEVEL, FUNCTION_NAME, M ){ \
  280. if ( g_cDbgTrace.IsTracingEnabled() && g_cDbgTrace.GetTraceEnterExit() ) { \
  281. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL), (FUNCTION_NAME), TRUE ); \
  282. g_cDbgTrace.PrintEnterExit M; \
  283. g_cDbgTrace.PostPrint( (INDENT) ); \
  284. } \
  285. }
  286. #ifdef _DEBUG
  287. #define BsDebugTraceEnter( INDENT, LEVEL, FUNCTION_NAME, M ) \
  288. BsDebugTraceEnterAlways( INDENT, LEVEL, FUNCTION_NAME, M )
  289. #else
  290. #define BsDebugTraceEnter( INDENT, LEVEL, FUNCTION_NAME, M)
  291. #endif
  292. /*++
  293. Macro Description:
  294. These macros will dump the return results of a function at function exit,
  295. if enter/exit tracing is enabled.
  296. BsDebugTraceExitAlways() is enabled in both retail and debug builds.
  297. BsDebugTraceExit() is enabled in debug builds but not in retail builds
  298. Arguments:
  299. IN INDENT - this is the indentation indicator
  300. IN LEVEL - the debug level
  301. IN FUNCTION_NAME - name of the function that's exiting
  302. IN M - the format string & the parameter list
  303. Return Value:
  304. None.
  305. --*/
  306. #define BsDebugTraceExitAlways( INDENT, LEVEL, FUNCTION_NAME, M ){ \
  307. if ( g_cDbgTrace.IsTracingEnabled() && g_cDbgTrace.GetTraceEnterExit() ) { \
  308. g_cDbgTrace.PrePrint( __WFILE__, __LINE__, (INDENT), (LEVEL), (FUNCTION_NAME), FALSE ); \
  309. g_cDbgTrace.PrintEnterExit M; \
  310. g_cDbgTrace.PostPrint( (INDENT) ); \
  311. } \
  312. }
  313. #ifdef _DEBUG
  314. #define BsDebugTraceExit( INDENT, LEVEL, FUNCTION_NAME, M ) \
  315. BsDebugTraceExitAlways( INDENT, LEVEL, FUNCTION_NAME, M )
  316. #else
  317. #define BsDebugTraceExit( INDENT, LEVEL, FUNCTION_NAME, M)
  318. #endif
  319. //
  320. // BsDebugExec will execute a statement at runtime
  321. //
  322. #define BsDebugExec(X) (X)
  323. #endif // _VSS_TRACE_H_