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.

124 lines
5.2 KiB

  1. #ifndef _DEBUG_H_
  2. #define _DEBUG_H_
  3. // Debug - used to track specific problems during debugging. Debug's are temporary,
  4. // and should be removed (or promoted to Info/Warning's) before check-in.
  5. // Info - general information during normal operation
  6. // Warning - warnings, recoverable errors
  7. // Error - things that shouldn't happen
  8. // Param - incorect params passed in, etc.
  9. // Interop - unexpected return codes/behavior from other (external) components
  10. // Assert - Assert-level really-shouldn't-happen errors.
  11. #define _TRACE_DEBUG 0
  12. #define _TRACE_INFO 1
  13. #define _TRACE_WARNING 2
  14. #define _TRACE_ERROR 3
  15. #define _TRACE_PARAM 4
  16. #define _TRACE_PARAWARN 5
  17. #define _TRACE_INTEROP 6
  18. #define _TRACE_ASSERT_D 7 // Debug-build assert - really does assert
  19. #define _TRACE_ASSERT_R 8 // Release-build assert - only logs error, doesn't halt program
  20. #define _TRACE_CALL 9
  21. #define _TRACE_RET 10
  22. void _Trace ( LPCTSTR pFile, ULONG uLineNo, DWORD dwLevel, const void * pThis, LPCTSTR pStr );
  23. // Also adds message corresponding to HRESULT...
  24. void _TraceHR ( LPCTSTR pFile, ULONG uLineNo, DWORD dwLevel, const void * pThis, HRESULT hr, LPCTSTR pStr );
  25. // Also adds message corresponding to GetLastError()...
  26. void _TraceW32 ( LPCTSTR pFile, ULONG uLineNo, DWORD dwLevel, const void * pThis, LPCTSTR pStr );
  27. //
  28. // _DTrace* is debug-only, while _Trace is debug and release...
  29. //
  30. #ifdef _DEBUG
  31. #define _DTrace( pFile, uLineNo, dwLevel, pThis, pStr ) _Trace( pFile, uLineNo, dwLevel, pThis, pStr )
  32. #define _DTraceHR( pFile, uLineNo, dwLevel, pThis, hr, pStr ) _TraceHR( pFile, uLineNo, dwLevel, pThis, hr, pStr )
  33. #define _DTraceW32( pFile, uLineNo, dwLevel, pThis, pStr ) _TraceW32( pFile, uLineNo, dwLevel, pThis, pStr )
  34. #define _TRACE_ASSERT _TRACE_ASSERT_D
  35. class DebugCallRetTracker
  36. {
  37. const void * m_pThis;
  38. LPCTSTR m_pMethodName;
  39. LPCTSTR m_pFile;
  40. ULONG m_Line;
  41. public:
  42. DebugCallRetTracker( const void * pThis, LPCTSTR pMethodName, LPCTSTR pFile, ULONG Line )
  43. : m_pThis( pThis ),
  44. m_pMethodName( pMethodName ),
  45. m_pFile( pFile ),
  46. m_Line( Line )
  47. {
  48. _Trace( m_pFile, m_Line, _TRACE_CALL, m_pThis, m_pMethodName );
  49. }
  50. ~DebugCallRetTracker( )
  51. {
  52. _Trace( m_pFile, m_Line, _TRACE_RET, m_pThis, m_pMethodName );
  53. }
  54. };
  55. #define IMETHOD( name ) DebugCallRetTracker IMETHOD_temp_var( this, TEXT( # name ), TEXT( __FILE__ ), __LINE__ )
  56. #else // _DEBUG
  57. #define _DTrace( pFile, uLineNo, dwLevel, pThis, pStr )
  58. #define _DTraceHR( pFile, uLineNo, dwLevel, hr, pThis, pStr )
  59. #define _DTraceW32( pFile, uLineNo, dwLevel, pThis, pStr )
  60. #define IMETHOD( name )
  61. #define _TRACE_ASSERT _TRACE_ASSERT_R
  62. #endif // _DEBUG
  63. #define Assert( cond ) if( cond ) { } else _Trace( TEXT( __FILE__ ), __LINE__, _TRACE_ASSERT, NULL, TEXT( # cond ) )
  64. #define AssertMsg( cond, str ) if( cond ) { } else _Trace( TEXT( __FILE__ ), __LINE__, _TRACE_ASSERT, NULL, str )
  65. #define TraceDebug( str ) _DTrace( TEXT( __FILE__ ), __LINE__, _TRACE_DEBUG, NULL, str )
  66. #define TraceInfo( str ) _DTrace( TEXT( __FILE__ ), __LINE__, _TRACE_INFO, NULL, str )
  67. #define TraceWarning( str ) _DTrace( TEXT( __FILE__ ), __LINE__, _TRACE_WARNING, NULL, str )
  68. #define TraceError( str ) _Trace( TEXT( __FILE__ ), __LINE__, _TRACE_ERROR, NULL, str )
  69. #define TraceParam( str ) _Trace( TEXT( __FILE__ ), __LINE__, _TRACE_PARAM, NULL, str )
  70. #define TraceParamWarn( str ) _Trace( TEXT( __FILE__ ), __LINE__, _TRACE_PARAMWARN, NULL, str )
  71. #define TraceInterop( str ) _Trace( TEXT( __FILE__ ), __LINE__, _TRACE_INTEROP, NULL, str )
  72. #define TraceDebugHR( hr, str ) _DTraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_DEBUG, NULL, hr, str )
  73. #define TraceInfoHR( hr, str ) _DTraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_INFO, NULL, hr, str )
  74. #define TraceWarningHR( hr, str ) _DTraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_WARNING, NULL, hr, str )
  75. #define TraceErrorHR( hr, str ) _TraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_ERROR, NULL, hr, str )
  76. #define TraceParamHR( hr, str ) _TraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_PARAM, NULL, hr, str )
  77. #define TraceParamWarnHR( hr, str ) _TraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_PARAMWARN, NULL, hr, str )
  78. #define TraceInteropHR( hr, str ) _TraceHR( TEXT( __FILE__ ), __LINE__, _TRACE_INTEROP, NULL, hr, str )
  79. #define TraceDebugW32( str ) _DTraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_DEBUG, NULL, str )
  80. #define TraceInfoW32( str ) _DTraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_INFO, NULL, str )
  81. #define TraceWarningW32( str ) _DTraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_WARNING, NULL, str )
  82. #define TraceErrorW32( str ) _TraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_ERROR, NULL, str )
  83. #define TraceParamW32( str ) _TraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_PARAM, NULL, str )
  84. #define TraceParamWarnW32( str ) _TraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_PARAMWARN, NULL, str )
  85. #define TraceInteropW32( str ) _TraceW32( TEXT( __FILE__ ), __LINE__, _TRACE_INTEROP, NULL, str )
  86. #endif // _DEBUG_H_