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.

219 lines
5.9 KiB

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