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.

154 lines
5.4 KiB

  1. /****************************Module*Header******************************\
  2. * Module Name: DEBUG.H
  3. *
  4. * Module Descripton: Debugging macros for ICM project
  5. *
  6. * Warnings:
  7. *
  8. * Issues:
  9. *
  10. * Created: 8 January 1996
  11. * Author: Srinivasan Chandraekar [srinivac]
  12. *
  13. * Copyright (c) 1996, 1997 Microsoft Corporation
  14. \***********************************************************************/
  15. #ifndef _DEBUG_H_
  16. #define _DEBUG_H_
  17. #if DBG
  18. //
  19. // These are used for debugging purposes, and do not generate code in the
  20. // retail version of the driver.
  21. //
  22. // A global variable (again present only in the debug build) maintains the
  23. // current debug level in the low order WORD. The high order WORD is treated
  24. // as a bitfield and is used to give more flexibility to debugging.
  25. //
  26. PSTR StripDirPrefixA(PSTR);
  27. VOID MyDebugPrintW(PWSTR, ...);
  28. VOID MyDebugPrintA(PSTR, ...);
  29. #ifdef UNICODE
  30. #define MyDebugPrint MyDebugPrintW
  31. #else
  32. #define MyDebugPrint MyDebugPrintA
  33. #endif
  34. #define DBGPRINT MyDebugPrint
  35. #define DBGPRINTA MyDebugPrintA
  36. #define DBGBREAK() DebugBreak()
  37. //
  38. // List of debug levels for low WORD of gdwDebugControl
  39. //
  40. #define DBG_LEVEL_VERBOSE 0x00000001
  41. #define DBG_LEVEL_TERSE 0x00000002
  42. #define DBG_LEVEL_WARNING 0x00000003
  43. #define DBG_LEVEL_ERROR 0x00000004
  44. #define DBG_LEVEL_FATAL 0x00000005
  45. //
  46. // Bits used in the high WORD of gdwDebugControl
  47. //
  48. #define FLAG_TRACEAPI 0x00010000 // Trace API entries
  49. #define CHECK_DBG_LEVEL(level) ((level) >= gdwDebugControl)
  50. #define TRACEAPI(funcname) \
  51. { \
  52. if (gdwDebugControl & FLAG_TRACEAPI) \
  53. { \
  54. DBGPRINTA("ICM: Entering function "); \
  55. DBGPRINT funcname; \
  56. } \
  57. }
  58. #define DBGMSG(level, mesg) \
  59. { \
  60. if (CHECK_DBG_LEVEL(level)) \
  61. { \
  62. DBGPRINTA("ICM: %s (%d): ", \
  63. StripDirPrefixA(__FILE__), __LINE__); \
  64. DBGPRINT mesg; \
  65. } \
  66. }
  67. //
  68. // These are the main macros that you'll be using in your code.
  69. // For giving additional parameters enclose the parameters in
  70. // paranthesis as shown in the example below.
  71. //
  72. // WARNING((__TEXT("Out of memory")));
  73. // ERR((__TEXT("Incorrect return value: %d"), rc)); // Note extra brackets
  74. //
  75. #define VERBOSE(mesg) DBGMSG(DBG_LEVEL_VERBOSE, mesg)
  76. #define TERSE(mesg) DBGMSG(DBG_LEVEL_TERSE, mesg)
  77. #define WARNING(mesg) DBGMSG(DBG_LEVEL_WARNING, mesg)
  78. #define ERR(mesg) DBGMSG(DBG_LEVEL_ERROR, mesg)
  79. #define FATAL(mesg) DBGMSG(DBG_LEVEL_FATAL, mesg)
  80. //
  81. // These macros are for Asserting and work independently of the
  82. // debugging variable.
  83. //
  84. #define ASSERT(expr) \
  85. { \
  86. if (! (expr)) { \
  87. DBGPRINTA("ICM: Assertion failed: %s (%d)\n", \
  88. StripDirPrefixA(__FILE__), __LINE__); \
  89. DBGBREAK(); \
  90. } \
  91. }
  92. //
  93. // For giving additional parameters, enclose the message and the other
  94. // parameters in extra paranthesis as shown below.
  95. //
  96. // ASSERTMSG(x>0, "x less than 0");
  97. // ASSERTMSG(x>0, ("x less than 0: x=%d", x));
  98. //
  99. #define ASSERTMSG(expr, mesg) \
  100. { \
  101. if (! (expr)) { \
  102. DBGPRINTA("ICM: Assertion failed: %s (%d)\n", \
  103. StripDirPrefixA(__FILE__), __LINE__); \
  104. DBGPRINT mesg; \
  105. DBGPRINTA("\n"); \
  106. DBGBREAK(); \
  107. } \
  108. }
  109. #define RIP(mesg) \
  110. { \
  111. DBGPRINTA("ICM: "); \
  112. DBGPRINT mesg; \
  113. DBGBREAK(); \
  114. }
  115. #else // !DBG
  116. #define TRACEAPI(mesg)
  117. #define DBGMSG(level, mesg)
  118. #define VERBOSE(mesg)
  119. #define TERSE(mesg)
  120. #define WARNING(mesg)
  121. #define ERR(mesg)
  122. #define FATAL(mesg)
  123. #define ASSERT(expr)
  124. #define ASSERTMSG(expr, mesg)
  125. #define RIP(mesg)
  126. #endif // !DBG
  127. #endif // ifndef _DEBUG_H_