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.

196 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1996 - 1999 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Macros used for debugging purposes
  7. Environment:
  8. Windows NT printer drivers
  9. Revision History:
  10. 03/16/96 -davidx-
  11. Created it.
  12. --*/
  13. #ifndef _DEBUG_H_
  14. #define _DEBUG_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. //
  19. // These macros are used for debugging purposes. They expand
  20. // to white spaces on a free build. Here is a brief description
  21. // of what they do and how they are used:
  22. //
  23. // giDebugLevel
  24. // Global variable which set the current debug level to control
  25. // the amount of debug messages emitted.
  26. //
  27. // VERBOSE(msg)
  28. // Display a message if the current debug level is <= DBG_VERBOSE.
  29. //
  30. // TERSE(msg)
  31. // Display a message if the current debug level is <= DBG_TERSE.
  32. //
  33. // WARNING(msg)
  34. // Display a message if the current debug level is <= DBG_WARNING.
  35. // The message format is: WRN filename (linenumber): message
  36. //
  37. // ERR(msg)
  38. // Similiar to WARNING macro above - displays a message
  39. // if the current debug level is <= DBG_ERROR.
  40. //
  41. // ASSERT(cond)
  42. // Verify a condition is true. If not, force a breakpoint.
  43. //
  44. // ASSERTMSG(cond, msg)
  45. // Verify a condition is true. If not, display a message and
  46. // force a breakpoint.
  47. //
  48. // RIP(msg)
  49. // Display a message and force a breakpoint.
  50. //
  51. // Usage:
  52. // These macros require extra parantheses for the msg argument
  53. // example, ASSERTMSG(x > 0, ("x is less than 0\n"));
  54. // WARNING(("App passed NULL pointer, ignoring...\n"));
  55. //
  56. #define DBG_VERBOSE 1
  57. #define DBG_TERSE 2
  58. #define DBG_WARNING 3
  59. #define DBG_ERROR 4
  60. #define DBG_RIP 5
  61. #if DBG
  62. //
  63. // Strip the directory prefix from a filename (ANSI version)
  64. //
  65. PCSTR
  66. StripDirPrefixA(
  67. IN PCSTR pstrFilename
  68. );
  69. extern INT giDebugLevel;
  70. #if defined(KERNEL_MODE) && !defined(USERMODE_DRIVER)
  71. extern VOID DbgPrint(PCSTR, ...);
  72. #define DbgBreakPoint EngDebugBreak
  73. #else
  74. extern ULONG _cdecl DbgPrint(PCSTR, ...);
  75. extern VOID DbgBreakPoint(VOID);
  76. #endif
  77. #define DBGMSG(level, prefix, msg) { \
  78. if (giDebugLevel <= (level)) { \
  79. DbgPrint("%s %s (%d): ", prefix, StripDirPrefixA(__FILE__), __LINE__); \
  80. DbgPrint msg; \
  81. } \
  82. }
  83. #define DBGPRINT(level, msg) { \
  84. if (giDebugLevel <= (level)) { \
  85. DbgPrint msg; \
  86. } \
  87. }
  88. #define VERBOSE(msg) DBGPRINT(DBG_VERBOSE, msg)
  89. #define TERSE(msg) DBGPRINT(DBG_TERSE, msg)
  90. #define WARNING(msg) DBGMSG(DBG_WARNING, "WRN", msg)
  91. #define ERR(msg) DBGMSG(DBG_ERROR, "ERR", msg)
  92. #ifndef __MDT__ // Don't redefine ASSERT when included in MINIDEV.EXE.
  93. #define ASSERT(cond) { \
  94. if (! (cond)) { \
  95. RIP(("\n")); \
  96. } \
  97. }
  98. #endif
  99. #define ASSERTMSG(cond, msg) { \
  100. if (! (cond)) { \
  101. RIP(msg); \
  102. } \
  103. }
  104. #define RIP(msg) { \
  105. DBGMSG(DBG_RIP, "RIP", msg); \
  106. DbgBreakPoint(); \
  107. }
  108. #else // !DBG
  109. #define VERBOSE(msg)
  110. #define TERSE(msg)
  111. #define WARNING(msg)
  112. #define ERR(msg)
  113. #ifndef __MDT__ // Don't redefine ASSERT when included in MINIDEV.EXE.
  114. #define ASSERT(cond)
  115. #endif
  116. #define ASSERTMSG(cond, msg)
  117. #define RIP(msg)
  118. #define DBGMSG(level, prefix, msg)
  119. #define DBGPRINT(level, msg)
  120. #endif
  121. //
  122. // The following macros let you enable tracing on per-file and per-function level.
  123. // To use these macros in a file, here is what you should do:
  124. //
  125. // At the beginning of the file (after header includes):
  126. //
  127. // Define a bit constant for each function you want to trace
  128. // Add the following line
  129. // DEFINE_FUNCTION_TRACE_FLAGS(flags);
  130. // where flags is a bit-wise OR of the functions you want to trace, e.g.
  131. // TRACE_FLAG_FUNC1 | TRACE_FLAG_FUNC2 | ...
  132. //
  133. // To generate trace inside each function you want to trace, use:
  134. // FUNCTION_TRACE(FunctionTraceFlag, (args));
  135. //
  136. #if DBG
  137. #define DEFINE_FUNCTION_TRACE_FLAGS(flags) \
  138. static DWORD gdwFunctionTraceFlags = (flags)
  139. #define FUNCTION_TRACE(flag, args) { \
  140. if (gdwFunctionTraceFlags & (flag)) { \
  141. DbgPrint args; \
  142. } \
  143. }
  144. #else // !DBG
  145. #define DEFINE_FUNCTION_TRACE_FLAGS(flags)
  146. #define FUNCTION_TRACE(flag, args)
  147. #endif // !DBG
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif // !_DEBUG_H_