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.

227 lines
6.5 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 = _vsnprintf( _szStringizedParameterList, cb,
  87. pszParameterFormatString, Arguments );
  88. if( -1 == cb )
  89. _szStringizedParameterList[ sizeof(_szStringizedParameterList)-1 ] = '\0';
  90. }
  91. DbgPrintf( _ulTraceMask, " Parameters(%08X)%s(%s)\n", _pThis, _pszFunction,
  92. _szStringizedParameterList );
  93. }
  94. inline void
  95. CDebugFunctionAndParameterTrace::DbgPrintf( ULONG ulTraceMask, const char *pszFormat, ... )
  96. const
  97. {
  98. if( propInfoLevel & ulTraceMask )
  99. {
  100. va_list Arguments;
  101. va_start( Arguments, pszFormat );
  102. vdprintf( ulTraceMask, _pszInfoLevelString, pszFormat, Arguments );
  103. }
  104. }
  105. inline void
  106. CDebugFunctionAndParameterTrace::SuppressExitErrors()
  107. {
  108. _fSuppressExitErrors = TRUE;
  109. }
  110. inline
  111. CDebugFunctionAndParameterTrace::~CDebugFunctionAndParameterTrace()
  112. {
  113. if( SUCCEEDED(*_phr) )
  114. {
  115. DbgPrintf( _ulTraceMask, "Exiting (%08x)%s, returning %08x\n",
  116. _pThis, _pszFunction, *_phr );
  117. }
  118. else
  119. {
  120. if( STG_E_INVALIDPARAMETER == *_phr || STG_E_INVALIDPOINTER == *_phr )
  121. {
  122. DbgPrintf( _fSuppressExitErrors ? DEB_TRACE : DEB_ERROR,
  123. "Exiting (%08x)%s, returning %08x\n",
  124. _pThis, _pszFunction, *_phr );
  125. }
  126. else if( _fSuppressExitErrors || STG_E_REVERTED == *_phr )
  127. {
  128. DbgPrintf( DEB_IWARN, "Exiting (%08x)%s, returning %08x (%s)\n",
  129. _pThis, _pszFunction, *_phr, _szStringizedParameterList );
  130. }
  131. else
  132. {
  133. DbgPrintf( DEB_ERROR, "Exiting (%08x)%s, returning %08x (%s)\n",
  134. _pThis, _pszFunction, *_phr, _szStringizedParameterList );
  135. }
  136. }
  137. }
  138. #endif // #if DBG
  139. inline DWORD DbgFlag( HRESULT hr, DWORD dbgflag )
  140. {
  141. #if DBG==1
  142. return( FAILED(hr) ? DEB_ERROR : dbgflag );
  143. #else
  144. return 0;
  145. #endif
  146. }
  147. #ifdef _MAC
  148. inline void propInlineDebugOut(DWORD dwDebugLevel, CHAR *szFormat, ...)
  149. {
  150. #if 0
  151. if( DEB_PROP_MAP >= dwDebugLevel )
  152. {
  153. CHAR szBuffer[ 256 ];
  154. va_list Arguments;
  155. va_start( Arguments, szFormat );
  156. *szBuffer = '\p'; // This is a zero-terminated string.
  157. if( -1 == _vsnprintf( szBuffer+1, sizeof(szBuffer)-1, szFormat, Arguments ))
  158. {
  159. // Terminate the buffer, since the string was too long.
  160. szBuffer[ sizeof(szBuffer)-1 ] = '\0';
  161. }
  162. DebugStr( (unsigned char*) szBuffer );
  163. }
  164. #endif
  165. }
  166. #endif // #ifdef _MAC
  167. #if DBG
  168. # define propDbg(x) propInlineDebugOut x
  169. # define DBGBUF(buf) CHAR buf[400]
  170. CHAR *DbgFmtId(REFFMTID rfmtid, CHAR *pszBuf);
  171. CHAR *DbgMode(DWORD grfMode, CHAR *pszBuf);
  172. CHAR *DbgFlags(DWORD grfMode, CHAR *pszBuf);
  173. #else
  174. # define propDbg(x) {}
  175. # define DBGBUF(buf)
  176. # define DbgFmtId(rfmtid, pszBuf)
  177. # define DbgMode(grfMode, pszBuf)
  178. # define DbgFlags(grfMode, pszBuf)
  179. #endif