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.

191 lines
5.5 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. // ONCE(code block)
  30. // Use this to make a code block execute only once per run.
  31. // Useful for cutting down on spew.
  32. // e.g.:
  33. // ONCE(WARNING(("Invalid arguments")));
  34. #define ONCE(codeblock) \
  35. { \
  36. static int doneOnce; \
  37. if (!doneOnce) \
  38. { \
  39. { codeblock ; } \
  40. doneOnce=1; \
  41. } \
  42. }
  43. #if DBG
  44. // Global debug level
  45. #define DBG_VERBOSE 1
  46. #define DBG_TERSE 2
  47. #define DBG_WARNING 3
  48. #define DBG_RIP 4
  49. extern int GpDebugLevel;
  50. ///////////////////////////// DEPRECATED STUFF ///////////////////////////////
  51. // Raw output function. Emits debug messages. Its direct use is depracated.
  52. // It's useful for private debugging, though.
  53. unsigned long _cdecl DbgPrint(char*, ...);
  54. // Strip the directory prefix from a filename
  55. const char*
  56. StripDirPrefix(
  57. const char* filename
  58. );
  59. // Use of DBGMSG is depracated - it's supplied only because driverd3d.cpp uses
  60. // it.
  61. #define DBGMSG(level, prefix, msg) \
  62. { \
  63. if (GpDebugLevel <= (level)) \
  64. { \
  65. DbgPrint("%s %s (%d): ", prefix, StripDirPrefix(__FILE__), __LINE__); \
  66. DbgPrint msg; \
  67. } \
  68. }
  69. ///////////////////////////// PRIVATE STUFF //////////////////////////////////
  70. // Just leave this function alone. You don't want to call it yourself. Trust me.
  71. char * _cdecl GpParseDebugString(char* format, ...);
  72. // Ditto for this one.
  73. void _cdecl GpLogDebugEvent(int level, char *file, unsigned int line, char *message);
  74. #define LOG_DEBUG_EVENT(level, msg) \
  75. { \
  76. if (GpDebugLevel <= (level)) \
  77. { \
  78. char *debugOutput = GpParseDebugString msg; \
  79. GpLogDebugEvent(level, __FILE__, __LINE__, debugOutput); \
  80. } \
  81. }
  82. //////////////////////////////// THE GOOD STUFF //////////////////////////////
  83. // These macros are used for debugging. They expand to
  84. // whitespace on a free build.
  85. //
  86. // GpDebugLevel
  87. // Global variable which holds the current debug level. You can use it to
  88. // control the quantity of debug messages emitted.
  89. //
  90. // VERBOSE(msg)
  91. // Display a message if the current debug level is <= DBG_VERBOSE.
  92. //
  93. // TERSE(msg)
  94. // Display a message if the current debug level is <= DBG_TERSE.
  95. //
  96. // WARNING(msg)
  97. // Display a message if the current debug level is <= DBG_WARNING.
  98. // The message format is: WRN filename (linenumber): message
  99. //
  100. // ASSERT(cond)
  101. // Verify that a condition is true. If not, force a breakpoint.
  102. //
  103. // ASSERTMSG(cond, msg)
  104. // Verify that a condition is true. If not, display a message and
  105. // force a breakpoint.
  106. //
  107. // RIP(msg)
  108. // Display a message and force a breakpoint.
  109. //
  110. // Usage:
  111. //
  112. // These macros require extra parentheses for the msg argument
  113. // for example:
  114. // WARNING(("App passed NULL pointer; ignoring it."));
  115. // ASSERTMSG(x > 0, ("x is less than 0"));
  116. //
  117. // Each call to an output function is treated as a separate event -
  118. // if you want to build up a message, e.g. in a loop, build it up in a
  119. // string, and then call the output function.
  120. //
  121. // This is because we don't always just output the string to the debugger -
  122. // when we link statically, we may send the output to a user-defined handler.
  123. //
  124. // Don't put a trailing \n on the message. If the output is sent to the
  125. // debugger, the output function will add the \n itself.
  126. #define VERBOSE(msg) LOG_DEBUG_EVENT(DBG_VERBOSE, msg)
  127. #define TERSE(msg) LOG_DEBUG_EVENT(DBG_TERSE, msg)
  128. #define WARNING(msg) LOG_DEBUG_EVENT(DBG_WARNING, msg)
  129. #define RIP(msg) LOG_DEBUG_EVENT(DBG_RIP, msg)
  130. #define ASSERT(cond) \
  131. { \
  132. if (! (cond)) \
  133. { \
  134. RIP(("Assertion failure: %s", #cond)); \
  135. } \
  136. }
  137. #define ASSERTMSG(cond, msg) \
  138. { \
  139. if (! (cond)) \
  140. { \
  141. RIP(msg); \
  142. } \
  143. }
  144. #else // !DBG
  145. //--------------------------------------------------------------------------
  146. // Retail build
  147. //--------------------------------------------------------------------------
  148. #define DBGMSG(level, prefix, msg) {}
  149. #define VERBOSE(msg) {}
  150. #define TERSE(msg) {}
  151. #define WARNING(msg) {}
  152. #define RIP(msg) {}
  153. #define ASSERT(cond) {}
  154. #define ASSERTMSG(cond, msg) {}
  155. #endif // !DBG
  156. #ifdef __cplusplus
  157. }
  158. #endif
  159. #endif // !_DEBUG_H