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.

147 lines
2.9 KiB

  1. // Debug.h: generic debugging facilities.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #ifndef __DEBUG_H__
  5. #define __DEBUG_H__
  6. #ifdef _DEBUG
  7. //////////////////////////////////////////////////////////////////////
  8. // Class CTraceEx
  9. //
  10. // Implements TRACEX macro.
  11. // Don't ever use directly, just use TRACEX
  12. //
  13. class CTraceEx
  14. {
  15. // Construction/Destruction
  16. public:
  17. CTraceEx() { nIndent++; }
  18. ~CTraceEx() { nIndent--; }
  19. private:
  20. static int nIndent; // current indent level
  21. friend void AFX_CDECL AfxTrace(LPCTSTR lpszFormat, ...);
  22. };
  23. // NOTE: YOU MUST NOT USE TRACEX IN A ONE-LINE IF STATEMENT!
  24. // This will fail:
  25. //
  26. // if (foo)
  27. // TRACEX(...)
  28. //
  29. // Instead, you must enclose the TRACE in squiggle-brackets
  30. //
  31. // if (foo) {
  32. // TRACEX(...)
  33. // }
  34. //
  35. #define TRACEX CTraceEx __fooble; TRACE(_T("->")); TRACE
  36. // Goodies to get names of things.
  37. //
  38. extern CString sDbgName(CWnd* pWnd); // get name of window
  39. extern CString sDbgName(UINT uMsg); // get name of WM_ message
  40. #ifdef REFIID
  41. struct DBGINTERFACENAME {
  42. const IID* piid; // ptr to GUID
  43. LPCSTR name; // human-readable name of interface
  44. };
  45. // Change this to whatever interfaces you want to track
  46. // Default is none
  47. //
  48. extern DBGINTERFACENAME* _pDbgInterfaceNames;
  49. extern CString sDbgName(REFIID iid); // get name of COM interface
  50. #endif // REFIID
  51. #else // Not _DEBUG
  52. #define sDbgName(x) CString()
  53. #define TRACEX TRACE
  54. #endif
  55. // Macro casts to LPCTSTR for use with TRACE/printf/CString::Format
  56. //
  57. #define DbgName(x) (LPCTSTR)sDbgName(x)
  58. //////////////////////////////////////////////////////////////////////
  59. // Inlines
  60. inline bool CHECKOBJPTR(CObject* pObj, const CRuntimeClass* pClass, size_t size)
  61. {
  62. ASSERT(pObj);
  63. if( pObj == NULL )
  64. {
  65. TRACE(_T("WARNING : object pointer is NULL !\n"));
  66. return false;
  67. }
  68. if( ! AfxIsValidAddress((LPVOID)pObj,size) )
  69. {
  70. TRACE(_T("FAILED : object pointer points to invalid memory !\n"));
  71. return false;
  72. }
  73. ASSERT_VALID(pObj);
  74. if( ! pObj->IsKindOf(pClass) )
  75. {
  76. TRACE(_T("FAILED : object pointer is not of type %s !\n"),pClass->m_lpszClassName);
  77. return false;
  78. }
  79. return true;
  80. }
  81. inline bool CHECKPTR(LPVOID pVoid, size_t size)
  82. {
  83. ASSERT(pVoid);
  84. if( pVoid == NULL )
  85. {
  86. TRACE(_T("WARNING : pointer is NULL !\n"));
  87. return false;
  88. }
  89. if( ! AfxIsValidAddress((LPVOID)pVoid,size) )
  90. {
  91. TRACE(_T("FAILED : pointer points to invalid memory !\n"));
  92. return false;
  93. }
  94. return true;
  95. }
  96. inline bool CHECKHRESULT(HRESULT hr)
  97. {
  98. ASSERT(hr != E_FAIL);
  99. if( hr != S_OK )
  100. {
  101. TRACE(_T("FAILED : HRESULT=%X\n"),hr);
  102. // ASSERT(FALSE);
  103. return false;
  104. }
  105. return true;
  106. }
  107. #define TRACEARGn(Arg) (TRACE(_T("[")_T(#Arg)_T("]=%d\n"),Arg))
  108. #define TRACEARGs(Arg) (TRACE(_T("[")_T(#Arg)_T("]=%s\n"),Arg))
  109. #define GfxCheckObjPtr(p,classname) (CHECKOBJPTR(p,RUNTIME_CLASS(classname),sizeof(#classname)))
  110. #define GfxCheckPtr(p,classname) (CHECKPTR(p,sizeof(#classname)))
  111. #endif //__DEBUG_H__