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.

227 lines
6.9 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * Debugging macros
  8. *
  9. * Abstract:
  10. *
  11. * Macros used for debugging purposes
  12. *
  13. * Revision History:
  14. *
  15. * 12/02/1998 davidx
  16. * Created it.
  17. * 09/07/1999 agodfrey
  18. * Moved from Engine\Common
  19. * 02/07/2000 agodfrey
  20. * Made more of it private (for bug #35561).
  21. * Changed the output function to add "\n" automatically.
  22. *
  23. \**************************************************************************/
  24. #ifndef _DEBUG_H
  25. #define _DEBUG_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #if DBG
  30. // Global debug level
  31. #define DBG_VERBOSE 1
  32. #define DBG_TERSE 2
  33. #define DBG_WARNING 3
  34. #define DBG_RIP 4
  35. extern INT GpDebugLevel;
  36. ///////////////////////////// DEPRECATED STUFF ///////////////////////////////
  37. // Raw output function. Emits debug messages. Its direct use is depracated.
  38. // It's useful for private debugging, though.
  39. ULONG _cdecl DbgPrint(CHAR*, ...);
  40. // Strip the directory prefix from a filename
  41. const CHAR*
  42. StripDirPrefix(
  43. const CHAR* filename
  44. );
  45. // Use of DBGMSG is depracated - it's supplied only because driverd3d.cpp uses
  46. // it.
  47. #define DBGMSG(level, prefix, msg) \
  48. { \
  49. if (GpDebugLevel <= (level)) \
  50. { \
  51. DbgPrint("%s %s (%d): ", prefix, StripDirPrefix(__FILE__), __LINE__); \
  52. DbgPrint msg; \
  53. } \
  54. }
  55. ///////////////////////////// PRIVATE STUFF //////////////////////////////////
  56. // Just leave this function alone. You don't want to call it yourself. Trust me.
  57. CHAR * _cdecl GpParseDebugString(CHAR* format, ...);
  58. // Ditto for this one.
  59. VOID _cdecl GpLogDebugEvent(INT level, CHAR *file, UINT line, CHAR *message);
  60. #define LOG_DEBUG_EVENT(level, msg) \
  61. { \
  62. if (GpDebugLevel <= (level)) \
  63. { \
  64. CHAR *debugOutput = GpParseDebugString msg; \
  65. GpLogDebugEvent(level, __FILE__, __LINE__, debugOutput); \
  66. } \
  67. }
  68. //////////////////////////////// THE GOOD STUFF //////////////////////////////
  69. // These macros are used for debugging. They expand to
  70. // whitespace on a free build.
  71. //
  72. // GpDebugLevel
  73. // Global variable which holds the current debug level. You can use it to
  74. // control the quantity of debug messages emitted.
  75. //
  76. // VERBOSE(msg)
  77. // Display a message if the current debug level is <= DBG_VERBOSE.
  78. //
  79. // TERSE(msg)
  80. // Display a message if the current debug level is <= DBG_TERSE.
  81. //
  82. // WARNING(msg)
  83. // Display a message if the current debug level is <= DBG_WARNING.
  84. // The message format is: WRN filename (linenumber): message
  85. //
  86. // ASSERT(cond)
  87. // Verify that a condition is true. If not, force a breakpoint.
  88. //
  89. // ASSERTMSG(cond, msg)
  90. // Verify that a condition is true. If not, display a message and
  91. // force a breakpoint.
  92. //
  93. // RIP(msg)
  94. // Display a message and force a breakpoint.
  95. //
  96. // ONCE(code block)
  97. // Use this to make a code block execute only once per run.
  98. // Useful for cutting down on spew.
  99. // e.g.:
  100. // ONCE(WARNING(("Invalid arguments")));
  101. //
  102. // Usage:
  103. //
  104. // These macros require extra parentheses for the msg argument
  105. // for example:
  106. // WARNING(("App passed NULL pointer; ignoring it."));
  107. // ASSERTMSG(x > 0, ("x is less than 0"));
  108. //
  109. // Each call to an output function is treated as a separate event -
  110. // if you want to build up a message, e.g. in a loop, build it up in a
  111. // string, and then call the output function.
  112. //
  113. // This is because we don't always just output the string to the debugger -
  114. // when we link statically, we may send the output to a user-defined handler.
  115. //
  116. // Don't put a trailing \n on the message. If the output is sent to the
  117. // debugger, the output function will add the \n itself.
  118. #define VERBOSE(msg) LOG_DEBUG_EVENT(DBG_VERBOSE, msg)
  119. #define TERSE(msg) LOG_DEBUG_EVENT(DBG_TERSE, msg)
  120. #define WARNING(msg) LOG_DEBUG_EVENT(DBG_WARNING, msg)
  121. // SAVE_WARNING must be identical to WARNING
  122. #define SAVE_WARNING(msg) LOG_DEBUG_EVENT(DBG_WARNING, msg)
  123. // same as WARNING, but doesn't require extra set of ()'s for single string
  124. #define WARNING1(msg) LOG_DEBUG_EVENT(DBG_WARNING, (msg))
  125. #define RIP(msg) LOG_DEBUG_EVENT(DBG_RIP, msg)
  126. #define ASSERT(cond) \
  127. { \
  128. if (! (cond)) \
  129. { \
  130. RIP(("Assertion failure: %s", #cond)); \
  131. } \
  132. }
  133. #define ASSERTMSG(cond, msg) \
  134. { \
  135. if (! (cond)) \
  136. { \
  137. RIP(msg); \
  138. } \
  139. }
  140. #define ONCE(codeblock) \
  141. { \
  142. static int doneOnce; \
  143. if (!doneOnce) \
  144. { \
  145. { codeblock ; } \
  146. doneOnce=1; \
  147. } \
  148. }
  149. #else // !DBG
  150. //--------------------------------------------------------------------------
  151. // Retail build
  152. //--------------------------------------------------------------------------
  153. #define DBGMSG(level, prefix, msg) {}
  154. #define VERBOSE(msg) {}
  155. #define TERSE(msg) {}
  156. #define WARNING(msg) {}
  157. #define SAVE_WARNING(msg) {}
  158. #define WARNING1(msg) {}
  159. #define RIP(msg) {}
  160. #define ASSERT(cond) {}
  161. #define ASSERTMSG(cond, msg) {}
  162. #define ONCE(codeblock) {}
  163. #endif // !DBG
  164. // IF_NOT_OK_WARN_AND_RETURN(statusValue)
  165. // This macro is used when you want to return early in case of a failure
  166. // and spit out a debug warning.
  167. //
  168. // Originally we had an ASSERT instead of WARNING, but this prevented test
  169. // from running automation on checked build
  170. //
  171. // from David Brown:
  172. // I got fed up writing this little block again and again all over the
  173. // place.
  174. //
  175. // Looking at all the places that needed it I found I was often missing
  176. // the ASSERT, and sometimes doing the ASSERT but missing the return.
  177. //
  178. // Futhermore when written in full, this block takes more space than the
  179. // code around it making it difficult to see the wood for the trees.
  180. //
  181. // Although I generally avoid macros because thay make code less
  182. // obvious, I believe this one makes it safer in the long run.
  183. #define IF_NOT_OK_WARN_AND_RETURN(a) \
  184. if ((a) != Ok) \
  185. { \
  186. WARNING(("Status != Ok")); \
  187. return a; \
  188. }
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. #endif // !_DEBUG_H