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.

334 lines
10 KiB

  1. /*----------------------------------------------------------------------
  2. dbgtrace.h
  3. Definitions for async tracing routines
  4. Copyright (C) 1994 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. gordm Gord Mangione
  8. History:
  9. 01/30/95 gordm Created.
  10. ----------------------------------------------------------------------*/
  11. #if !defined(_DBGTRACE_H_)
  12. #define _DBGTRACE_H_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifndef THIS_FILE
  17. #define THIS_FILE __FILE__
  18. #endif
  19. #if defined( NOTRACE )
  20. #define FLUSHASYNCTRACE // for _ASSERT below
  21. #define FatalTrace 1 ? (void)0 : PreAsyncTrace
  22. #define ErrorTrace 1 ? (void)0 : PreAsyncTrace
  23. #define DebugTrace 1 ? (void)0 : PreAsyncTrace
  24. #define StateTrace 1 ? (void)0 : PreAsyncTrace
  25. #define FunctTrace 1 ? (void)0 : PreAsyncTrace
  26. #define ErrorTraceX 1 ? (void)0 : PreAsyncTrace
  27. #define DebugTraceX 1 ? (void)0 : PreAsyncTrace
  28. #define MessageTrace( lParam, pbData, cbData )
  29. #define BinaryTrace( lParam, pbData, cbData )
  30. #define UserTrace( lParam, dwUserType, pbData, cbData )
  31. #define TraceFunctEnter( sz )
  32. #define TraceFunctEnterEx( lparam, sz )
  33. #define TraceFunctLeave()
  34. //
  35. // import functions from DBGTRACE.DLL
  36. //
  37. #define InitAsyncTrace()
  38. #define TermAsyncTrace()
  39. #define FlushAsyncTrace()
  40. __inline int PreAsyncTrace( LPARAM lParam, LPCSTR szFormat, ... )
  41. {
  42. return( 1);
  43. }
  44. #define MessageTrace( lParam, pbData, cbData )
  45. #define BinaryTrace( lParam, pbData, cbData )
  46. #define UserTrace( lParam, dwUserType, pbData, cbData )
  47. #else // NOTRACE
  48. #define FLUSHASYNCTRACE FlushAsyncTrace(), // for _ASSERT below
  49. #define FatalTrace !(__dwEnabledTraces & FATAL_TRACE_MASK) ? \
  50. (void)0 : \
  51. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, FATAL_TRACE_MASK ) && \
  52. PreAsyncTrace
  53. #define ErrorTrace !(__dwEnabledTraces & ERROR_TRACE_MASK) ? \
  54. (void)0 : \
  55. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, ERROR_TRACE_MASK ) && \
  56. PreAsyncTrace
  57. #define DebugTrace !(__dwEnabledTraces & DEBUG_TRACE_MASK) ? \
  58. (void)0 : \
  59. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, DEBUG_TRACE_MASK ) && \
  60. PreAsyncTrace
  61. #define StateTrace !(__dwEnabledTraces & STATE_TRACE_MASK) ? \
  62. (void)0 : \
  63. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, STATE_TRACE_MASK ) && \
  64. PreAsyncTrace
  65. #define FunctTrace !(__dwEnabledTraces & FUNCT_TRACE_MASK) ? \
  66. (void)0 : \
  67. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, FUNCT_TRACE_MASK ) && \
  68. PreAsyncTrace
  69. //
  70. // Support for unspecified function names
  71. //
  72. #define ErrorTraceX !(__dwEnabledTraces & ERROR_TRACE_MASK) ? \
  73. (void)0 : \
  74. SetAsyncTraceParams( THIS_FILE, __LINE__, "Fn", ERROR_TRACE_MASK ) && \
  75. PreAsyncTrace
  76. #define DebugTraceX !(__dwEnabledTraces & DEBUG_TRACE_MASK) ? \
  77. (void)0 : \
  78. SetAsyncTraceParams( THIS_FILE, __LINE__, "Fn", DEBUG_TRACE_MASK ) && \
  79. PreAsyncTrace
  80. //
  81. // use to explicitly remove function tracing even for debug builds
  82. //
  83. #define TraceQuietEnter( sz ) \
  84. char *___pszFunctionName = sz
  85. //
  86. // disable function tracing for retail builds
  87. // reduces code size increase and only should
  88. // only be used sparingly
  89. //
  90. #ifdef DEBUG
  91. #define TraceFunctEnter( sz ) \
  92. TraceQuietEnter( sz ); \
  93. FunctTrace( 0, "Entering %s", sz )
  94. #define TraceFunctLeave() \
  95. FunctTrace( 0, "Leaving %s", ___pszFunctionName )
  96. #define TraceFunctEnterEx( lParam, sz ) \
  97. TraceQuietEnter( sz ); \
  98. FunctTrace( lParam, "Entering %s", sz )
  99. #define TraceFunctLeaveEx( lParam ) \
  100. FunctTrace( lParam, "Leaving %s", ___pszFunctionName )
  101. #else
  102. #define TraceFunctEnter( sz ) TraceQuietEnter( sz )
  103. #define TraceFunctEnterEx( lParam, sz ) TraceQuietEnter( sz )
  104. #define TraceFunctLeave()
  105. #define TraceFunctLeaveEx( lParam )
  106. #endif
  107. //
  108. // fixed number of parameters for Binary trace macros
  109. //
  110. #define MessageTrace( lParam, pbData, cbData ) \
  111. !(__dwEnabledTraces & MESSAGE_TRACE_MASK) ? \
  112. (void)0 : \
  113. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, MESSAGE_TRACE_MASK ) && \
  114. AsyncBinaryTrace( lParam, TRACE_MESSAGE, pbData, cbData )
  115. #define BinaryTrace( lParam, pbData, cbData ) \
  116. !(__dwEnabledTraces & MESSAGE_TRACE_MASK) ? \
  117. (void)0 : \
  118. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, MESSAGE_TRACE_MASK ) && \
  119. AsyncBinaryTrace( lParam, TRACE_BINARY, pbData, cbData )
  120. #define UserTrace( lParam, dwUserType, pbData, cbData ) \
  121. !(__dwEnabledTraces & MESSAGE_TRACE_MASK) ? \
  122. (void)0 : \
  123. SetAsyncTraceParams( THIS_FILE, __LINE__, ___pszFunctionName, MESSAGE_TRACE_MASK ) && \
  124. AsyncBinaryTrace( lParam, dwUserType, pbData, cbData )
  125. ////////////////////////////////////////////////////////////////////////////////
  126. ////////////////////////////////////////////////////////////////////////////////
  127. ////////////////////////////////////////////////////////////////////////////////
  128. //
  129. // imported trace flag used by trace macros to determine if the trace
  130. // statement should be executed
  131. //
  132. extern DWORD __dwEnabledTraces;
  133. //
  134. // import functions from ATRACE.LIB
  135. //
  136. BOOL InitAsyncTrace ( void );
  137. BOOL TermAsyncTrace ( void );
  138. BOOL FlushAsyncTrace( void );
  139. void DebugAssert( DWORD dwLine, LPCSTR lpszFunction, LPCSTR lpszExpression );
  140. int SetAsyncTraceParams( LPCSTR pszFile, int iLine, LPCSTR szFunction, DWORD dwTraceMask );
  141. int AsyncStringTrace( LPARAM lParam, LPCSTR szFormat , va_list marker );
  142. int AsyncBinaryTrace( LPARAM lParam, DWORD dwBinaryType, LPBYTE pbData, DWORD cbData );
  143. ////////////////////////////////////////////////////////////////////////////////
  144. ////////////////////////////////////////////////////////////////////////////////
  145. ////////////////////////////////////////////////////////////////////////////////
  146. //
  147. // Trace flag constants
  148. //
  149. #define FATAL_TRACE_MASK 0x00000001
  150. #define ERROR_TRACE_MASK 0x00000002
  151. #define DEBUG_TRACE_MASK 0x00000004
  152. #define STATE_TRACE_MASK 0x00000008
  153. #define FUNCT_TRACE_MASK 0x00000010
  154. #define MESSAGE_TRACE_MASK 0x00000020
  155. #define ALL_TRACE_MASK 0xFFFFFFFF
  156. #define NUM_TRACE_TYPES 6
  157. //
  158. // Output trace types. used by tools to modify the
  159. // registry to change the output target
  160. //
  161. enum tagTraceOutputTypes {
  162. TRACE_OUTPUT_DISABLED = 0,
  163. TRACE_OUTPUT_FILE = 1,
  164. TRACE_OUTPUT_DEBUG = 2,
  165. TRACE_OUTPUT_DISCARD = 4 // used to find race windows
  166. };
  167. #define TRACE_OUTPUT_INVALID \
  168. ~(TRACE_OUTPUT_FILE|TRACE_OUTPUT_DEBUG|TRACE_OUTPUT_DISCARD)
  169. #define IsTraceFile(x) ((x) & TRACE_OUTPUT_FILE)
  170. #define IsTraceDebug(x) ((x) & TRACE_OUTPUT_DEBUG)
  171. #define IsTraceDiscard(x) ((x) & TRACE_OUTPUT_DISCARD)
  172. //
  173. // predefined types of binary trace types. User defined
  174. // types must be greater than 0x8000
  175. //
  176. enum tagBinaryTypes {
  177. TRACE_STRING = 0,
  178. TRACE_BINARY,
  179. TRACE_MESSAGE,
  180. TRACE_USER = 0x8000
  181. };
  182. #include <stdarg.h>
  183. //
  184. // use __inline to ensure grab __LINE__ and __FILE__
  185. //
  186. __inline int WINAPIV PreAsyncTrace( LPARAM lParam, LPCSTR szFormat, ... )
  187. {
  188. va_list marker;
  189. int iLength;
  190. va_start( marker, szFormat );
  191. iLength = AsyncStringTrace( lParam, szFormat, marker );
  192. va_end( marker );
  193. return iLength;
  194. }
  195. // !defined(NOTRACE) from way at the top of this include file
  196. #endif // !defined(NOTRACE)
  197. // Asserts are independent of tracing
  198. // (with the exception of flushing the trace buffer).
  199. //
  200. // For now enable ASSERT defines only if debugging is enabled
  201. //
  202. #ifdef DEBUG
  203. #define _ENABLE_ASSERTS
  204. #ifndef NOTRACE
  205. #define _ENABLE_VERBOSE_ASSERTS
  206. #endif // NO_TRACE
  207. #endif // DEBUG
  208. //
  209. // Macros added for doing asserts and verifies. basic clones
  210. // of the MFC macros with a prepended _ symbol
  211. //
  212. #ifdef _ENABLE_ASSERTS
  213. #ifndef _ASSERT
  214. #ifdef _ENABLE_VERBOSE_ASSERTS
  215. #define _ASSERT(f) !(f) ? DebugAssert( __LINE__, THIS_FILE, #f ) : ((void)0)
  216. #else
  217. #define _ASSERT(f) !(f) ? DebugBreak() : ((void)0)
  218. #endif //_ENABLE_VERBOSE_ASSERTS
  219. #endif
  220. #define _VERIFY(f) _ASSERT(f)
  221. #else
  222. #define _ASSERT(f) ((void)0)
  223. #define _VERIFY(f) ((void)(f))
  224. #endif // _ENABLE_ASSERTS
  225. #ifdef __cplusplus
  226. } // extern "C"
  227. ////////////////////////////////////////////////////////////////////////////////
  228. #ifdef NOTRACE
  229. #define TraceFunctEntry(sz)
  230. #else
  231. class CTraceEntry
  232. {
  233. public:
  234. CTraceEntry(char * psz)
  235. {
  236. this->___pszFunctionName = psz;
  237. FunctTrace( 0, "Entering %s", psz);
  238. }
  239. ~CTraceEntry()
  240. {
  241. FunctTrace( 0, "Leaving %s", this->___pszFunctionName);
  242. }
  243. char * ___pszFunctionName;
  244. };
  245. #define TraceFunctEntry(sz) CTraceEntry __cte(sz)
  246. #endif // NOTRACE
  247. ////////////////////////////////////////////////////////////////////////////////
  248. #endif
  249. #endif // !defined(_DBGTRACE_H_)