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.

180 lines
4.7 KiB

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