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.

153 lines
6.6 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: StandardDebug.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // This file defines standard debug macros for the consumer Windows additions
  7. // to Windows 2000 msgina.
  8. //
  9. // History: 1999-08-18 vtan created
  10. // 1999-09-10 vtan reworked macros
  11. // 2000-01-31 vtan moved from Neptune to Whistler
  12. // --------------------------------------------------------------------------
  13. #ifndef _StandardDebug_
  14. #define _StandardDebug_
  15. #ifdef DBG
  16. typedef enum
  17. {
  18. TRACE_ERROR_TYPE_WIN32 = 1,
  19. TRACE_ERROR_TYPE_BOOL,
  20. TRACE_ERROR_TYPE_HRESULT,
  21. TRACE_ERROR_TYPE_NTSTATUS
  22. } TRACE_ERROR_TYPE;
  23. static const int FLAG_BREAK_ON_ERROR = 0x00000001;
  24. extern LONG gLastResult;
  25. class CDebug
  26. {
  27. public:
  28. static void AttachUserModeDebugger (void);
  29. static void Break (void);
  30. static void BreakIfRequested (void);
  31. static void DisplayStandardPrefix (void);
  32. static void DisplayError (TRACE_ERROR_TYPE eType, LONG code, const char *pszFunction, const char *pszSource, int iLine);
  33. static void DisplayMessage (const char *pszMessage);
  34. static void DisplayAssert (const char *pszMessage, bool fForceBreak = false);
  35. static void DisplayWarning (const char *pszMessage);
  36. static void DisplayDACL (HANDLE hObject, SE_OBJECT_TYPE seObjectType);
  37. static NTSTATUS StaticInitialize (void);
  38. static NTSTATUS StaticTerminate (void);
  39. private:
  40. static void DisplaySID (PSID pSID);
  41. private:
  42. static bool s_fHasUserModeDebugger,
  43. s_fHasKernelModeDebugger;
  44. };
  45. #undef ASSERTMSG
  46. #define ASSERTMSG(condition, message) \
  47. if (!(condition)) \
  48. { \
  49. CDebug::DisplayAssert(message); \
  50. }
  51. #define ASSERTBREAKMSG(condition, message) \
  52. if (!(condition)) \
  53. { \
  54. CDebug::DisplayAssert(message, true); \
  55. }
  56. #define DISPLAYMSG(message) \
  57. { \
  58. CDebug::DisplayAssert(message); \
  59. }
  60. #define WARNINGMSG(message) \
  61. { \
  62. CDebug::DisplayWarning(message); \
  63. }
  64. #define INFORMATIONMSG(message) \
  65. { \
  66. CDebug::DisplayMessage(message); \
  67. }
  68. #define TW32(result) \
  69. if (ERROR_SUCCESS != (gLastResult = result)) \
  70. { \
  71. CDebug::DisplayError(TRACE_ERROR_TYPE_WIN32, gLastResult, #result, __FILE__, __LINE__); \
  72. }
  73. #define TBOOL(result) \
  74. if (result == FALSE) \
  75. { \
  76. CDebug::DisplayError(TRACE_ERROR_TYPE_BOOL, 0, #result, __FILE__, __LINE__); \
  77. }
  78. #define THR(result) \
  79. if (FAILED(gLastResult = result)) \
  80. { \
  81. CDebug::DisplayError(TRACE_ERROR_TYPE_HRESULT, gLastResult, #result, __FILE__, __LINE__); \
  82. }
  83. #define TSTATUS(result) \
  84. if (!NT_SUCCESS(gLastResult = result)) \
  85. { \
  86. CDebug::DisplayError(TRACE_ERROR_TYPE_NTSTATUS, gLastResult, #result, __FILE__, __LINE__); \
  87. }
  88. #define COMPILETIME_ASSERT(condition) \
  89. switch (0) case 0: case condition:
  90. #define DEBUGFILLMEMORY(address,size) \
  91. FillMemory(address, size, 0xA7)
  92. inline int _DebugExceptionFilter( LONG ecode, EXCEPTION_POINTERS* pep, LPSTR pszMsg, LONG lExceptionRet )
  93. {
  94. CHAR szBuf[512];
  95. #ifdef _STRSAFE_H_INCLUDED_
  96. StringCchPrintfA(szBuf, ARRAYSIZE(szBuf),
  97. #else _STRSAFE_H_INCLUDED_
  98. wsprintfA(szBuf,
  99. #endif _STRSAFE_H_INCLUDED_
  100. "%s\nEXCEPTION INFO: code: %08lx, record (.exr): %08lx, context (.cxr): %08lx\n",
  101. pszMsg, ecode, pep->ExceptionRecord, pep->ContextRecord);
  102. DISPLAYMSG(szBuf);
  103. return lExceptionRet;
  104. }
  105. #define DEBUG_TRY() __try {
  106. #define DEBUG_EXCEPT(pszAssertMsg) } __except(_DebugExceptionFilter(_exception_code(), (EXCEPTION_POINTERS*)_exception_info(), \
  107. pszAssertMsg, EXCEPTION_EXECUTE_HANDLER)) {\
  108. DebugBreak();}
  109. #else /* DBG */
  110. #undef ASSERTMSG
  111. #define ASSERTMSG(condition, message)
  112. #define ASSERTBREAKMSG(condition, message)
  113. #define DISPLAYMSG(message)
  114. #define WARNINGMSG(message)
  115. #define TW32(result) (LONG)result
  116. #define TBOOL(result) (BOOL)result
  117. #define THR(result) (HRESULT)result
  118. #define TSTATUS(result) (NTSTATUS)result
  119. #define DEBUGFILLMEMORY(address,size)
  120. #define DEBUG_TRY()
  121. #define DEBUG_EXCEPT(pszAssertMsg)
  122. #endif /* DBG */
  123. #endif /* _StandardDebug_ */