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.

203 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name :
  4. irtldbg.h
  5. Abstract:
  6. Some simple debugging macros that look and behave a lot like their
  7. namesakes in MFC. These macros should work in both C and C++ and do
  8. something useful with almost any Win32 compiler.
  9. Author:
  10. George V. Reilly (GeorgeRe) 06-Jan-1998
  11. Environment:
  12. Win32 - User Mode
  13. Project:
  14. Internet Information Server RunTime Library
  15. Revision History:
  16. --*/
  17. #ifndef __IRTLDBG_H__
  18. #define __IRTLDBG_H__
  19. #ifndef __IRTLMISC_H__
  20. # include <irtlmisc.h>
  21. #endif
  22. /* Ensure that MessageBoxes can popup */
  23. # define IRTLDBG_RUNNING_AS_SERVICE 1
  24. #include <tchar.h>
  25. // Compile-time (not run-time) assertion. Code will not compile if
  26. // expr is false. Note: there is no non-debug version of this; we
  27. // want this for all builds. The compiler optimizes the code away.
  28. template <bool> struct static_checker;
  29. template <> struct static_checker<true> {}; // specialize only for `true'
  30. #define STATIC_ASSERT(expr) static_checker< (expr) >()
  31. # ifndef _AFX
  32. /* Assure compatiblity with MFC */
  33. # ifdef _DEBUG
  34. # define IRTLDEBUG
  35. # endif
  36. # ifdef IRTLDEBUG
  37. # ifndef USE_DEBUG_CRTS
  38. /* IIS (and NT) do not ship msvcrtD.dll, per the VC license,
  39. * so we can't use the assertion code from <crtdbg.h>. Use similar
  40. * macros from <pudebug.h> instead. */
  41. # include <pudebug.h>
  42. /* workaround for /W4 warnings about 'constant expressions' */
  43. # define IRTLASSERT(f) \
  44. ((void) ((f) || (PuDbgAssertFailed(DBG_CONTEXT, #f), 0) ))
  45. # elif defined(_MSC_VER) && (_MSC_VER >= 1000)
  46. /* Use the new debugging tools in Visual C++ 4.x */
  47. # include <crtdbg.h>
  48. /* _ASSERTE will give a more meaningful message, but the string takes
  49. * space. Use _ASSERT if this is an issue. */
  50. # define IRTLASSERT(f) _ASSERTE(f)
  51. # else
  52. # include <assert.h>
  53. # define IRTLASSERT(f) assert(f)
  54. # endif
  55. # define IRTLVERIFY(f) IRTLASSERT(f)
  56. # ifndef DEBUG_ONLY
  57. # define DEBUG_ONLY(f) (f)
  58. # endif
  59. # define IRTLTRACE IrtlTrace
  60. # define IRTLTRACE0(psz) IrtlTrace(_T("%s"), _T(psz))
  61. # define IRTLTRACE1(psz, p1) IrtlTrace(_T(psz), p1)
  62. # define IRTLTRACE2(psz, p1, p2) IrtlTrace(_T(psz), p1, p2)
  63. # define IRTLTRACE3(psz, p1, p2, p3) IrtlTrace(_T(psz), p1, p2, p3)
  64. # define IRTLTRACE4(psz, p1, p2, p3, p4) \
  65. IrtlTrace(_T(psz), p1, p2, p3, p4)
  66. # define IRTLTRACE5(psz, p1, p2, p3, p4, p5) \
  67. IrtlTrace(_T(psz), p1, p2, p3, p4, p5)
  68. # define ASSERT_VALID(pObj) \
  69. do {IRTLASSERT((pObj) != NULL); (pObj)->AssertValid();} while (0)
  70. # define DUMP(pObj) \
  71. do {IRTLASSERT((pObj) != NULL); (pObj)->Dump();} while (0)
  72. # else /* !IRTLDEBUG */
  73. /* These macros should all compile away to nothing */
  74. # define IRTLASSERT(f) ((void)0)
  75. # define IRTLVERIFY(f) ((void)(f))
  76. # ifndef DEBUG_ONLY
  77. # define DEBUG_ONLY(f) ((void)0)
  78. # endif
  79. # define IRTLTRACE 1 ? (void)0 : IrtlTrace
  80. # define IRTLTRACE0(psz) 1 ? (void)0 : IrtlTrace
  81. # define IRTLTRACE1(psz, p1) 1 ? (void)0 : IrtlTrace
  82. # define IRTLTRACE2(psz, p1, p2) 1 ? (void)0 : IrtlTrace
  83. # define IRTLTRACE3(psz, p1, p2, p3) 1 ? (void)0 : IrtlTrace
  84. # define IRTLTRACE4(psz, p1, p2, p3, p4) 1 ? (void)0 : IrtlTrace
  85. # define IRTLTRACE5(psz, p1, p2, p3, p4, p5) 1 ? (void)0 : IrtlTrace
  86. # define ASSERT_VALID(pObj) ((void)0)
  87. # define DUMP(pObj) ((void)0)
  88. # endif /* !IRTLDEBUG */
  89. # define ASSERT_POINTER(p, type) \
  90. IRTLASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
  91. # define ASSERT_NULL_OR_POINTER(p, type) \
  92. IRTLASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
  93. #define ASSERT_STRING(s) \
  94. IRTLASSERT(((s) != NULL) && IsValidString((s), -1))
  95. #define ASSERT_NULL_OR_STRING(s) \
  96. IRTLASSERT(((s) == NULL) || IsValidString((s), -1))
  97. /* Declarations for non-Windows apps */
  98. # ifndef _WINDEF_
  99. typedef void* LPVOID;
  100. typedef const void* LPCVOID;
  101. typedef unsigned int UINT;
  102. typedef int BOOL;
  103. typedef const char* LPCTSTR;
  104. # endif /* _WINDEF_ */
  105. # ifndef TRUE
  106. # define FALSE 0
  107. # define TRUE 1
  108. # endif
  109. # ifdef __cplusplus
  110. extern "C" {
  111. /* Low-level sanity checks for memory blocks */
  112. IRTL_DLLEXP BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite = TRUE);
  113. IRTL_DLLEXP BOOL IsValidString(LPCTSTR ptsz, int nLength = -1);
  114. }
  115. # else /* !__cplusplus */
  116. /* Low-level sanity checks for memory blocks */
  117. IRTL_DLLEXP BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite);
  118. IRTL_DLLEXP BOOL IsValidString(LPCTSTR ptsz, int nLength);
  119. # endif /* !__cplusplus */
  120. #else
  121. # define IRTLASSERT(f) _ASSERTE(f)
  122. #endif /* !_AFX */
  123. /* Writes trace messages to debug stream */
  124. extern
  125. #ifdef __cplusplus
  126. "C"
  127. #endif /* !__cplusplus */
  128. IRTL_DLLEXP
  129. void __cdecl
  130. IrtlTrace(
  131. LPCTSTR pszFormat,
  132. ...);
  133. #ifdef IRTLDEBUG
  134. # define IRTL_DEBUG_INIT() IrtlDebugInit()
  135. # define IRTL_DEBUG_TERM() IrtlDebugTerm()
  136. #else /* !IRTLDEBUG */
  137. # define IRTL_DEBUG_INIT() ((void)0)
  138. # define IRTL_DEBUG_TERM() ((void)0)
  139. #endif /* !IRTLDEBUG */
  140. #ifdef __cplusplus
  141. extern "C" {
  142. #endif /* __cplusplus */
  143. /* should be called from main(), WinMain(), or DllMain() */
  144. IRTL_DLLEXP void
  145. IrtlDebugInit();
  146. IRTL_DLLEXP void
  147. IrtlDebugTerm();
  148. #ifdef __cplusplus
  149. }
  150. #endif /* __cplusplus */
  151. #endif /* __IRTLDBG_H__ */