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.

236 lines
6.9 KiB

  1. /* Copyright (c) 1995, Microsoft Corporation, all rights reserved
  2. **
  3. ** debug.h
  4. ** Debug and tracing macros
  5. **
  6. ** 08/24/95 Steve Cobb
  7. **
  8. ** To use TRACE/DUMP:
  9. **
  10. ** These calls encapsulate dynamically linking to the tracing utilities in
  11. ** RTUTIL.DLL and provide shortcut macros to access them and to prevent
  12. ** their inclusion in non-DBG builds.
  13. **
  14. ** Before calling any TRACE/DUMP macros call:
  15. ** DEBUGINIT( "YOURMODULE" );
  16. **
  17. ** Use the TRACEx and DUMPx macros to print messages to the log as defined
  18. ** by the associated RTUTIL.DLL routines. Currently, this code is removed
  19. ** from non-DBG builds. A few examples:
  20. **
  21. ** TRACE("MyRoutine");
  22. ** TRACE2("MyRoutine=%d,c=%s",dwErr,psz);
  23. **
  24. ** After done calling TRACE/DUMP macros call:
  25. ** DEBUGTERM();
  26. **
  27. ** Exactly one file should have define the debug globals with the
  28. ** following while all other files should include the header without
  29. ** defining the manifest.
  30. **
  31. ** #define DEBUGGLOBALS
  32. ** #include <debug.h>
  33. **
  34. ** Static libraries can safely use TRACE/DUMP without calling DEBUGINIT
  35. ** and DEBUGTERM or defining DEBUGGLOBALS. If the caller sets up these in
  36. ** his module, the library trace will appear as part of caller's module
  37. ** trace.
  38. **
  39. ** To use ASSERT:
  40. **
  41. ** Use ASSERT to assert that a given expression is true, popping up a
  42. ** dialog indicating the file and line number of the ASSERTION if it
  43. ** fails. It is not necessary to call DEBUGINIT and DEBUGTERM to use
  44. ** ASSERT. For example:
  45. **
  46. ** hwndOwner = GetParent( hwnd );
  47. ** ASSERT(hwndOwner!=NULL);
  48. */
  49. #ifndef _DEBUG_H_
  50. #define _DEBUG_H_
  51. #define FREETRACE 1
  52. /*----------------------------------------------------------------------------
  53. ** Datatypes and global declarations (defined in debug.c)
  54. **----------------------------------------------------------------------------
  55. */
  56. #if (DBG || FREETRACE)
  57. extern DWORD g_dwTraceId;
  58. typedef DWORD (APIENTRY * TRACEREGISTEREXA)( LPCSTR, DWORD );
  59. extern TRACEREGISTEREXA g_pTraceRegisterExA;
  60. typedef DWORD (APIENTRY * TRACEDEREGISTERA)( DWORD );
  61. extern TRACEDEREGISTERA g_pTraceDeregisterA;
  62. typedef DWORD (APIENTRY * TRACEDEREGISTEREXA)( DWORD, DWORD );
  63. extern TRACEDEREGISTEREXA g_pTraceDeregisterExA;
  64. typedef DWORD (APIENTRY * TRACEPRINTFA)( DWORD, LPCSTR, ... );
  65. extern TRACEPRINTFA g_pTracePrintfA;
  66. typedef DWORD (APIENTRY * TRACEPRINTFEXA)( DWORD, DWORD, LPCSTR, ... );
  67. extern TRACEPRINTFEXA g_pTracePrintfExA;
  68. typedef DWORD (APIENTRY * TRACEDUMPEXA)( DWORD, DWORD, LPBYTE, DWORD, DWORD, BOOL, LPCSTR );
  69. extern TRACEDUMPEXA g_pTraceDumpExA;
  70. #endif // (DBG || FREETRACE)
  71. /*----------------------------------------------------------------------------
  72. ** Macros
  73. **----------------------------------------------------------------------------
  74. */
  75. /* Debug macros. This code does not appear in non-DBG builds unless FREETRACE
  76. ** is defined.
  77. **
  78. ** The trailing number indicates the number of printf arguments in the format
  79. ** string. TRACEW1 accepts a format string containing a single WCHAR*
  80. ** argument. The argument is converted before output so that the output file
  81. ** remains entirely ANSI.
  82. */
  83. #if (DBG || FREETRACE)
  84. #define TRACE(a) \
  85. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a)
  86. #define TRACE1(a,b) \
  87. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b)
  88. #define TRACE2(a,b,c) \
  89. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c)
  90. #define TRACE3(a,b,c,d)\
  91. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d)
  92. #define TRACE4(a,b,c,d,e) \
  93. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d,e)
  94. #define TRACE5(a,b,c,d,e,f) \
  95. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d,e,f)
  96. #define TRACE6(a,b,c,d,e,f,g) \
  97. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d,e,f,g)
  98. #define TRACEX(l,a) \
  99. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a)
  100. #define TRACEX1(l,a,b) \
  101. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b)
  102. #define TRACEX2(l,a,b,c) \
  103. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c)
  104. #define TRACEX3(l,a,b,c,d)\
  105. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d)
  106. #define TRACEX4(l,a,b,c,d,e) \
  107. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d,e)
  108. #define TRACEX5(l,a,b,c,d,e,f) \
  109. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d,e,f)
  110. #define TRACEX6(l,a,b,c,d,e,f,h) \
  111. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d,e,f,h)
  112. #define TRACE_ID(id,a) \
  113. if (id != -1) g_pTracePrintfA(id,a)
  114. #define TRACE_ID1(id,a,b) \
  115. if (id != -1) g_pTracePrintfA(id,a,b)
  116. #define TRACE_ID2(id,a,b,c) \
  117. if (id != -1) g_pTracePrintfA(id,a,b,c)
  118. #define TRACE_ID3(id,a,b,c,d)\
  119. if (id != -1) g_pTracePrintfA(id,a,b,c,d)
  120. #define TRACE_ID4(id,a,b,c,d,e) \
  121. if (id != -1) g_pTracePrintfA(id,a,b,c,d,e)
  122. #define TRACE_ID5(id,a,b,c,d,e,f) \
  123. if (id != -1) g_pTracePrintfA(id,a,b,c,d,e,f)
  124. #define TRACE_ID6(id,a,b,c,d,e,f,h) \
  125. if (id != -1) g_pTracePrintfA(id,a,b,c,d,e,f,h)
  126. #define TRACEW1(a,b) \
  127. if (g_dwTraceId!=-1) TracePrintfW1(a,b)
  128. #define DUMPB(p,c) \
  129. if (g_dwTraceId!=-1) g_pTraceDumpExA(g_dwTraceId,1,(LPBYTE)p,c,1,1,NULL)
  130. #define DUMPDW(p,c) \
  131. if (g_dwTraceId!=-1) g_pTraceDumpExA(g_dwTraceId,1,(LPBYTE)p,c,4,1,NULL)
  132. #if defined(ASSERT)
  133. #undef ASSERT
  134. #endif
  135. #if DBG
  136. #define ASSERT(a) \
  137. if (!(a)) Assert(#a,__FILE__,__LINE__)
  138. #else
  139. #define ASSERT(a)
  140. #endif
  141. #define DEBUGINIT(s) \
  142. DebugInit(s)
  143. #define DEBUGTERM() \
  144. DebugTerm()
  145. #else
  146. #define TRACE(a)
  147. #define TRACE1(a,b)
  148. #define TRACE2(a,b,c)
  149. #define TRACE3(a,b,c,d)
  150. #define TRACE4(a,b,c,d,e)
  151. #define TRACE5(a,b,c,d,e,f)
  152. #define TRACE6(a,b,c,d,e,f,g)
  153. #define TRACEX(l,a)
  154. #define TRACEX1(l,a,b)
  155. #define TRACEX2(l,a,b,c)
  156. #define TRACEX3(l,a,b,c,d)
  157. #define TRACEX4(l,a,b,c,d,e)
  158. #define TRACEX5(l,a,b,c,d,e,f)
  159. #define TRACEX6(l,a,b,c,d,e,f,g)
  160. #define TRACEW1(a,b)
  161. #define TRACE_ID(id,a)
  162. #define TRACE_ID1(id,a,b)
  163. #define TRACE_ID2(id,a,b,c)
  164. #define TRACE_ID3(id,a,b,c,d)
  165. #define TRACE_ID4(id,a,b,c,d,e)
  166. #define TRACE_ID5(id,a,b,c,d,e,f)
  167. #define TRACE_ID6(id,a,b,c,d,e,f,h)
  168. #define DUMPB(p,c)
  169. #define DUMPDW(p,c)
  170. #if defined(ASSERT)
  171. #undef ASSERT
  172. #endif
  173. #define ASSERT(a)
  174. #define DEBUGINIT(s)
  175. #define DEBUGTERM()
  176. #endif
  177. /*----------------------------------------------------------------------------
  178. ** Prototypes (alphabetically)
  179. **----------------------------------------------------------------------------
  180. */
  181. DWORD
  182. DebugInitEx(
  183. IN CHAR* pszModule,
  184. OUT LPDWORD lpdwId);
  185. VOID
  186. DebugTermEx(
  187. OUT LPDWORD lpdwTraceId );
  188. VOID
  189. DebugInit(
  190. IN CHAR* pszModule );
  191. VOID
  192. DebugTerm(
  193. void );
  194. VOID
  195. Assert(
  196. IN const CHAR* pszExpression,
  197. IN const CHAR* pszFile,
  198. IN UINT unLine );
  199. VOID
  200. TracePrintfW1(
  201. CHAR* pszFormat,
  202. TCHAR* psz1 );
  203. #endif // _DEBUG_H_