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.

202 lines
4.5 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. --*/
  28. #ifndef _STIDEBUG_H_
  29. #define _STIDEBUG_H_
  30. #if defined(DEBUG)
  31. static const CHAR szFileName[] = __FILE__;
  32. #define _FILENAME_DEFINED_ONCE szFileName
  33. #endif
  34. #if defined(__cplusplus)
  35. extern "C"
  36. {
  37. #endif
  38. VOID UIAssertHelper( const CHAR* pszFileName, UINT nLine );
  39. VOID UIAssertSzHelper( const CHAR* pszMessage, const CHAR* pszFileName, UINT nLine );
  40. VOID AssertHelper( const CHAR* pszFileName, UINT nLine );
  41. VOID AssertSzHelper( const CHAR* pszMessage, const CHAR* pszFileName, UINT nLine );
  42. #if defined(DEBUG)
  43. # ifdef USE_MESSAGEBOX_UI
  44. # define ASSERT(exp) \
  45. { if (!(exp)) UIAssertHelper(__FILE__, __LINE__); }
  46. # define ASSERTSZ(exp, sz) \
  47. { if (!(exp)) UIAssertSzHelper((sz), __FILE__, __LINE__); }
  48. # else
  49. #ifndef ASSERT
  50. # define ASSERT(exp) \
  51. { if (!(exp)) AssertHelper(__FILE__, __LINE__); }
  52. #endif
  53. # define ASSERTSZ(exp, sz) \
  54. { if (!(exp)) AssertSzHelper((sz), __FILE__, __LINE__); }
  55. #define EVAL(exp) \
  56. ((exp) || AssertHelper(__FILE__, __LINE__))
  57. # endif // USE_MESSAGEBOX_UI
  58. # define UIASSERT(exp) ASSERT(exp)
  59. # define REQUIRE(exp) ASSERT(exp)
  60. #else // !DEBUG
  61. #ifndef ASSERT
  62. # define ASSERT(exp) ;
  63. #endif
  64. # define EVAL(exp) ;
  65. # define UIASSERT(exp) ;
  66. # define ASSERTSZ(exp, sz) ;
  67. # define REQUIRE(exp) { (exp); }
  68. #endif // DEBUG
  69. //
  70. // Debug mask management.
  71. //
  72. // NOTE: You can #define your own DM_* values using bits in the HI BYTE
  73. #define DM_TRACE 0x0001 // Trace messages
  74. #define DM_WARNING 0x0002 // Warning
  75. #define DM_ERROR 0x0004 // Error
  76. #define DM_ASSERT 0x0008 // Assertions
  77. #define DM_DATA 0x0010 // Data Transfered
  78. #define DM_INFO 0x0020 // Info we are currently interested in
  79. #define DM_LOG_FILE 0x0100
  80. #define DM_PREFIX 0x0200
  81. #if !defined(StiDebugMsg)
  82. //
  83. // StiDebugMsg(mask, msg, args...) - Generate wsprintf-formatted msg using
  84. // specified debug mask. System debug mask governs whether message is output.
  85. //
  86. #define REGVAL_STR_DEBUGMASK_A "DebugMask"
  87. #define REGVAL_STR_DEBUGMASK_W L"DebugMask"
  88. void __cdecl StiDebugMsg(UINT mask, LPCSTR psz, ...);
  89. UINT WINAPI StiSetDebugParameters(PSTR pszName,PSTR pszLogFile);
  90. UINT WINAPI StiSetDebugMask(UINT mask);
  91. UINT WINAPI StiGetDebugMask(void);
  92. #endif
  93. #ifdef DEBUG
  94. #define Break() DebugBreak()
  95. #define DPRINTF StiDebugMsg
  96. #else
  97. #define Break()
  98. //
  99. // Nb: Following definition is needed to avoid compiler complaining
  100. // about empty function name in expression. In retail builds using this macro
  101. // will cause string parameters not appear in executable
  102. //
  103. #define DPRINTF 1?(void)0 : (void)
  104. #endif
  105. #if defined(__cplusplus)
  106. }
  107. #endif
  108. #if defined(__cplusplus)
  109. #ifdef DEBUG
  110. class DBGTRACE
  111. {
  112. private:
  113. TCHAR m_szMessage[200];
  114. public:
  115. inline DBGTRACE(LPTSTR szMsg) {
  116. lstrcpy(m_szMessage,szMsg);
  117. DPRINTF(DM_TRACE,"ProcTraceEnter:%s",m_szMessage);
  118. }
  119. inline ~DBGTRACE() {
  120. DPRINTF(DM_TRACE,"ProcTraceExit:%s",m_szMessage);
  121. }
  122. };
  123. #else
  124. class DBGTRACE
  125. {
  126. public:
  127. inline DBGTRACE(LPTSTR szMsg) {
  128. }
  129. inline ~DBGTRACE() {
  130. }
  131. };
  132. #endif
  133. #endif
  134. #endif // _STIDEBUG_H_