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.

116 lines
3.5 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 CALLBACK DefAssertSzFn (PCSTR pszaMsg, PCSTR pszaFile, int nLine);
  56. #define Assert(a) AssertSz(a, "Assert(" #a ")\r\n")
  57. #define AssertSz(a,b) if (!(a)) AssertSzFn(b, __FILE__, __LINE__);
  58. #define AssertH Assert
  59. #define AssertSzH AssertSz
  60. void WINAPIV AssertFmt(BOOL fExp, PCSTR pszaFile, int nLine, PCSTR pszaFmt, ...);
  61. #define AssertValidReadPtrSz(p,msg) AssertSz(!IsBadReadPtr(p, sizeof(*p)), msg)
  62. #define AssertValidWritePtrSz(p,msg) AssertSz(!IsBadWritePtr(p, sizeof(*p)), msg)
  63. #define AssertValidReadPtr(p) AssertValidReadPtrSz(p,"Bad read pointer:" #p)
  64. #define AssertValidWritePtr(p) AssertValidWritePtrSz(p,"Bad write pointer:" #p)
  65. #define SideAssert(a) Assert(a)
  66. #define SideAssertH(a) AssertH(a)
  67. #define SideAssertSz(a,b) AssertSz(a,b)
  68. #define SideAssertSzH(a,b) AssertSzH(a,b)
  69. #define NYI(a) AssertSz(FALSE, "NYI: " a)
  70. #define NYIH(a) AssertSzH(FALSE, "NYI: " a)
  71. //+---------------------------------------------------------------------------
  72. //
  73. // !DBG (retail) build
  74. //
  75. #else
  76. #define DbgCheckPrematureDllUnload(a,b) NOP_FUNCTION
  77. #define AssertH(a)
  78. #define AssertSzH(a,b)
  79. #define Assert(a)
  80. #define AssertSz(a,b)
  81. #define AssertFmt NOP_FUNCTION
  82. #define AssertValidReadPtrSz(p,msg) NOP_FUNCTION
  83. #define AssertValidWritePtrSz(p,msg) NOP_FUNCTION
  84. #define AssertValidReadPtr(p) NOP_FUNCTION
  85. #define AssertValidWritePtr(p) NOP_FUNCTION
  86. #define SideAssert(a) (a)
  87. #define SideAssertH(a) (a)
  88. #define SideAssertSz(a,b) (a)
  89. #define SideAssertSzH(a,b) (a)
  90. #define NYI(a) NOP_FUNCTION
  91. #endif // DBG
  92. #endif // _NCDEBUG_H_