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.

179 lines
5.7 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 (at least, when FREETRACE is 0).
  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. ** Static libraries can safely use TRACE/DUMP without calling DEBUGINIT
  28. ** and DEBUGTERM. If the caller sets up these in his module, the library
  29. ** trace will appear as part of caller's module trace.
  30. **
  31. ** To use ASSERT:
  32. **
  33. ** Use ASSERT to assert that a given expression is true, breaking in the
  34. ** tracing console indicating the file and line number of the ASSERTION if
  35. ** it fails. It is not necessary to call DEBUGINIT and DEBUGTERM to use
  36. ** ASSERT. For example:
  37. **
  38. ** hwndOwner = GetParent( hwnd );
  39. ** ASSERT(hwndOwner!=NULL);
  40. */
  41. #ifndef _DEBUG_H_
  42. #define _DEBUG_H_
  43. #define FREETRACE 1
  44. /*----------------------------------------------------------------------------
  45. ** Datatypes and global declarations (defined in debug.c)
  46. **----------------------------------------------------------------------------
  47. */
  48. #if (DBG || FREETRACE)
  49. extern DWORD g_dwTraceId;
  50. typedef DWORD (APIENTRY * TRACEREGISTEREXA)( LPCSTR, DWORD );
  51. extern TRACEREGISTEREXA g_pTraceRegisterExA;
  52. typedef DWORD (APIENTRY * TRACEDEREGISTERA)( DWORD );
  53. extern TRACEDEREGISTERA g_pTraceDeregisterA;
  54. typedef DWORD (APIENTRY * TRACEDEREGISTEREXA)( DWORD, DWORD );
  55. extern TRACEDEREGISTEREXA g_pTraceDeregisterExA;
  56. typedef DWORD (APIENTRY * TRACEPRINTFA)( DWORD, LPCSTR, ... );
  57. extern TRACEPRINTFA g_pTracePrintfA;
  58. typedef DWORD (APIENTRY * TRACEPRINTFEXA)( DWORD, DWORD, LPCSTR, ... );
  59. extern TRACEPRINTFEXA g_pTracePrintfExA;
  60. typedef DWORD (APIENTRY * TRACEDUMPEXA)( DWORD, DWORD, LPBYTE, DWORD, DWORD, BOOL, LPCSTR );
  61. extern TRACEDUMPEXA g_pTraceDumpExA;
  62. typedef VOID (APIENTRY * ROUTERASSERT)( PSTR, PSTR, DWORD, PSTR );
  63. extern ROUTERASSERT g_pRouterAssert;
  64. #endif // (DBG || FREETRACE)
  65. /*----------------------------------------------------------------------------
  66. ** Macros
  67. **----------------------------------------------------------------------------
  68. */
  69. /* Debug macros. This code does not appear in non-DBG builds unless FREETRACE
  70. ** is defined.
  71. **
  72. ** The trailing number indicates the number of printf arguments in the format
  73. ** string. The argument is converted before output so that the output file
  74. ** remains entirely ANSI.
  75. */
  76. #if (DBG || FREETRACE)
  77. #define TRACE(a) \
  78. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a)
  79. #define TRACE1(a,b) \
  80. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b)
  81. #define TRACE2(a,b,c) \
  82. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c)
  83. #define TRACE3(a,b,c,d)\
  84. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d)
  85. #define TRACE4(a,b,c,d,e) \
  86. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d,e)
  87. #define TRACE5(a,b,c,d,e,f) \
  88. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d,e,f)
  89. #define TRACE6(a,b,c,d,e,f,g) \
  90. if (g_dwTraceId!=-1) g_pTracePrintfA(g_dwTraceId,a,b,c,d,e,f,g)
  91. #define TRACEX(l,a) \
  92. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a)
  93. #define TRACEX1(l,a,b) \
  94. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b)
  95. #define TRACEX2(l,a,b,c) \
  96. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c)
  97. #define TRACEX3(l,a,b,c,d)\
  98. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d)
  99. #define TRACEX4(l,a,b,c,d,e) \
  100. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d,e)
  101. #define TRACEX5(l,a,b,c,d,e,f) \
  102. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d,e,f)
  103. #define TRACEX6(l,a,b,c,d,e,f,h) \
  104. if (g_dwTraceId!=-1) g_pTracePrintfExA(g_dwTraceId,l,a,b,c,d,e,f,h)
  105. #define DUMPB(p,c) \
  106. if (g_dwTraceId!=-1) g_pTraceDumpExA(g_dwTraceId,1,(LPBYTE)p,c,1,1,NULL)
  107. #define DUMPDW(p,c) \
  108. if (g_dwTraceId!=-1) g_pTraceDumpExA(g_dwTraceId,1,(LPBYTE)p,c,4,1,NULL)
  109. #if defined(ASSERT)
  110. #undef ASSERT
  111. #endif
  112. #define ASSERT(a) \
  113. if ((g_dwTraceId!=-1) && !(a)) g_pRouterAssert(#a,__FILE__,__LINE__,NULL)
  114. #define DEBUGINIT(s) \
  115. DebugInit(s)
  116. #define DEBUGTERM() \
  117. DebugTerm()
  118. #else
  119. #define TRACE(a)
  120. #define TRACE1(a,b)
  121. #define TRACE2(a,b,c)
  122. #define TRACE3(a,b,c,d)
  123. #define TRACE4(a,b,c,d,e)
  124. #define TRACE5(a,b,c,d,e,f)
  125. #define TRACE6(a,b,c,d,e,f,g)
  126. #define TRACEX(l,a)
  127. #define TRACEX1(l,a,b)
  128. #define TRACEX2(l,a,b,c)
  129. #define TRACEX3(l,a,b,c,d)
  130. #define TRACEX4(l,a,b,c,d,e)
  131. #define TRACEX5(l,a,b,c,d,e,f)
  132. #define TRACEX6(l,a,b,c,d,e,f,g)
  133. #define DUMPB(p,c)
  134. #define DUMPDW(p,c)
  135. #if defined(ASSERT)
  136. #undef ASSERT
  137. #endif
  138. #define ASSERT(a)
  139. #define DEBUGINIT(s)
  140. #define DEBUGTERM()
  141. #endif
  142. /*----------------------------------------------------------------------------
  143. ** Prototypes (alphabetically)
  144. **----------------------------------------------------------------------------
  145. */
  146. VOID
  147. DebugInit(
  148. IN CHAR* pszModule );
  149. VOID
  150. DebugTerm(
  151. void );
  152. #endif // _DEBUG_H_