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.

142 lines
3.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: dbg.h
  8. //
  9. //--------------------------------------------------------------------------
  10. /////////////////////////////////////////////////////////////////////
  11. // debug helpers
  12. #if defined(_USE_MTFRMWK_TRACE)
  13. #if defined(TRACE)
  14. #undef TRACE
  15. void MtFrmwkTrace(LPCWSTR, ...);
  16. #define TRACE MtFrmwkTrace
  17. #endif
  18. #else
  19. #if defined(TRACE)
  20. #undef TRACE
  21. #define TRACE
  22. #endif
  23. #endif
  24. #if defined(DBG)
  25. void MtFrmwkLogFile(LPCTSTR lpszFormat, ...);
  26. void MtFrmwkLogFileIfLog(BOOL bLog, LPCTSTR lpszFormat, ...);
  27. //
  28. // Copied from burnslib on 12-07-1999
  29. //
  30. #define TRACET MtFrmwkLogFile
  31. #define TRACE_LOGFILE MtFrmwkLogFile
  32. #define TRACE_LOGFILE_IF_NO_UI MtFrmwkLogFileIfLog
  33. #define TRACE_SCOPET(bLog, msg) \
  34. CScopeTracer __tracer(bLog, msg);
  35. #define TRACE_FUNCTION(func) TRACE_SCOPET(TRUE, TEXT(#func))
  36. #define TRACE_FUNCTION_IF_NO_UI(bLog, func) TRACE_SCOPET(bLog, TEXT(#func))
  37. #else
  38. #define TRACET
  39. #define TRACE_LOGFILE
  40. #define TRACE_LOGFILE_IF_NO_UI
  41. #define TRACE_SCOPET(bLog, msg)
  42. #define TRACE_FUNCTION(func)
  43. #define TRACE_FUNCTION_IF_NO_UI(bLog, func)
  44. #endif // defined(DBG)
  45. // A ScopeTracer object emits text to the log upon construction and
  46. // destruction. Place one at the beggining of a lexical scope, and it will
  47. // log when the scope is entered and exited.
  48. //
  49. // See TRACE_SCOPE, TRACE_CTOR, TRACE_DTOR, TRACE_FUNCTION, TRACE_FUNCTION2
  50. class CScopeTracer
  51. {
  52. public:
  53. CScopeTracer(BOOL bLog, PCWSTR pszMessage);
  54. ~CScopeTracer();
  55. private:
  56. CString szMessage;
  57. BOOL m_bLog;
  58. };
  59. //
  60. // Log provides an interface to a singleton application logging facility.
  61. //
  62. class CLogFile
  63. {
  64. friend class CScopeTracer;
  65. public:
  66. //
  67. // Returns a pointer to the single CLogFile instance.
  68. //
  69. static CLogFile* GetInstance();
  70. //
  71. // Closes and deletes the single CLogFile instance. If GetInstance is
  72. // called after this point, then a new instance will be created.
  73. //
  74. static void KillInstance();
  75. //
  76. // Returns true if the log file is open, false if not.
  77. //
  78. BOOL IsOpen() const;
  79. void writeln(PCWSTR pszText);
  80. void indent();
  81. void outdent();
  82. private:
  83. CLogFile(PCWSTR logBaseName);
  84. ~CLogFile();
  85. CString szBase_name;
  86. HANDLE file_handle;
  87. unsigned trace_line_number;
  88. //
  89. // not implemented; no instance copying allowed.
  90. //
  91. CLogFile(const CLogFile&);
  92. const CLogFile& operator=(const CLogFile&);
  93. };
  94. #if defined(_USE_MTFRMWK_ASSERT)
  95. #undef ASSERT
  96. #undef VERIFY
  97. #undef THIS_FILE
  98. #define THIS_FILE __FILE__
  99. BOOL MtFrmwkAssertFailedLine(LPCSTR lpszFileName, int nLine);
  100. #define ASSERT(f) \
  101. do \
  102. { \
  103. BOOL bPrefast = (f && L"a hack so that prefast doesn't bark"); \
  104. if (!(bPrefast) && MtFrmwkAssertFailedLine(THIS_FILE, __LINE__)) \
  105. ::DebugBreak(); \
  106. } while (0) \
  107. #define VERIFY(f) ASSERT(f)
  108. #endif // _USE_MTFRMWK_ASSERT