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.

121 lines
4.0 KiB

  1. //=--------------------------------------------------------------------------=
  2. // Debug.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // contains the various macros and the like which are only useful in DEBUG
  13. // builds
  14. //
  15. #ifndef _DEBUG_H_
  16. //=---------------------------------------------------------------------------=
  17. // all the things required to handle our ASSERT mechanism
  18. //=---------------------------------------------------------------------------=
  19. //
  20. #if DEBUG
  21. // Function Prototypes
  22. //
  23. VOID DisplayAssert(LPSTR pszMsg, LPSTR pszAssert, LPSTR pszFile, UINT line);
  24. VOID SetCtlSwitches (LPSTR lpFileName);
  25. // Macros
  26. //
  27. // *** Include this macro at the top of any source file using *ASSERT*() macros ***
  28. //
  29. #if !defined(SZTHISFILE)
  30. #define SZTHISFILE static char _szThisFile[] = __FILE__;
  31. #endif //!defined(SZTHISFILE)
  32. // our versions of the ASSERT and FAIL macros.
  33. //
  34. #if !defined(ASSERT)
  35. #define ASSERT(fTest, szMsg) \
  36. if (!(fTest)) { \
  37. static char szMsgCode[] = szMsg; \
  38. static char szAssert[] = #fTest; \
  39. DisplayAssert(szMsgCode, szAssert, _szThisFile, __LINE__); \
  40. }
  41. #endif //!defined(ASSERT)
  42. #if !defined(FAIL)
  43. #define FAIL(szMsg) \
  44. { static char szMsgCode[] = szMsg; \
  45. DisplayAssert(szMsgCode, "FAIL", _szThisFile, __LINE__); }
  46. #endif //!defined(FAIL)
  47. // macro that checks a pointer for validity on input
  48. //
  49. #define CHECK_POINTER(val) if (!(val) || IsBadReadPtr((void *)(val), sizeof(void *))) { FAIL("Pointer is NULL"); }
  50. //////
  51. // CCritSec
  52. // ~~~~~~~~
  53. // This is a class to help track down whether a critical section has been left
  54. // using a LeaveCriticalSection or not.
  55. //
  56. class CCritSec
  57. {
  58. public:
  59. CCritSec(CRITICAL_SECTION *CritSec);
  60. ~CCritSec();
  61. // methods
  62. void Left(void);
  63. private:
  64. // variables
  65. BOOL m_fLeft;
  66. CRITICAL_SECTION *m_pCriticalSection;
  67. }; // CCritSec
  68. #define ENTERCRITICALSECTION1(CriticalSection) CCritSec DebugCriticalSection1(CriticalSection)
  69. #define LEAVECRITICALSECTION1(CriticalSection) DebugCriticalSection1.Left()
  70. #define ENTERCRITICALSECTION2(CriticalSection) CCritSec DebugCriticalSection2(CriticalSection)
  71. #define LEAVECRITICALSECTION2(CriticalSection) DebugCriticalSection2.Left()
  72. #define ENTERCRITICALSECTION3(CriticalSection) CCritSec DebugCriticalSection3(CriticalSection)
  73. #define LEAVECRITICALSECTION3(CriticalSection) DebugCriticalSection3.Left()
  74. #else // DEBUG
  75. #if !defined(SZTHISFILE)
  76. #define SZTHISFILE
  77. #endif //!defined(SZTHISFILE)
  78. #if !defined(ASSERT)
  79. #define ASSERT(fTest, err)
  80. #endif //!defined(ASSERT)
  81. #if !defined(FAIL)
  82. #define FAIL(err)
  83. #endif //!defined(FAIL)
  84. #define CHECK_POINTER(val)
  85. #define ENTERCRITICALSECTION1(CriticalSection) EnterCriticalSection(CriticalSection)
  86. #define LEAVECRITICALSECTION1(CriticalSection) LeaveCriticalSection(CriticalSection)
  87. #define ENTERCRITICALSECTION2(CriticalSection) EnterCriticalSection(CriticalSection)
  88. #define LEAVECRITICALSECTION2(CriticalSection) LeaveCriticalSection(CriticalSection)
  89. #define ENTERCRITICALSECTION3(CriticalSection) EnterCriticalSection(CriticalSection)
  90. #define LEAVECRITICALSECTION3(CriticalSection) LeaveCriticalSection(CriticalSection)
  91. // Force compile errors when OutputDebugString used in Retail builds
  92. #ifndef USE_OUTPUTDEBUGSTRING_IN_RETAIL
  93. #undef OutputDebugString
  94. #define OutputDebugString(s)
  95. #endif
  96. #endif // DEBUG
  97. #define _DEBUG_H_
  98. #endif // _DEBUG_H_