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.

230 lines
6.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: propdbg.hxx
  7. //
  8. // Contents: Declarations for tracing property code
  9. //
  10. // History:
  11. // 28-Aug-96 MikeHill Added a Mac version of propinlineDebugOut
  12. // 03-Mar-98 MikeHill Added CDebugFunctionAndParameterTrace
  13. // for debug tracing.
  14. // 6/11/98 MikeHill
  15. // - Allow errors to be suppressed from dbg output.
  16. // - Ensure against stack corruption.
  17. //
  18. //--------------------------------------------------------------------------
  19. #ifndef _MAC
  20. DECLARE_DEBUG(prop)
  21. #endif
  22. #include <stdio.h> // vsprintf
  23. // Custom debug flags for the 'prop' info level
  24. #define DEB_PROP_INFO DEB_USER1
  25. #define DEB_PROP_TRACE_CREATE DEB_USER2
  26. // 'prop' macros for tracing external and internal routines, and tracing parameters.
  27. #if DBG == 1
  28. #define propXTrace(x) CDebugFunctionAndParameterTrace propTrace( this, &hr, "prop", DEB_TRACE, x);
  29. #define propITrace(x) CDebugFunctionAndParameterTrace propTrace( this, &hr, "prop", DEB_ITRACE, x);
  30. #define propXTraceStatic(x) CDebugFunctionAndParameterTrace propTrace( NULL, &hr, "prop", DEB_TRACE, x);
  31. #define propITraceStatic(x) CDebugFunctionAndParameterTrace propTrace( NULL, &hr, "prop", DEB_ITRACE, x);
  32. #define propTraceParameters(x) propTrace.Parameters x
  33. #define propSuppressExitErrors() propTrace.SuppressExitErrors()
  34. #else
  35. #define propXTrace(x) {}
  36. #define propITrace(x) {}
  37. #define propXTraceStatic(x) {}
  38. #define propITraceStatic(x) {}
  39. #define propTraceParameters(x) {}
  40. #define propSuppressExitErrors() {}
  41. #endif
  42. #if DBG
  43. class CDebugFunctionAndParameterTrace
  44. {
  45. public:
  46. CDebugFunctionAndParameterTrace( const void *pThis, const HRESULT *phr,
  47. const char *pszInfoLevelString, ULONG ulTraceMask,
  48. const char *pszFunction );
  49. void Parameters( const char *pszParameterFormatString = NULL, ... );
  50. ~CDebugFunctionAndParameterTrace();
  51. void DbgPrintf( ULONG ulTraceMask, const char *pszFormat, ... ) const;
  52. void SuppressExitErrors();
  53. private:
  54. const char * _pszFunction;
  55. const char * _pszInfoLevelString;
  56. char _szStringizedParameterList[ 2 * MAX_PATH ];
  57. ULONG _ulTraceMask;
  58. const void * _pThis;
  59. const HRESULT *_phr;
  60. BOOL _fSuppressExitErrors:1;
  61. }; // class CDebugFunctionAndParameterTrace
  62. inline
  63. CDebugFunctionAndParameterTrace::CDebugFunctionAndParameterTrace( const void *pThis,
  64. const HRESULT *phr,
  65. const char *pszInfoLevelString,
  66. ULONG ulTraceMask,
  67. const char *pszFunction )
  68. {
  69. _pszInfoLevelString = pszInfoLevelString;
  70. _pThis = pThis;
  71. _phr = phr;
  72. _pszFunction = pszFunction;
  73. _szStringizedParameterList[0] = '\0';
  74. _ulTraceMask = ulTraceMask;
  75. _fSuppressExitErrors = FALSE;
  76. DbgPrintf( _ulTraceMask, "Entering (%08x)%s\n", _pThis, _pszFunction );
  77. }
  78. inline void
  79. CDebugFunctionAndParameterTrace::Parameters( const char *pszParameterFormatString, ... )
  80. {
  81. va_list Arguments;
  82. va_start( Arguments, pszParameterFormatString );
  83. if( NULL != pszParameterFormatString )
  84. {
  85. int cb = sizeof(_szStringizedParameterList);
  86. cb = StringCbVPrintfA( _szStringizedParameterList,
  87. cb,
  88. pszParameterFormatString,
  89. Arguments );
  90. if( -1 == cb )
  91. _szStringizedParameterList[ sizeof(_szStringizedParameterList)-1 ] = '\0';
  92. }
  93. DbgPrintf( _ulTraceMask, " Parameters(%08X)%s(%s)\n", _pThis, _pszFunction,
  94. _szStringizedParameterList );
  95. }
  96. inline void
  97. CDebugFunctionAndParameterTrace::DbgPrintf( ULONG ulTraceMask, const char *pszFormat, ... )
  98. const
  99. {
  100. if( propInfoLevel & ulTraceMask )
  101. {
  102. va_list Arguments;
  103. va_start( Arguments, pszFormat );
  104. vdprintf( ulTraceMask, _pszInfoLevelString, pszFormat, Arguments );
  105. }
  106. }
  107. inline void
  108. CDebugFunctionAndParameterTrace::SuppressExitErrors()
  109. {
  110. _fSuppressExitErrors = TRUE;
  111. }
  112. inline
  113. CDebugFunctionAndParameterTrace::~CDebugFunctionAndParameterTrace()
  114. {
  115. if( SUCCEEDED(*_phr) )
  116. {
  117. DbgPrintf( _ulTraceMask, "Exiting (%08x)%s, returning %08x\n",
  118. _pThis, _pszFunction, *_phr );
  119. }
  120. else
  121. {
  122. if( STG_E_INVALIDPARAMETER == *_phr || STG_E_INVALIDPOINTER == *_phr )
  123. {
  124. DbgPrintf( _fSuppressExitErrors ? DEB_TRACE : DEB_ERROR,
  125. "Exiting (%08x)%s, returning %08x\n",
  126. _pThis, _pszFunction, *_phr );
  127. }
  128. else if( _fSuppressExitErrors || STG_E_REVERTED == *_phr )
  129. {
  130. DbgPrintf( DEB_IWARN, "Exiting (%08x)%s, returning %08x (%s)\n",
  131. _pThis, _pszFunction, *_phr, _szStringizedParameterList );
  132. }
  133. else
  134. {
  135. DbgPrintf( DEB_ERROR, "Exiting (%08x)%s, returning %08x (%s)\n",
  136. _pThis, _pszFunction, *_phr, _szStringizedParameterList );
  137. }
  138. }
  139. }
  140. #endif // #if DBG
  141. inline DWORD DbgFlag( HRESULT hr, DWORD dbgflag )
  142. {
  143. #if DBG==1
  144. return( FAILED(hr) ? DEB_ERROR : dbgflag );
  145. #else
  146. return 0;
  147. #endif
  148. }
  149. #ifdef _MAC
  150. inline void propInlineDebugOut(DWORD dwDebugLevel, CHAR *szFormat, ...)
  151. {
  152. #if 0
  153. if( DEB_PROP_MAP >= dwDebugLevel )
  154. {
  155. CHAR szBuffer[ 256 ];
  156. va_list Arguments;
  157. va_start( Arguments, szFormat );
  158. *szBuffer = '\p'; // This is a zero-terminated string.
  159. if( -1 == _vsnprintf( szBuffer+1, sizeof(szBuffer)-1, szFormat, Arguments ))
  160. {
  161. // Terminate the buffer, since the string was too long.
  162. szBuffer[ sizeof(szBuffer)-1 ] = '\0';
  163. }
  164. DebugStr( (unsigned char*) szBuffer );
  165. }
  166. #endif
  167. }
  168. #endif // #ifdef _MAC
  169. #if DBG
  170. # define propDbg(x) propInlineDebugOut x
  171. # define CB_DBGBUF 400
  172. # define DBGBUF(buf) CHAR buf[ CB_DBGBUF ]
  173. CHAR *DbgFmtId(REFFMTID rfmtid, CHAR *pszBuf);
  174. CHAR *DbgMode(DWORD grfMode, CHAR *pszBuf);
  175. CHAR *DbgFlags(DWORD grfMode, CHAR *pszBuf);
  176. #else
  177. # define propDbg(x) {}
  178. # define DBGBUF(buf)
  179. # define DbgFmtId(rfmtid, pszBuf)
  180. # define DbgMode(grfMode, pszBuf)
  181. # define DbgFlags(grfMode, pszBuf)
  182. #endif