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.

186 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1998 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 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. # ifndef USE_DEBUG_CRTS
  35. /* IIS (and NT) do not ship msvcrtD.dll, per the VC license,
  36. * so we can't use the assertion code from <crtdbg.h>. Use similar
  37. * macros from <pudebug.h> instead. */
  38. # include <pudebug.h>
  39. /* workaround for /W4 warnings about 'constant expressions' */
  40. # define IRTLASSERT(f) \
  41. ((void) ((f) || (PuDbgAssertFailed(DBG_CONTEXT, #f), 0) ))
  42. # elif defined(_MSC_VER) && (_MSC_VER >= 1000)
  43. /* Use the new debugging tools in Visual C++ 4.x */
  44. # include <crtdbg.h>
  45. /* _ASSERTE will give a more meaningful message, but the string takes
  46. * space. Use _ASSERT if this is an issue. */
  47. # define IRTLASSERT(f) _ASSERTE(f)
  48. # else
  49. # include <assert.h>
  50. # define IRTLASSERT(f) assert(f)
  51. # endif
  52. # define IRTLVERIFY(f) IRTLASSERT(f)
  53. # define DEBUG_ONLY(f) (f)
  54. # define TRACE IrtlTrace
  55. # define TRACE0(psz) IrtlTrace(_T("%s"), _T(psz))
  56. # define TRACE1(psz, p1) IrtlTrace(_T(psz), p1)
  57. # define TRACE2(psz, p1, p2) IrtlTrace(_T(psz), p1, p2)
  58. # define TRACE3(psz, p1, p2, p3) IrtlTrace(_T(psz), p1, p2, p3)
  59. # define ASSERT_VALID(pObj) \
  60. do {IRTLASSERT((pObj) != NULL); (pObj)->AssertValid();} while (0)
  61. # define DUMP(pObj) \
  62. do {IRTLASSERT((pObj) != NULL); (pObj)->Dump();} while (0)
  63. # else /* !_DEBUG */
  64. /* These macros should all compile away to nothing */
  65. # define IRTLASSERT(f) ((void)0)
  66. # define IRTLVERIFY(f) ((void)(f))
  67. # define DEBUG_ONLY(f) ((void)0)
  68. # define TRACE 1 ? (void)0 : IrtlTrace
  69. # define TRACE0(psz)
  70. # define TRACE1(psz, p1)
  71. # define TRACE2(psz, p1, p2)
  72. # define TRACE3(psz, p1, p2, p3)
  73. # define ASSERT_VALID(pObj) ((void)0)
  74. # define DUMP(pObj) ((void)0)
  75. # endif /* !_DEBUG */
  76. # define ASSERT_POINTER(p, type) \
  77. IRTLASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
  78. # define ASSERT_NULL_OR_POINTER(p, type) \
  79. IRTLASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
  80. #define ASSERT_STRING(s) \
  81. IRTLASSERT(((s) != NULL) && IsValidString((s), -1))
  82. #define ASSERT_NULL_OR_STRING(s) \
  83. IRTLASSERT(((s) == NULL) || IsValidString((s), -1))
  84. /* Declarations for non-Windows apps */
  85. # ifndef _WINDEF_
  86. typedef void* LPVOID;
  87. typedef const void* LPCVOID;
  88. typedef unsigned int UINT;
  89. typedef int BOOL;
  90. typedef const char* LPCTSTR;
  91. # endif /* _WINDEF_ */
  92. # ifndef TRUE
  93. # define FALSE 0
  94. # define TRUE 1
  95. # endif
  96. # ifdef __cplusplus
  97. extern "C" {
  98. /* Low-level sanity checks for memory blocks */
  99. IRTL_DLLEXP BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite = TRUE);
  100. IRTL_DLLEXP BOOL IsValidString(LPCTSTR ptsz, int nLength = -1);
  101. }
  102. # else /* !__cplusplus */
  103. /* Low-level sanity checks for memory blocks */
  104. IRTL_DLLEXP BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite);
  105. IRTL_DLLEXP BOOL IsValidString(LPCTSTR ptsz, int nLength);
  106. # endif /* !__cplusplus */
  107. #endif /* !_AFX */
  108. /* Writes trace messages to debug stream */
  109. extern
  110. #ifdef __cplusplus
  111. "C"
  112. #endif /* !__cplusplus */
  113. IRTL_DLLEXP
  114. void __cdecl
  115. IrtlTrace(
  116. LPCTSTR pszFormat,
  117. ...);
  118. #ifdef _DEBUG
  119. # define IRTL_DEBUG_INIT() IrtlDebugInit()
  120. # define IRTL_DEBUG_TERM() IrtlDebugTerm()
  121. #else /* !_DEBUG */
  122. # define IRTL_DEBUG_INIT() ((void)0)
  123. # define IRTL_DEBUG_TERM() ((void)0)
  124. #endif /* !_DEBUG */
  125. #ifdef __cplusplus
  126. extern "C" {
  127. #endif /* __cplusplus */
  128. /* should be called from main(), WinMain(), or DllMain() */
  129. IRTL_DLLEXP void
  130. IrtlDebugInit();
  131. IRTL_DLLEXP void
  132. IrtlDebugTerm();
  133. #ifdef __cplusplus
  134. }
  135. #endif /* __cplusplus */
  136. #endif /* __IRTLDBG_H__ */