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.

139 lines
3.4 KiB

  1. #ifndef _DEBUG_H_
  2. #define _DEBUG_H_
  3. #ifdef _DEBUG
  4. #ifdef __cplusplus
  5. #include "cstd.h"
  6. class INI
  7. {
  8. public:
  9. static UINT DtgProfileString( const TCHAR *szValue,
  10. const TCHAR *szDefault,
  11. TCHAR *szResult,
  12. INT cbResult,
  13. const TCHAR *szSection = _szSection );
  14. static UINT DtgProfileInt( const TCHAR *szValue,
  15. INT iDefault,
  16. const TCHAR *szSection = _szSection );
  17. static const TCHAR* SzDebugSection () { return _szSection ; }
  18. static const TCHAR* SzToolSection () { return _szSection ; }
  19. static BOOL DtgProfileTestDbgFlag(UINT fDbgFlag, BOOL fOr);
  20. static BOOL FExitOnAssert()
  21. {
  22. return DtgProfileInt(_szAssertExit, bTrue);
  23. }
  24. static UINT CAssertToPost()
  25. {
  26. return DtgProfileInt(_szAssertCount, 10);
  27. }
  28. static BOOL FAssertOnLeak()
  29. {
  30. return DtgProfileInt(_szAssertMemLeak, bTrue);
  31. }
  32. static BOOL FDebugFlag()
  33. {
  34. return DtgProfileInt(_szActive, bFalse);
  35. }
  36. static VOID WriteCallocStop(UINT cAlloc);
  37. static UINT CallocStopRead()
  38. {
  39. return DtgProfileInt(_szCallocStop, 0);
  40. }
  41. private:
  42. static const TCHAR* _szName;
  43. static const TCHAR* _szSection;
  44. static const TCHAR* _szToolSection;
  45. static const TCHAR* _szActive;
  46. static const TCHAR* _szAssertExit;
  47. static const TCHAR* _szAssertCount;
  48. static const TCHAR* _szAssertMemLeak;
  49. static const TCHAR* _szDebugFlag;
  50. static const TCHAR* _szCallocStop;
  51. };
  52. #endif
  53. #endif
  54. #define Assert(cond) AssertSz(cond, #cond)
  55. VOID DebugAppExit();
  56. // Return TRUE if the given bit(s) are on in the debug flag.
  57. // If 'fOr', any bit returns TRUE; if !fOr all bits must match.
  58. //extern BOOL DtgProfileTestDbgFlag ( UINT fDbgFlag, BOOL fOr = TRUE );
  59. // Return just the file name from a possibly full path.
  60. extern const char * DtgDbgReduceFileName ( const char * pszFileName ) ;
  61. #ifdef _DEBUG
  62. typedef UINT LINE;
  63. #define AssertData() static SZ __file__ = __FILE__
  64. extern VOID PrintFileLine(SZ, UINT);
  65. extern VOID AssertFailed(SZC szFile, LINE line, SZC szCond, BOOL bFatal);
  66. extern VOID DBVPrintf(SZ, ...);
  67. extern VOID CheckHeap();
  68. extern VOID NYI();
  69. extern VOID NotReached();
  70. extern BOOL fDebug;
  71. #if defined(MSBN)
  72. #define AssertSafeAlloc(count,typnam) \
  73. AssertSzFatal((long) count * sizeof(typnam) < 65535L,\
  74. "Attempt to allocate > 64K in block")
  75. #define DebugMSBN(x) x
  76. #else
  77. #define AssertSafeAlloc(count, typnam)
  78. #define DebugMSBN(x)
  79. #endif
  80. // Assert-with-messge macro; allows continuation skipping problem
  81. #define AssertSz(cond, sz)\
  82. if (!(cond))\
  83. AssertFailed(__file__, __LINE__, sz, fFalse);\
  84. else
  85. // Assert-with-message macro; forces program termination
  86. #define AssertSzFatal(cond, sz)\
  87. if (!(cond))\
  88. AssertFailed(__file__, __LINE__, sz, fTrue);\
  89. else
  90. #define Verify(x) Assert(x)
  91. #define Debug(x) x
  92. #define DBPrintf(fLevel, arglist)\
  93. ((fDebug & fLevel) ? (PrintFileLine(__FILE__, __LINE__),\
  94. (DBVPrintf arglist),\
  95. DBVPrintf("\r\n")) : 0)\
  96. #else // DEBUG
  97. // Null definitions for debug-message functions
  98. #define AssertSafeAlloc(count, typnam)
  99. #define AssertData()
  100. #define AssertSz(cond, sz)
  101. #define AssertSzFatal(cond, sz)
  102. #define Verify(cond) cond
  103. #define Debug(x)
  104. #define DebugMSBN(x)
  105. #define DBPrintf(x, y)
  106. #define CheckHeap()
  107. #define NYI()
  108. #define NotReached()
  109. #define Trace(szFunc)
  110. #endif // _DEBUG
  111. #endif // _DEBUG_H_