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.

363 lines
10 KiB

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