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.

204 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. blbdbg.cpp
  5. Abstract:
  6. This module contains the debugging support for the userdir dll.
  7. Author:
  8. Mu Han (muhan) 1-May-1997
  9. Changes:
  10. copied muhan's file from userdir and changed the key used to find out the debug level
  11. B.Rajeev (rajeevb) 10-Oct-1997
  12. --*/
  13. #include "stdafx.h"
  14. #include "blbdbg.h"
  15. #ifdef SDPDBG
  16. #define MAXDEBUGSTRINGLENGTH 512
  17. static DWORD sg_dwTraceID = INVALID_TRACEID;
  18. static char sg_szTraceName[100]; // saves name of dll
  19. static DWORD sg_dwTracingToDebugger = 0;
  20. static DWORD sg_dwTracingToConsole = 0;
  21. static DWORD sg_dwTracingToFile = 0;
  22. static DWORD sg_dwDebuggerMask = 0;
  23. BOOL SDPLogRegister(LPCTSTR szName)
  24. {
  25. HKEY hTracingKey;
  26. char szTracingKey[100];
  27. const char szDebuggerTracingEnableValue[] = "EnableDebuggerTracing";
  28. const char szConsoleTracingEnableValue[] = "EnableConsoleTracing";
  29. const char szFileTracingEnableValue[] = "EnableFileTracing";
  30. const char szTracingMaskValue[] = "ConsoleTracingMask";
  31. sg_dwTracingToDebugger = 0;
  32. sg_dwTracingToConsole = 0;
  33. sg_dwTracingToFile = 0;
  34. #ifdef UNICODE
  35. wsprintfA(szTracingKey, "Software\\Microsoft\\Tracing\\%ls", szName);
  36. #else
  37. wsprintfA(szTracingKey, "Software\\Microsoft\\Tracing\\%s", szName);
  38. #endif
  39. if ( ERROR_SUCCESS == RegOpenKeyExA(HKEY_LOCAL_MACHINE,
  40. szTracingKey,
  41. 0,
  42. KEY_READ,
  43. &hTracingKey) )
  44. {
  45. DWORD dwDataSize = sizeof (DWORD);
  46. DWORD dwDataType;
  47. RegQueryValueExA(hTracingKey,
  48. szDebuggerTracingEnableValue,
  49. 0,
  50. &dwDataType,
  51. (LPBYTE) &sg_dwTracingToDebugger,
  52. &dwDataSize);
  53. RegQueryValueExA(hTracingKey,
  54. szConsoleTracingEnableValue,
  55. 0,
  56. &dwDataType,
  57. (LPBYTE) &sg_dwTracingToConsole,
  58. &dwDataSize);
  59. RegQueryValueExA(hTracingKey,
  60. szFileTracingEnableValue,
  61. 0,
  62. &dwDataType,
  63. (LPBYTE) &sg_dwTracingToFile,
  64. &dwDataSize);
  65. RegQueryValueExA(hTracingKey,
  66. szTracingMaskValue,
  67. 0,
  68. &dwDataType,
  69. (LPBYTE) &sg_dwDebuggerMask,
  70. &dwDataSize);
  71. RegCloseKey (hTracingKey);
  72. }
  73. #ifdef UNICODE
  74. wsprintfA(sg_szTraceName, "%ls", szName);
  75. #else
  76. wsprintfA(sg_szTraceName, "%s", szName);
  77. #endif
  78. sg_dwTraceID = TraceRegister(szName);
  79. return (sg_dwTraceID != INVALID_TRACEID);
  80. }
  81. void SDPLogDeRegister()
  82. {
  83. sg_dwTracingToDebugger = 0;
  84. sg_dwTracingToConsole = 0;
  85. sg_dwTracingToFile = 0;
  86. if (sg_dwTraceID != INVALID_TRACEID)
  87. {
  88. TraceDeregister(sg_dwTraceID);
  89. sg_dwTraceID = INVALID_TRACEID;
  90. }
  91. }
  92. void DbgPrt(IN int dwDbgLevel, IN LPCTSTR lpszFormat, IN ...)
  93. /*++
  94. Routine Description:
  95. Formats the incoming debug message & calls DbgPrint
  96. Arguments:
  97. DbgLevel - level of message verboseness
  98. DbgMessage - printf-style format string, followed by appropriate
  99. list of arguments
  100. Return Value:
  101. --*/
  102. {
  103. TCHAR buf[MAXDEBUGSTRINGLENGTH + 1];
  104. TCHAR *message[5] =
  105. {
  106. _T("FAIL: "),
  107. _T("WARN: "),
  108. _T("INFO: "),
  109. _T("TRCE: "),
  110. _T("ELSE: ")
  111. };
  112. if ((sg_dwTracingToDebugger > 0) &&
  113. (((DWORD)dwDbgLevel) <= sg_dwDebuggerMask))
  114. {
  115. SYSTEMTIME SystemTime;
  116. // retrieve local time
  117. GetLocalTime(&SystemTime);
  118. va_list ap;
  119. if (dwDbgLevel > ELSE)
  120. {
  121. dwDbgLevel = ELSE;
  122. }
  123. wsprintf(buf, _T("SDPBLB:[%02u:%02u:%02u.%03u,tid=%x:]%s"),
  124. SystemTime.wHour,
  125. SystemTime.wMinute,
  126. SystemTime.wSecond,
  127. SystemTime.wMilliseconds,
  128. GetCurrentThreadId(),
  129. message[dwDbgLevel - 1]
  130. );
  131. va_start(ap, lpszFormat);
  132. _vsntprintf(&buf[lstrlen(buf)],
  133. MAXDEBUGSTRINGLENGTH - lstrlen(buf),
  134. lpszFormat,
  135. ap
  136. );
  137. lstrcat(buf, _T("\n"));
  138. OutputDebugString(buf);
  139. }
  140. if (sg_dwTraceID != INVALID_TRACEID)
  141. {
  142. if ( ( sg_dwTracingToConsole > 0 ) || ( sg_dwTracingToFile > 0 ) )
  143. {
  144. if (dwDbgLevel > ELSE)
  145. {
  146. dwDbgLevel = ELSE;
  147. }
  148. wsprintf(buf, _T("[%s] %s"), message[dwDbgLevel-1], lpszFormat);
  149. va_list arglist;
  150. va_start(arglist, lpszFormat);
  151. TraceVprintfEx(sg_dwTraceID, dwDbgLevel, buf, arglist);
  152. va_end(arglist);
  153. }
  154. }
  155. }
  156. #endif // DBG