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.

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