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.

175 lines
3.9 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * debug.h
  8. *
  9. * Abstract:
  10. *
  11. * Macros used for debugging purposes
  12. *
  13. * Revision History:
  14. *
  15. * 12/02/1998 davidx
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #ifndef _DEBUG_H
  20. #define _DEBUG_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. //
  25. // These macros are used for debugging purposes. They expand
  26. // to white spaces on a free build. Here is a brief description
  27. // of what they do and how they are used:
  28. //
  29. // _debugLevel
  30. // Global variable which set the current debug level to control
  31. // the amount of debug messages emitted.
  32. //
  33. // VERBOSE(msg)
  34. // Display a message if the current debug level is <= DBG_VERBOSE.
  35. //
  36. // TERSE(msg)
  37. // Display a message if the current debug level is <= DBG_TERSE.
  38. //
  39. // WARNING(msg)
  40. // Display a message if the current debug level is <= DBG_WARNING.
  41. // The message format is: WRN filename (linenumber): message
  42. //
  43. // ASSERT(cond)
  44. // Verify a condition is true. If not, force a breakpoint.
  45. //
  46. // ASSERTMSG(cond, msg)
  47. // Verify a condition is true. If not, display a message and
  48. // force a breakpoint.
  49. //
  50. // RIP(msg)
  51. // Display a message and force a breakpoint.
  52. //
  53. // Usage:
  54. //
  55. // These macros require extra parantheses for the msg argument
  56. // for example:
  57. // WARNING(("App passed NULL pointer, ignoring...\n"));
  58. // ASSERTMSG(x > 0, ("x is less than 0\n"));
  59. //
  60. #if DBG
  61. #ifndef _COMPLUS_GDI
  62. // Global debug level
  63. #define DBG_VERBOSE 1
  64. #define DBG_TERSE 2
  65. #define DBG_WARNING 3
  66. #define DBG_RIP 4
  67. extern INT _debugLevel;
  68. //--------------------------------------------------------------------------
  69. // Debug build for native DLL
  70. //--------------------------------------------------------------------------
  71. // Emit debug messages
  72. VOID DbgPrint(const CHAR*, ...);
  73. // Strip the directory prefix from a filename
  74. const CHAR*
  75. StripDirPrefix(
  76. const CHAR* filename
  77. );
  78. #define DBGMSG(level, prefix, msg) \
  79. { \
  80. if (_debugLevel <= (level)) \
  81. { \
  82. DbgPrint("%s %s (%d): ", prefix, StripDirPrefix(__FILE__), __LINE__); \
  83. DbgPrint msg; \
  84. } \
  85. }
  86. #define DBGPRINT(level, msg) \
  87. { \
  88. if (_debugLevel <= (level)) \
  89. { \
  90. DbgPrint msg; \
  91. } \
  92. }
  93. #else // _COMPLUS_GDI
  94. //--------------------------------------------------------------------------
  95. // Debug build COM+ IL
  96. //--------------------------------------------------------------------------
  97. VOID DbgPrint(const WCHAR* msg);
  98. VOID DebugBreak();
  99. #define DBGMSG(level, prefix, msg) \
  100. DbgPrint(L"*** DEBUG MESSAGE\n")
  101. #define DBGPRINT(level, msg) \
  102. DbgPrint(L"*** DEBUG MESSAGE\n")
  103. #endif // _COMPLUS_GDI
  104. #define VERBOSE(msg) DBGPRINT(DBG_VERBOSE, msg)
  105. #define TERSE(msg) DBGPRINT(DBG_TERSE, msg)
  106. #define WARNING(msg) DBGMSG(DBG_WARNING, "WRN", msg)
  107. #define ASSERT(cond) \
  108. { \
  109. if (! (cond)) \
  110. { \
  111. RIP(("\n")); \
  112. } \
  113. }
  114. #define ASSERTMSG(cond, msg) \
  115. { \
  116. if (! (cond)) \
  117. { \
  118. RIP(msg); \
  119. } \
  120. }
  121. #define RIP(msg) \
  122. { \
  123. DBGMSG(DBG_RIP, "RIP", msg); \
  124. DebugBreak(); \
  125. }
  126. #else // !DBG
  127. //--------------------------------------------------------------------------
  128. // Retail build
  129. //--------------------------------------------------------------------------
  130. #define VERBOSE(msg)
  131. #define TERSE(msg)
  132. #define WARNING(msg)
  133. #define ASSERT(cond)
  134. #define ASSERTMSG(cond, msg)
  135. #define RIP(msg)
  136. #define DBGMSG(level, prefix, msg)
  137. #define DBGPRINT(level, msg)
  138. #endif // !DBG
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif // !_DEBUG_H