Source code of Windows XP (NT5)
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.

270 lines
4.4 KiB

  1. // File: DebSpew.cpp
  2. #include "precomp.h"
  3. #include <confreg.h>
  4. #include <RegEntry.h>
  5. #ifdef DEBUG /* THE WHOLE FILE! */
  6. #if defined (_M_IX86)
  7. #define _DbgBreak() __asm { int 3 }
  8. #else
  9. #define _DbgBreak() DebugBreak()
  10. #endif
  11. /* Types
  12. ********/
  13. PCSTR g_pcszSpewModule = NULL;
  14. /* debug flags */
  15. typedef enum _debugdebugflags
  16. {
  17. DEBUG_DFL_ENABLE_TRACE_MESSAGES = 0x0001,
  18. DEBUG_DFL_LOG_TRACE_MESSAGES = 0x0002,
  19. DEBUG_DFL_ENABLE_CALL_TRACING = 0x0008,
  20. ALL_DEBUG_DFLAGS = (DEBUG_DFL_ENABLE_TRACE_MESSAGES |
  21. DEBUG_DFL_LOG_TRACE_MESSAGES |
  22. DEBUG_DFL_ENABLE_CALL_TRACING)
  23. }
  24. DEBUGDEBUGFLAGS;
  25. /* Global Variables
  26. *******************/
  27. #pragma data_seg(DATA_SEG_PER_INSTANCE)
  28. /* parameters used by SpewOut() */
  29. DWORD g_dwSpewFlags = 0;
  30. UINT g_uSpewSev = 0;
  31. UINT g_uSpewLine = 0;
  32. PCSTR g_pcszSpewFile = NULL;
  33. HDBGZONE ghDbgZone = NULL;
  34. /* debug flags */
  35. DWORD s_dwDebugModuleFlags = 0;
  36. #pragma data_seg()
  37. /***************************** Private Functions *****************************/
  38. /* Module Prototypes
  39. ********************/
  40. BOOL IsValidSpewSev(UINT);
  41. /*
  42. ** IsValidSpewSev()
  43. **
  44. **
  45. **
  46. ** Arguments:
  47. **
  48. ** Returns:
  49. **
  50. ** Side Effects: none
  51. */
  52. BOOL IsValidSpewSev(UINT uSpewSev)
  53. {
  54. BOOL bResult;
  55. switch (uSpewSev)
  56. {
  57. case SPEW_TRACE:
  58. case SPEW_CALLTRACE:
  59. case SPEW_WARNING:
  60. case SPEW_ERROR:
  61. case SPEW_FATAL:
  62. bResult = TRUE;
  63. break;
  64. default:
  65. ERROR_OUT(("IsValidSpewSev(): Invalid debug spew severity %u.",
  66. uSpewSev));
  67. bResult = FALSE;
  68. break;
  69. }
  70. return(bResult);
  71. }
  72. /****************************** Public Functions *****************************/
  73. DWORD GetDebugOutputFlags(VOID)
  74. {
  75. return s_dwDebugModuleFlags;
  76. }
  77. VOID SetDebugOutputFlags(DWORD dw)
  78. {
  79. ASSERT(FLAGS_ARE_VALID(dw, ALL_DEBUG_DFLAGS));
  80. s_dwDebugModuleFlags = dw;
  81. }
  82. /*
  83. ** InitDebugModule()
  84. **
  85. **
  86. **
  87. ** Arguments:
  88. **
  89. ** Returns:
  90. **
  91. ** Side Effects: none
  92. */
  93. BOOL InitDebugModule(PCSTR pcszSpewModule)
  94. {
  95. s_dwDebugModuleFlags = 0;
  96. g_pcszSpewModule = pcszSpewModule;
  97. if (NULL == ghDbgZone)
  98. {
  99. PSTR rgsz[4];
  100. rgsz[0] = (PSTR) pcszSpewModule;
  101. ASSERT(0 == ZONE_WARNING);
  102. rgsz[1+ZONE_WARNING] = "Warning";
  103. ASSERT(1 == ZONE_TRACE);
  104. rgsz[1+ZONE_TRACE] = "Trace";
  105. ASSERT(2 == ZONE_FUNCTION);
  106. rgsz[1+ZONE_FUNCTION] = "Function";
  107. // Initialize standard debug settings with warning enabled by default
  108. DbgInitEx(&ghDbgZone, rgsz, 3, 0x01);
  109. }
  110. return TRUE;
  111. }
  112. /*
  113. ** ExitDebugModule()
  114. **
  115. **
  116. **
  117. ** Arguments:
  118. **
  119. ** Returns:
  120. **
  121. ** Side Effects: none
  122. */
  123. void ExitDebugModule(void)
  124. {
  125. g_pcszSpewModule = NULL;
  126. DBGDEINIT(&ghDbgZone);
  127. }
  128. /* _ D B G Z P R I N T M S G */
  129. /*-------------------------------------------------------------------------
  130. %%Function: _DbgZPrintMsg
  131. -------------------------------------------------------------------------*/
  132. static VOID _DbgZPrintMsg(UINT iZone, PSTR pszFormat, va_list arglist)
  133. {
  134. PCSTR pcszSpewPrefix;
  135. char szModule[128];
  136. if (g_pcszSpewModule)
  137. {
  138. switch (iZone)
  139. {
  140. case ZONE_TRACE:
  141. pcszSpewPrefix = "Trace";
  142. break;
  143. case ZONE_FUNCTION:
  144. pcszSpewPrefix = "Func ";
  145. break;
  146. case ZONE_WARNING:
  147. pcszSpewPrefix = "Warn ";
  148. break;
  149. default:
  150. pcszSpewPrefix = "?????";
  151. break;
  152. }
  153. wsprintfA(szModule, "%s:%s", g_pcszSpewModule, pcszSpewPrefix);
  154. }
  155. else
  156. {
  157. // No module nonsense, empty prefix
  158. wsprintfA(szModule, "%s", "");
  159. }
  160. DbgPrintf(szModule, pszFormat, arglist);
  161. }
  162. VOID WINAPI DbgZPrintError(PSTR pszFormat,...)
  163. {
  164. va_list v1;
  165. va_start(v1, pszFormat);
  166. _DbgZPrintMsg(ZONE_WARNING, pszFormat, v1);
  167. va_end(v1);
  168. _DbgBreak();
  169. }
  170. VOID WINAPI DbgZPrintWarning(PSTR pszFormat,...)
  171. {
  172. if (GETZONEMASK(ghDbgZone) & ZONE_WARNING_FLAG)
  173. {
  174. va_list v1;
  175. va_start(v1, pszFormat);
  176. _DbgZPrintMsg(ZONE_WARNING, pszFormat, v1);
  177. va_end(v1);
  178. }
  179. }
  180. VOID WINAPI DbgZPrintTrace(PSTR pszFormat,...)
  181. {
  182. if (GETZONEMASK(ghDbgZone) & ZONE_TRACE_FLAG)
  183. {
  184. va_list v1;
  185. va_start(v1, pszFormat);
  186. _DbgZPrintMsg(ZONE_TRACE, pszFormat, v1);
  187. va_end(v1);
  188. }
  189. }
  190. VOID WINAPI DbgZPrintFunction(PSTR pszFormat,...)
  191. {
  192. if (GETZONEMASK(ghDbgZone) & ZONE_FUNCTION_FLAG)
  193. {
  194. va_list v1;
  195. va_start(v1, pszFormat);
  196. _DbgZPrintMsg(ZONE_FUNCTION, pszFormat, v1);
  197. va_end(v1);
  198. }
  199. }
  200. #endif /* DEBUG */
  201.