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.

107 lines
2.8 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. #if DBG
  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 /* !DBG */
  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 NOP_FUNCTION
  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 /* !DBG */
  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. /* Declarations for non-Windows apps */
  48. #ifndef _WINDEF_
  49. typedef void* LPVOID;
  50. typedef const void* LPCVOID;
  51. typedef unsigned int UINT;
  52. typedef int BOOL;
  53. typedef const char* LPCTSTR;
  54. #endif /* _WINDEF_ */
  55. #ifndef TRUE
  56. # define FALSE 0
  57. # define TRUE 1
  58. #endif
  59. #ifdef __cplusplus
  60. extern "C" {
  61. /* Low-level sanity checks for memory blocks */
  62. BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite = TRUE);
  63. BOOL IsValidString(LPCTSTR ptsz, int nLength = -1);
  64. #else /* !__cplusplus */
  65. /* Low-level sanity checks for memory blocks */
  66. BOOL IsValidAddress(LPCVOID pv, UINT nBytes, BOOL fReadWrite);
  67. BOOL IsValidString(LPCTSTR ptsz, int nLength);
  68. #endif /* !__cplusplus */
  69. /* in debug version, writes trace messages to debug stream */
  70. void __cdecl
  71. Trace(
  72. LPCTSTR pszFormat,
  73. ...);
  74. /* should be called from main(), WinMain(), or DllMain() */
  75. void
  76. DebugInit();
  77. void
  78. DebugTerm();
  79. #ifdef __cplusplus
  80. }
  81. #endif /* __cplusplus */
  82. #endif /* __DEBUG_H__ */