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.

138 lines
3.8 KiB

  1. //====== Assertion/Debug output APIs =================================
  2. #include <platform.h> // sdk\inc, for __endexcept
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //
  7. // Debug macros and validation code
  8. //
  9. #if !defined(UNIX) || (defined(UNIX) && !defined(NOSHELLDEBUG))
  10. // Undefine the macros that we define in case some other header
  11. // might have tried defining these commonly-named macros.
  12. #undef Assert
  13. #undef AssertE
  14. #undef AssertMsg
  15. #undef AssertStrLen
  16. #undef DebugMsg
  17. #undef FullDebugMsg
  18. #undef EVAL
  19. #undef ASSERTMSG // catch people's typos
  20. #undef DBEXEC
  21. #endif
  22. //
  23. // Debug macros and validation code
  24. //
  25. // Trace flags for g_dwTraceFlags
  26. #define TF_ALWAYS 0xFFFFFFFF
  27. #define TF_NEVER 0x00000000
  28. #define TF_WARNING 0x00000001
  29. #define TF_ERROR 0x00000002
  30. #define TF_GENERAL 0x00000004 // Standard messages
  31. #define TF_FUNC 0x00000008 // Trace function calls
  32. #define TF_ATL 0x00000008 // Since TF_FUNC is so-little used, I'm overloading this bit
  33. // (Upper 28 bits reserved for custom use per-module)
  34. // Old, archaic debug flags.
  35. // (scotth): the following flags will be phased out over time.
  36. #ifdef DM_TRACE
  37. #undef DM_TRACE
  38. #undef DM_WARNING
  39. #undef DM_ERROR
  40. #endif
  41. #define DM_TRACE TF_GENERAL // OBSOLETE Trace messages
  42. #define DM_WARNING TF_WARNING // OBSOLETE Warning
  43. #define DM_ERROR TF_ERROR // OBSOLETE Error
  44. // Use this macro to declare message text that will be placed
  45. // in the CODE segment (useful if DS is getting full)
  46. //
  47. // Ex: DEBUGTEXT(szMsg, "Invalid whatever: %d");
  48. //
  49. #define DEBUGTEXT(sz, msg) /* ;Internal */ \
  50. static const TCHAR sz[] = msg
  51. #ifdef DEBUG
  52. #ifdef _X86_
  53. // Use int 3 so we stop immediately in the source
  54. #define DEBUG_BREAK do { _try { _asm int 3 } _except (EXCEPTION_EXECUTE_HANDLER) {;} } while (0)
  55. #else
  56. #define DEBUG_BREAK do { _try { DebugBreak(); } _except (EXCEPTION_EXECUTE_HANDLER) {;} __endexcept } while (0)
  57. #endif
  58. #endif // DEBUG
  59. // ASSERT(f)
  60. //
  61. // Generates a "Assert file.c, line x (eval)" message if f is NOT true.
  62. //
  63. // Use ASSERT() to check for logic invariance. These are typically considered
  64. // fatal problems, and falls into the 'this should never ever happen'
  65. // category.
  66. //
  67. // Do *not* use ASSERT() to verify successful API calls if the APIs can
  68. // legitimately fail due to low resources. For example, LocalAlloc can
  69. // legally fail, so you shouldn't assert that it will never fail.
  70. //
  71. // The BF_ASSERT bit in g_dwBreakFlags governs whether the function
  72. // performs a DebugBreak().
  73. //
  74. // Default Behavior-
  75. // Retail builds: nothing
  76. // Debug builds: spew and break
  77. // Full debug builds: spew and break
  78. //
  79. #ifdef DEBUG
  80. BOOL CcshellAssertFailedA(LPCSTR szFile, int line, LPCSTR pszEval, BOOL bBreakInside);
  81. BOOL CcshellAssertFailedW(LPCWSTR szFile, int line, LPCWSTR pwszEval, BOOL bBreakInside);
  82. #ifdef UNICODE
  83. #define CcshellAssertFailed CcshellAssertFailedW
  84. #else
  85. #define CcshellAssertFailed CcshellAssertFailedA
  86. #endif
  87. #define ASSERT(f) \
  88. { \
  89. DEBUGTEXT(szFile, TEXT(__FILE__)); \
  90. if (!(f) && CcshellAssertFailed(szFile, __LINE__, TEXT(#f), FALSE)) \
  91. DEBUG_BREAK; \
  92. }
  93. #else // DEBUG
  94. #define ASSERT(f)
  95. #endif // DEBUG
  96. #ifdef DEBUG
  97. void CDECL _DebugMsgA(DWORD flag, LPCSTR psz, ...);
  98. void CDECL _DebugMsgW(DWORD flag, LPCWSTR psz, ...);
  99. #ifdef UNICODE
  100. #define _DebugMsg _DebugMsgW
  101. #else
  102. #define _DebugMsg _DebugMsgA
  103. #endif
  104. #define DebugMsg _DebugMsg
  105. #else // DEBUG
  106. #define DebugMsg 1 ? (void)0 : (void)
  107. #endif // DEBUG
  108. #ifdef __cplusplus
  109. };
  110. #endif