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.

164 lines
3.8 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. // Global debug level
  62. #define DBG_VERBOSE 1
  63. #define DBG_TERSE 2
  64. #define DBG_WARNING 3
  65. #define DBG_RIP 4
  66. extern INT _debugLevel;
  67. //--------------------------------------------------------------------------
  68. // Debug build for native DLL
  69. //--------------------------------------------------------------------------
  70. // Emit debug messages
  71. ULONG DbgPrint(const CHAR*, ...);
  72. // Strip the directory prefix from a filename
  73. const CHAR*
  74. StripDirPrefix(
  75. const CHAR* filename
  76. );
  77. #define DBGMSG(level, prefix, msg) \
  78. do { \
  79. if (_debugLevel <= (level)) \
  80. { \
  81. DbgPrint("%s %s (%d): ", prefix, StripDirPrefix(__FILE__), __LINE__); \
  82. DbgPrint msg; \
  83. } \
  84. } while (0)
  85. #define DBGPRINT(level, msg) \
  86. do { \
  87. if (_debugLevel <= (level)) \
  88. { \
  89. DbgPrint msg; \
  90. } \
  91. } while (0)
  92. #define VERBOSE(msg) DBGPRINT(DBG_VERBOSE, msg)
  93. #define TERSE(msg) DBGPRINT(DBG_TERSE, msg)
  94. #define WARNING(msg) DBGMSG(DBG_WARNING, "WRN", msg)
  95. #define ASSERT(cond) \
  96. do { \
  97. if (! (cond)) \
  98. { \
  99. RIP(("\n")); \
  100. } \
  101. } while (0)
  102. #define ASSERTMSG(cond, msg) \
  103. do { \
  104. if (! (cond)) \
  105. { \
  106. RIP(msg); \
  107. } \
  108. } while (0)
  109. #define RIP(msg) \
  110. do { \
  111. DBGMSG(DBG_RIP, "RIP", msg); \
  112. DebugBreak(); \
  113. } while (0)
  114. #define ENTERFUNC(func) VERBOSE(("%x:%x: Enter "##func##"\n", GetCurrentProcessId(), GetCurrentThreadId()))
  115. #define LEAVEFUNC(func) VERBOSE(("%x:%x: Leave "##func##"\n", GetCurrentProcessId(), GetCurrentThreadId()))
  116. #else // !DBG
  117. //--------------------------------------------------------------------------
  118. // Retail build
  119. //--------------------------------------------------------------------------
  120. #define DbgPrint
  121. #define VERBOSE(msg)
  122. #define TERSE(msg)
  123. #define WARNING(msg)
  124. #define ASSERT(cond)
  125. #define ASSERTMSG(cond, msg)
  126. #define RIP(msg)
  127. #define DBGMSG(level, prefix, msg)
  128. #define DBGPRINT(level, msg)
  129. #define ENTERFUNC(func)
  130. #define LEAVEFUNC(func)
  131. #endif // !DBG
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif // !_DEBUG_H