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.

299 lines
9.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // BCATrace.h
  7. //
  8. // Description:
  9. // Contains definition of a few macros and a class that helps in tracing.
  10. //
  11. // Implementation Files:
  12. // None
  13. //
  14. // Maintained By:
  15. // Vij Vasu (Vvasu) 03-MAR-2000
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. // Make sure that this file is included only once per compile path.
  19. #pragma once
  20. #ifdef DEBUG
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Include Files
  23. //////////////////////////////////////////////////////////////////////////////
  24. // For debugging functions.
  25. #include "Debug.h"
  26. // For Logging functions.
  27. #include "Log.h"
  28. // For PszTraceFindInterface()
  29. #include "CiTracker.h"
  30. //////////////////////////////////////////////////////////////////////
  31. // Macro Definitions
  32. //////////////////////////////////////////////////////////////////////////////
  33. #define BCA_TRACE_FLAGS static_cast< unsigned long >( mtfALWAYS )
  34. //////////////////////////////////////////////////////////////////////////////
  35. //++
  36. //
  37. // MACRO
  38. // BCATraceMsg(
  39. // _pszfn
  40. // )
  41. //
  42. // Description:
  43. // Displays file, line number, module and "_pszfn" only if the
  44. // mtfOUTPUTTODISK | mtfFunc is set in g_tfModule. "_pszfn" is the name of the
  45. // function just entered.
  46. //
  47. // Arguments:
  48. // _pszfn - Name of the function just entered.
  49. //
  50. // Return Values:
  51. // None.
  52. //
  53. //--
  54. //////////////////////////////////////////////////////////////////////////////
  55. #define BCATraceMsg( _pszfn ) \
  56. do \
  57. { \
  58. if ( g_tfModule != 0 ) \
  59. { \
  60. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn) ); \
  61. } \
  62. } while ( 0 )
  63. //
  64. // These next macros are just like TraceFunc except they take additional
  65. // arguments to display the values passed into the function call. "_pszfn"
  66. // should contain a printf string on how to display the arguments.
  67. //
  68. #define BCATraceMsg1( _pszfn, _arg1 ) \
  69. do \
  70. { \
  71. if ( g_tfModule != 0 ) \
  72. { \
  73. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn), _arg1 ); \
  74. } \
  75. } while ( 0 )
  76. #define BCATraceMsg2( _pszfn, _arg1, _arg2 ) \
  77. do \
  78. { \
  79. if ( g_tfModule != 0 ) \
  80. { \
  81. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn), _arg1, _arg2 ); \
  82. } \
  83. } while ( 0 )
  84. #define BCATraceMsg3( _pszfn, _arg1, _arg2, _arg3 ) \
  85. do \
  86. { \
  87. if ( g_tfModule != 0 ) \
  88. { \
  89. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn), _arg1, _arg2, _arg3 ); \
  90. } \
  91. } while ( 0 )
  92. #define BCATraceMsg4( _pszfn, _arg1, _arg2, _arg3, _arg4 ) \
  93. do \
  94. { \
  95. if ( g_tfModule != 0 ) \
  96. { \
  97. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn), _arg1, _arg2, _arg3, _arg4 ); \
  98. } \
  99. } while ( 0 )
  100. #define BCATraceMsg5( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  101. do \
  102. { \
  103. if ( g_tfModule != 0 ) \
  104. { \
  105. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn), _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  106. } \
  107. } while ( 0 )
  108. #define BCATraceMsg6( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ) \
  109. do \
  110. { \
  111. if ( g_tfModule != 0 ) \
  112. { \
  113. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, BCA_TRACE_FLAGS, TEXT("| ") TEXT(_pszfn), _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 ); \
  114. } \
  115. } while ( 0 )
  116. #define BCATraceScope( _szArgs ) \
  117. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__) ); \
  118. if ( g_tfModule != 0 ) \
  119. { \
  120. DebugIncrementStackDepthCounter( ); \
  121. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )") ); \
  122. }
  123. #define BCATraceScope1( _szArgs, _arg1 ) \
  124. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__) ); \
  125. if ( g_tfModule != 0 ) \
  126. { \
  127. DebugIncrementStackDepthCounter( ); \
  128. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1 ); \
  129. }
  130. #define BCATraceScope2( _szArgs, _arg1, _arg2 ) \
  131. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__) ); \
  132. if ( g_tfModule != 0 ) \
  133. { \
  134. DebugIncrementStackDepthCounter( ); \
  135. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2 ); \
  136. }
  137. #define BCATraceScope3( _szArgs, _arg1, _arg2, _arg3 ) \
  138. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__) ); \
  139. if ( g_tfModule != 0 ) \
  140. { \
  141. DebugIncrementStackDepthCounter( ); \
  142. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3 ); \
  143. }
  144. #define BCATraceScope4( _szArgs, _arg1, _arg2, _arg3, _arg4 ) \
  145. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__) ); \
  146. if ( g_tfModule != 0 ) \
  147. { \
  148. DebugIncrementStackDepthCounter( ); \
  149. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3, _arg4 ); \
  150. }
  151. #define BCATraceScope5( _szArgs, _arg1, _arg2, _arg3, _arg4, _arg5 ) \
  152. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__) ); \
  153. if ( g_tfModule != 0 ) \
  154. { \
  155. DebugIncrementStackDepthCounter( ); \
  156. TraceMessage( TEXT(__FILE__), __LINE__, __MODULE__, mtfFUNC, TEXT("+ ") TEXT(__FUNCTION__) TEXT("( ") TEXT(_szArgs) TEXT(" )"), _arg1, _arg2, _arg3, _arg4, _arg5 ); \
  157. }
  158. #define BCATraceQIScope( _riid, _ppv ) \
  159. CBCATraceScope scopeTracker##__LINE__( TEXT(__FILE__), __LINE__, __MODULE__, TEXT(__FUNCTION__), _riid, _ppv )
  160. //////////////////////////////////////////////////////////////////////////////
  161. // Class Definitions
  162. //////////////////////////////////////////////////////////////////////////////
  163. //////////////////////////////////////////////////////////////////////////////
  164. //++
  165. //
  166. // class CBCATraceScope
  167. //
  168. // Description:
  169. // This class traces entry and exit of a scope. To use this class,
  170. // instantiate an object of this class in the scope to be traced.
  171. //
  172. //--
  173. //////////////////////////////////////////////////////////////////////////////
  174. class CBCATraceScope
  175. {
  176. public:
  177. const TCHAR * const m_pszFileName;
  178. const UINT m_uiLine;
  179. const TCHAR * const m_pszModuleName;
  180. const TCHAR * const m_pszScopeName;
  181. // Constructor - prints function entry.
  182. CBCATraceScope(
  183. const TCHAR * const pszFileNameIn
  184. , const UINT uiLineIn
  185. , const TCHAR * const pszModuleNameIn
  186. , const TCHAR * const pszScopeNameIn
  187. )
  188. : m_pszFileName( pszFileNameIn )
  189. , m_uiLine( uiLineIn )
  190. , m_pszModuleName( pszModuleNameIn )
  191. , m_pszScopeName( pszScopeNameIn )
  192. {
  193. } //*** CBCATraceScope::CBCATraceScope( )
  194. // Constructor for QIs
  195. CBCATraceScope(
  196. const TCHAR * const pszFileNameIn
  197. , const UINT uiLineIn
  198. , const TCHAR * const pszModuleNameIn
  199. , const TCHAR * const pszScopeNameIn
  200. , REFIID riid
  201. , void ** ppv
  202. )
  203. : m_pszFileName( pszFileNameIn )
  204. , m_uiLine( uiLineIn )
  205. , m_pszModuleName( pszModuleNameIn )
  206. , m_pszScopeName( pszScopeNameIn )
  207. {
  208. if ( g_tfModule != 0 )
  209. {
  210. WCHAR szGuid[ cchGUID_STRING_SIZE ];
  211. DebugIncrementStackDepthCounter( );
  212. TraceMessage(
  213. m_pszFileName
  214. , m_uiLine
  215. , m_pszModuleName
  216. , mtfFUNC
  217. , TEXT("+ %s( [IUnknown] %s, ppv = %#x )")
  218. , m_pszScopeName
  219. , PszTraceFindInterface( riid, szGuid )
  220. , ppv
  221. );
  222. }
  223. } //*** CBCATraceScope::CBCATraceScope( )
  224. // Destructor - prints function exit.
  225. ~CBCATraceScope( void )
  226. {
  227. if ( g_tfModule != 0 )
  228. {
  229. TraceMessage(
  230. m_pszFileName
  231. , m_uiLine
  232. , m_pszModuleName
  233. , mtfFUNC
  234. , TEXT("V %s")
  235. , m_pszScopeName
  236. );
  237. DebugDecrementStackDepthCounter( );
  238. }
  239. } //*** CBCATraceScope::~CBCATraceScope( )
  240. }; //*** class CBCATraceScope
  241. #else // ifdef DEBUG
  242. // For Logging functions.
  243. #include "Log.h"
  244. #define BCATraceMsg( _pszfn )
  245. #define BCATraceMsg1( _pszfn, _arg1 )
  246. #define BCATraceMsg2( _pszfn, _arg1, _arg2 )
  247. #define BCATraceMsg3( _pszfn, _arg1, _arg2, _arg3 )
  248. #define BCATraceMsg4( _pszfn, _arg1, _arg2, _arg3, _arg4 )
  249. #define BCATraceMsg5( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5 )
  250. #define BCATraceMsg6( _pszfn, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6 )
  251. #define BCATraceScope( _szArgs )
  252. #define BCATraceScope1( _szArgs, _arg1 )
  253. #define BCATraceScope2( _szArgs, _arg1, _arg2 )
  254. #define BCATraceScope3( _szArgs, _arg1, _arg2, _arg3 )
  255. #define BCATraceScope4( _szArgs, _arg1, _arg2, _arg3, _arg4 )
  256. #define BCATraceScope5( _szArgs, _arg1, _arg2, _arg3, _arg4, _arg5 )
  257. #define BCATraceQIScope( _riid, _ppv )
  258. #endif // ifdef DEBUG