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.

247 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. stidebug.h
  5. Abstract:
  6. Environment independent assertion/logging routines
  7. Usage:
  8. ASSERT(exp) Evaluates its argument. If "exp" evals to
  9. FALSE, then the app will terminate, naming
  10. the file name and line number of the assertion
  11. in the source.
  12. UIASSERT(exp) Synonym for ASSERT.
  13. ASSERTSZ(exp,sz) As ASSERT, except will also print the message
  14. "sz" with the assertion message should it fail.
  15. REQUIRE(exp) As ASSERT, except that its expression is still
  16. evaluated in retail versions. (Other versions
  17. of ASSERT disappear completely in retail builds.)
  18. The ASSERT macros expect a symbol _FILENAME_DEFINED_ONCE, and will
  19. use the value of that symbol as the filename if found; otherwise,
  20. they will emit a new copy of the filename, using the ANSI C __FILE__
  21. macro. A client sourcefile may therefore define __FILENAME_DEFINED_ONCE
  22. in order to minimize the DGROUP footprint of a number of ASSERTs.
  23. Author:
  24. Vlad Sadovsky (vlads) 26-Jan-1997
  25. Revision History:
  26. 26-Jan-1997 VladS created
  27. 13-Apr-1999 VladS make UNICODE aware
  28. --*/
  29. #ifndef _STIDEBUG_H_
  30. #define _STIDEBUG_H_
  31. #if defined(DEBUG)
  32. static const char szFileName[] = __FILE__;
  33. #define _FILENAME_DEFINED_ONCE szFileName
  34. #endif
  35. #if defined(__cplusplus)
  36. extern "C"
  37. {
  38. #endif
  39. extern VOID UIAssertHelper( const CHAR* pszFileName, UINT nLine );
  40. extern VOID UIAssertSzHelper( const TCHAR* pszMessage, const CHAR* pszFileName, UINT nLine );
  41. extern VOID AssertHelper( const CHAR* pszFileName, UINT nLine );
  42. extern VOID AssertSzHelper( const TCHAR* pszMessage, const CHAR* pszFileName, UINT nLine );
  43. #if defined(DEBUG)
  44. # ifdef USE_MESSAGEBOX_UI
  45. # define ASSERT(exp) \
  46. { if (!(exp)) UIAssertHelper(__FILE__, __LINE__); }
  47. # define ASSERTSZ(exp, sz) \
  48. { if (!(exp)) UIAssertSzHelper((sz), __FILE__, __LINE__); }
  49. # else
  50. # define ASSERT(exp) \
  51. { if (!(exp)) AssertHelper(__FILE__, __LINE__); }
  52. # define ASSERTSZ(exp, sz) \
  53. { if (!(exp)) AssertSzHelper((sz), __FILE__, __LINE__); }
  54. #define EVAL(exp) \
  55. ((exp) || AssertHelper(__FILE__, __LINE__))
  56. # endif // USE_MESSAGEBOX_UI
  57. # define UIASSERT(exp) ASSERT(exp)
  58. # define REQUIRE(exp) ASSERT(exp)
  59. #else // !DEBUG
  60. # define ASSERT(exp) ;
  61. # define EVAL(exp) ;
  62. # define UIASSERT(exp) ;
  63. # define ASSERTSZ(exp, sz) ;
  64. # define REQUIRE(exp) { (exp); }
  65. #endif // DEBUG
  66. //
  67. // Debug mask management.
  68. //
  69. // NOTE: You can #define your own DM_* values using bits in the HI BYTE
  70. #define DM_TRACE 0x0001 // Trace messages
  71. #define DM_WARNING 0x0002 // Warning
  72. #define DM_ERROR 0x0004 // Error
  73. #define DM_ASSERT 0x0008 // Assertions
  74. #define DM_LOG_FILE 0x0100
  75. #define DM_PREFIX 0x0200
  76. #if !defined(StiDebugMsg)
  77. //
  78. // StiDebugMsg(mask, msg, args...) - Generate wsprintf-formatted msg using
  79. // specified debug mask. System debug mask governs whether message is output.
  80. //
  81. #define REGVAL_STR_DEBUGMASK_A "DebugMask"
  82. #define REGVAL_STR_DEBUGMASK_W L"DebugMask"
  83. void __cdecl StiDebugMsg(UINT mask, LPCTSTR psz, ...);
  84. UINT WINAPI StiSetDebugParameters(PTSTR pszName,PTSTR pszLogFile);
  85. UINT WINAPI StiSetDebugMask(UINT mask);
  86. UINT WINAPI StiGetDebugMask(void);
  87. #endif
  88. #ifdef DEBUG
  89. #define Break() DebugBreak()
  90. #define DPRINTF StiDebugMsg
  91. #else
  92. #define Break()
  93. //
  94. // Nb: Following definition is needed to avoid compiler complaining
  95. // about empty function name in expression. In retail builds using this macro
  96. // will cause string parameters not appear in executable
  97. //
  98. #define DPRINTF 1?(void)0 : (void)
  99. #endif
  100. #if defined(__cplusplus)
  101. }
  102. #endif
  103. #if defined(__cplusplus)
  104. #ifdef DEBUG
  105. class DBGTRACE
  106. {
  107. private:
  108. TCHAR m_szMessage[200];
  109. public:
  110. inline DBGTRACE(LPTSTR szMsg) {
  111. ZeroMemory(m_szMessage, sizeof(m_szMessage));
  112. lstrcpyn(m_szMessage,szMsg, sizeof(m_szMessage) / sizeof(m_szMessage[0]) - 1);
  113. DPRINTF(DM_TRACE,TEXT("ProcTraceEnter:%s At sec =%d "),
  114. m_szMessage,::GetTickCount()/1000);
  115. }
  116. inline ~DBGTRACE() {
  117. DPRINTF(DM_TRACE,TEXT("ProcTraceExit:%s At sec. =%d "),m_szMessage,::GetTickCount()/1000);
  118. }
  119. };
  120. #else
  121. class DBGTRACE
  122. {
  123. public:
  124. inline DBGTRACE(LPTSTR szMsg) {
  125. }
  126. inline ~DBGTRACE() {
  127. }
  128. };
  129. #endif
  130. #endif
  131. //
  132. // Performance monitoring
  133. //
  134. #if defined(__cplusplus)
  135. #ifdef DEBUG
  136. class TICK_COUNTER
  137. {
  138. private:
  139. UINT m_uiStartingCount;
  140. TCHAR m_szMessage[200];
  141. public:
  142. inline TICK_COUNTER(LPTSTR szMsg) {
  143. ZeroMemory(m_szMessage, sizeof(m_szMessage));
  144. lstrcpyn(m_szMessage,szMsg, sizeof(m_szMessage) / sizeof(m_szMessage[0]) - 1);
  145. m_uiStartingCount = ::GetTickCount();
  146. }
  147. inline ~TICK_COUNTER() {
  148. DPRINTF(DM_TRACE,TEXT("Elapsed time in (%s) is: %d ticks, %d seconds"),
  149. m_szMessage,
  150. ::GetTickCount() - m_uiStartingCount,
  151. (::GetTickCount() - m_uiStartingCount) / 1000
  152. );
  153. }
  154. inline ElapsedTicks(VOID) { return (::GetTickCount() - m_uiStartingCount);}
  155. };
  156. #else
  157. class TICK_COUNTER
  158. {
  159. public:
  160. inline TICK_COUNTER(LPTSTR szMsg) {
  161. }
  162. inline ~TICK_COUNTER() {
  163. }
  164. };
  165. #endif
  166. #endif
  167. #endif // _STIDEBUG_H_