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.

125 lines
4.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: N C D E B U G . H
  7. //
  8. // Contents: Debug routines.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 24 Mar 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #ifndef _NCDEBUG_H_
  17. #define _NCDEBUG_H_
  18. #include "dbgflags.h" // For debugflags id definitions
  19. #include "trace.h"
  20. NOTHROW void InitializeDebugging ();
  21. NOTHROW void UnInitializeDebugging ();
  22. //
  23. // Useful macros to use with Asserts.
  24. // Eg, Assert(FImplies(sz, !*sz));
  25. // Assert(FIff(sz, cch));
  26. //
  27. #define FImplies(a,b) (!(a) || (b))
  28. #define FIff(a,b) (!(a) == !(b))
  29. //
  30. // "Normal" assertion checking. Provided for compatibility with
  31. // imported code.
  32. //
  33. // Assert(a) Displays a message indicating the file and line number
  34. // of this Assert() if a == 0.
  35. // AssertSz(a,b) As Assert(); also displays the message b (which should
  36. // be a string literal.)
  37. // SideAssert(a) As Assert(); the expression a is evaluated even if
  38. // asserts are disabled.
  39. //
  40. #undef AssertSz
  41. #undef Assert
  42. //+---------------------------------------------------------------------------
  43. //
  44. // DBG (checked) build
  45. //
  46. #ifdef DBG
  47. VOID
  48. DbgCheckPrematureDllUnload (
  49. PCSTR pszaDllName,
  50. UINT ModuleLockCount);
  51. typedef VOID (CALLBACK * PFNASSERTHOOK)(PCSTR, PCSTR, int);
  52. VOID WINAPI SetAssertFn (PFNASSERTHOOK);
  53. BOOL WINAPI FInAssert (VOID);
  54. VOID WINAPI AssertSzFn (PCSTR pszaMsg, PCSTR pszaFile, int nLine);
  55. VOID WINAPI AssertSzFn (PCSTR pszaMsg, PCSTR pszaFile, int nLine, PCSTR pszaFunc);
  56. VOID WINAPI AssertSzFnWithDbgPrompt (BOOL fPromptIgnore, PCSTR pszaMsg, PCSTR pszaFile, int nLine, PCSTR pszaFunc);
  57. VOID CALLBACK DefAssertSzFn (PCSTR pszaMsg, PCSTR pszaFile, int nLine);
  58. #define Assert(a) AssertSz(a, "Assert(" #a ")\r\n")
  59. #define AssertSz(a,b) if (!(a)) AssertSzFn(b, __FILE__, __LINE__);
  60. #define AssertSzWithDbgPromptIgnore(a,b) if (!(a)) AssertSzFnWithDbgPrompt(TRUE, b, __FILE__, __LINE__, __FUNCTION__);
  61. #define AssertSzWithDbgPromptRetry(a,b) if (!(a)) AssertSzFnWithDbgPrompt(FALSE, b, __FILE__, __LINE__, __FUNCTION__);
  62. //#define Assert(exp) if (!(exp)) RtlAssert(#exp, __FILE__, __LINE__, NULL)
  63. //#define AssertSz(exp,msg) if (!(exp)) RtlAssert(#exp, __FILE__, __LINE__, msg)
  64. #define AssertH Assert
  65. #define AssertSzH AssertSz
  66. void WINAPIV AssertFmt(BOOL fExp, PCSTR pszaFile, int nLine, PCSTR pszaFmt, ...);
  67. #define AssertValidReadPtrSz(p,msg) AssertSz(!IsBadReadPtr(p, sizeof(*p)), msg)
  68. #define AssertValidWritePtrSz(p,msg) AssertSz(!IsBadWritePtr(p, sizeof(*p)), msg)
  69. #define AssertValidReadPtr(p) AssertValidReadPtrSz(p,"Bad read pointer:" #p)
  70. #define AssertValidWritePtr(p) AssertValidWritePtrSz(p,"Bad write pointer:" #p)
  71. #define SideAssert(a) Assert(a)
  72. #define SideAssertH(a) AssertH(a)
  73. #define SideAssertSz(a,b) AssertSz(a,b)
  74. #define SideAssertSzH(a,b) AssertSzH(a,b)
  75. #define NYI(a) AssertSz(FALSE, "NYI: " a)
  76. #define NYIH(a) AssertSzH(FALSE, "NYI: " a)
  77. //+---------------------------------------------------------------------------
  78. //
  79. // !DBG (retail) build
  80. //
  81. #else
  82. #define DbgCheckPrematureDllUnload(a,b) NOP_FUNCTION
  83. #define AssertH(a)
  84. #define AssertSzH(a,b)
  85. #define Assert(a)
  86. #define AssertSz(a,b)
  87. #define AssertSzWithDbgPrompt(a,b)
  88. #define AssertFmt NOP_FUNCTION
  89. #define AssertValidReadPtrSz(p,msg) NOP_FUNCTION
  90. #define AssertValidWritePtrSz(p,msg) NOP_FUNCTION
  91. #define AssertValidReadPtr(p) NOP_FUNCTION
  92. #define AssertValidWritePtr(p) NOP_FUNCTION
  93. #define SideAssert(a) (a)
  94. #define SideAssertH(a) (a)
  95. #define SideAssertSz(a,b) (a)
  96. #define SideAssertSzH(a,b) (a)
  97. #define NYI(a) NOP_FUNCTION
  98. #endif // DBG
  99. #endif // _NCDEBUG_H_