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.

206 lines
6.4 KiB

  1. /*----------------------------------------------------------------------------
  2. Dbgutil.H
  3. Exported header file for Dbgutil module.
  4. Copyright (C) Microsoft Corporation, 1993 - 1998
  5. All rights reserved.
  6. Authors:
  7. kennt Kenn Takara
  8. ----------------------------------------------------------------------------*/
  9. #ifndef _DBGUTIL_H
  10. #define _DBGUTIL_H
  11. #if _MSC_VER >= 1000 // VC 5.0 or later
  12. #pragma once
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #ifndef _OBJBASE_H_
  18. #include <objbase.h>
  19. #endif
  20. #if defined(_DEBUG) && !defined(DEBUG)
  21. #define DEBUG
  22. #endif
  23. #define DBG_API(type) __declspec( dllexport ) type FAR PASCAL
  24. #define DBG_APIV(type) __declspec( dllexport ) type FAR CDECL
  25. #define DBG_STRING(var, val) \
  26. static TCHAR var[] = _T(val);
  27. /*---------------------------------------------------------------------------
  28. Debug instance counter
  29. ---------------------------------------------------------------------------*/
  30. #ifdef _DEBUG
  31. inline void DbgInstanceRemaining(char * pszClassName, int cInstRem)
  32. {
  33. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  34. char buf[100];
  35. char title[100];
  36. char szModule[100];
  37. GetModuleFileNameA(AfxGetInstanceHandle(), szModule, 100);
  38. wsprintfA(buf, "%s has %d instances left over.", pszClassName, cInstRem);
  39. wsprintfA(title, "%s Memory Leak!!!", szModule);
  40. ::MessageBoxA(NULL, buf, title, MB_OK);
  41. }
  42. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls) extern int s_cInst_##cls = 0;
  43. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls) extern int s_cInst_##cls; ++(s_cInst_##cls);
  44. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls) extern int s_cInst_##cls; --(s_cInst_##cls);
  45. #define DEBUG_VERIFY_INSTANCE_COUNT(cls) \
  46. extern int s_cInst_##cls; \
  47. if (s_cInst_##cls) DbgInstanceRemaining(#cls, s_cInst_##cls);
  48. #else
  49. #define DEBUG_DECLARE_INSTANCE_COUNTER(cls)
  50. #define DEBUG_INCREMENT_INSTANCE_COUNTER(cls)
  51. #define DEBUG_DECREMENT_INSTANCE_COUNTER(cls)
  52. #define DEBUG_VERIFY_INSTANCE_COUNT(cls)
  53. #endif _DEBUG
  54. #ifdef _DEBUG
  55. DBG_API(HRESULT) HrReportExit(HRESULT hr, LPCTSTR szString);
  56. #else
  57. #define HrReportExit(hr,sz) hr
  58. #endif _DEBUG
  59. /*---------------------------------------------------------------------------
  60. Assert
  61. ---------------------------------------------------------------------------*/
  62. #define Panic() Assert0(FDbgFalse(), "Panic")
  63. #define Panic0(szFmt) Assert0(FDbgFalse(), szFmt)
  64. #define Panic1(szFmt, p1) Assert1(FDbgFalse(), szFmt, p1)
  65. #define Panic2(szFmt, p1, p2) Assert2(FDbgFalse(), szFmt, p1, p2)
  66. #define Panic3(szFmt, p1, p2, p3) Assert3(FDbgFalse(), szFmt, p1, p2, p3)
  67. #define Panic4(szFmt, p1, p2, p3, p4) Assert4(FDbgFalse(), szFmt, p1, p2, p3, p4)
  68. #define Panic5(szFmt, p1, p2, p3, p4, p5) Assert5(FDbgFalse(), szFmt, p1, p2, p3, p4, p5)
  69. #define SideAssert(f) Verify(f)
  70. #define AssertSz(f, sz) Assert0(f, sz)
  71. #if !defined(DEBUG)
  72. #define IfDebug(x)
  73. #define Verify(f) ((void)(f))
  74. #define Assert(f) ((void)0)
  75. #define Assert0(f, szFmt) ((void)0)
  76. #define Assert1(f, szFmt, p1) ((void)0)
  77. #define Assert2(f, szFmt, p1, p2) ((void)0)
  78. #define Assert3(f, szFmt, p1, p2, p3) ((void)0)
  79. #define Assert4(f, szFmt, p1, p2, p3, p4) ((void)0)
  80. #define Assert5(f, szFmt, p1, p2, p3, p4, p5) ((void)0)
  81. #else
  82. #ifndef THIS_FILE
  83. #define THIS_FILE __FILE__
  84. #endif
  85. #define IfDebug(x) x
  86. #define Verify(f) Assert(f)
  87. DBG_APIV(void) DbgAssert(LPCSTR szFileName, int iLine, LPCTSTR szFmt, ...);
  88. #define FDbgFalse() (0)
  89. #define Assert(f) \
  90. do { DBG_STRING(_sz, #f) \
  91. DBG_STRING(_szFmt, "%s") \
  92. if (!(f)) DbgAssert(THIS_FILE, __LINE__,_szFmt,(LPSTR)_sz); } while (FDbgFalse())
  93. #define Assert0(f, szFmt) \
  94. do { DBG_STRING(_sz, szFmt)\
  95. if (!(f)) DbgAssert(THIS_FILE, __LINE__, _sz); } while (FDbgFalse())
  96. #define Assert1(f, szFmt, p1) \
  97. do { DBG_STRING(_sz, szFmt)\
  98. if (!(f)) DbgAssert(THIS_FILE, __LINE__, _sz, p1); } while (FDbgFalse())
  99. #define Assert2(f, szFmt, p1, p2) \
  100. do { DBG_STRING(_sz, szFmt)\
  101. if (!(f)) DbgAssert(THIS_FILE, __LINE__, _sz, p1, p2); } while (FDbgFalse())
  102. #define Assert3(f, szFmt, p1, p2, p3) \
  103. do { DBG_STRING(_sz, szFmt)\
  104. if (!(f)) DbgAssert(THIS_FILE, __LINE__, _sz, p1, p2, p3); } while (FDbgFalse())
  105. #define Assert4(f, szFmt, p1, p2, p3, p4) \
  106. do { DBG_STRING(_sz, szFmt)\
  107. if (!(f)) DbgAssert(THIS_FILE, __LINE__, _sz, p1, p2, p3, p4); } while (FDbgFalse())
  108. #define Assert5(f, szFmt, p1, p2, p3, p4, p5) \
  109. do { DBG_STRING(_sz, szFmt)\
  110. if (!(f)) DbgAssert(THIS_FILE, __LINE__, _sz, p1, p2, p3, p4, p5); } while (FDbgFalse())
  111. #endif
  112. /*---------------------------------------------------------------------------
  113. Trace
  114. ---------------------------------------------------------------------------*/
  115. #if !defined(DEBUG)
  116. #define Trace0(szFmt) ((void)0)
  117. #define Trace1(szFmt, p1) ((void)0)
  118. #define Trace2(szFmt, p1, p2) ((void)0)
  119. #define Trace3(szFmt, p1, p2, p3) ((void)0)
  120. #define Trace4(szFmt, p1, p2, p3, p4) ((void)0)
  121. #define Trace5(szFmt, p1, p2, p3, p4, p5) ((void)0)
  122. #else
  123. DBG_APIV(LPCTSTR) DbgFmtFileLine ( const char * szFn, int line );
  124. DBG_APIV(void) DbgTrace(LPCTSTR szFileLine, LPTSTR szFormat, ...);
  125. #define szPreDbg DbgFmtFileLine(THIS_FILE, __LINE__)
  126. #define Trace0(szFmt) \
  127. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz); } while (FDbgFalse())
  128. #define Trace1(szFmt, p1) \
  129. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz, p1); } while (FDbgFalse())
  130. #define Trace2(szFmt, p1, p2) \
  131. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz, p1, p2); } while (FDbgFalse())
  132. #define Trace2(szFmt, p1, p2) \
  133. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz, p1, p2); } while (FDbgFalse())
  134. #define Trace3(szFmt, p1, p2, p3) \
  135. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz, p1, p2, p3); } while (FDbgFalse())
  136. #define Trace4(szFmt, p1, p2, p3, p4) \
  137. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz, p1, p2, p3, p4); } while (FDbgFalse())
  138. #define Trace5(szFmt, p1, p2, p3, p4, p5) \
  139. do { DBG_STRING(_sz, szFmt) DbgTrace(szPreDbg, _sz, p1, p2, p3, p4, p5); } while (FDbgFalse())
  140. #endif
  141. #if !defined(DEBUG)
  142. #define FImplies(a,b) (!(a) || (b))
  143. #define FIff(a,b) (!(a) == !(b))
  144. #else
  145. #define FImplies(a,b)
  146. #define FIff(a,b)
  147. #endif
  148. void DbgStop(void);
  149. #ifdef __cplusplus
  150. } // extern "C"
  151. #endif
  152. #endif // _DBGUTIL_H