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.

114 lines
3.1 KiB

  1. /*
  2. * Some simple debugging macros that look and behave a lot like their
  3. * namesakes in MFC. These macros should work in both C and C++ and
  4. * do something useful with almost any Win32 compiler.
  5. *
  6. * George V. Reilly <georger@microcrafts.com> <a-georgr@microsoft.com>
  7. */
  8. #ifndef __DEBUG_H__
  9. #define __DEBUG_H__
  10. #ifdef _DEBUG
  11. # if defined(_MSC_VER) && (_MSC_VER >= 1000)
  12. /* Use the new debugging tools in Visual C++ 4.x */
  13. # include <crtdbg.h>
  14. /* _ASSERTE will give a more meaningful message, but the string takes
  15. * space. Use _ASSERT if this is an issue. */
  16. # define ASSERT(f) _ASSERTE(f)
  17. # else
  18. # include <assert.h>
  19. # define ASSERT(f) assert(f)
  20. # endif
  21. # define VERIFY(f) ASSERT(f)
  22. # define DEBUG_ONLY(f) (f)
  23. # define TRACE Trace
  24. # define TRACE0(psz) Trace(_T("%s"), _T(psz))
  25. # define TRACE1(psz, p1) Trace(_T(psz), p1)
  26. # define TRACE2(psz, p1, p2) Trace(_T(psz), p1, p2)
  27. # define TRACE3(psz, p1, p2, p3) Trace(_T(psz), p1, p2, p3)
  28. # define DEBUG_INIT() DebugInit()
  29. # define DEBUG_TERM() DebugTerm()
  30. #else /* !_DEBUG */
  31. /* These macros should all compile away to nothing */
  32. # define ASSERT(f) ((void)0)
  33. # define VERIFY(f) ((void)(f))
  34. # define DEBUG_ONLY(f) ((void)0)
  35. # define TRACE 1 ? (void)0 : Trace
  36. # define TRACE0(psz)
  37. # define TRACE1(psz, p1)
  38. # define TRACE2(psz, p1, p2)
  39. # define TRACE3(psz, p1, p2, p3)
  40. # define DEBUG_INIT() ((void)0)
  41. # define DEBUG_TERM() ((void)0)
  42. #endif /* !_DEBUG */
  43. #define ASSERT_POINTER(p, type) \
  44. ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
  45. #define ASSERT_NULL_OR_POINTER(p, type) \
  46. ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
  47. /* t-brianm (6-3-97) Added ASSERT_STRING macros */
  48. #define ASSERT_STRING(s) \
  49. ASSERT(((s) != NULL) && IsValidString((s), -1))
  50. #define ASSERT_NULL_OR_STRING(s) \
  51. ASSERT(((s) == NULL) || IsValidString((s), -1))
  52. /* Declarations for non-Windows apps */
  53. #ifndef _WINDEF_
  54. typedef void* LPVOID;
  55. typedef const void* LPCVOID;
  56. typedef unsigned int UINT;
  57. typedef int BOOL;
  58. typedef const char* LPCTSTR;
  59. #endif /* _WINDEF_ */
  60. #ifndef TRUE
  61. # define FALSE 0
  62. # define TRUE 1
  63. #endif
  64. #ifdef __cplusplus
  65. extern "C" {
  66. /* Low-level sanity checks for memory blocks */
  67. BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite = TRUE);
  68. BOOL IsValidString(LPCTSTR ptsz, int nLength = -1);
  69. #else /* !__cplusplus */
  70. /* Low-level sanity checks for memory blocks */
  71. BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite);
  72. BOOL IsValidString(LPCTSTR ptsz, int nLength);
  73. #endif /* !__cplusplus */
  74. /* in debug version, writes trace messages to debug stream */
  75. void __cdecl
  76. Trace(
  77. LPCTSTR pszFormat,
  78. ...);
  79. /* should be called from main(), WinMain(), or DllMain() */
  80. void
  81. DebugInit();
  82. void
  83. DebugTerm();
  84. #ifdef __cplusplus
  85. }
  86. #endif /* __cplusplus */
  87. #endif /* __DEBUG_H__ */