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.

233 lines
5.2 KiB

  1. //
  2. // Microsoft Corporation 1998
  3. //
  4. // DEBUG.CPP - Debug library
  5. //
  6. #include "main.h"
  7. #if DBG
  8. //
  9. // Global Variable containing the debugging level.
  10. //
  11. DWORD dwDebugLevel;
  12. //
  13. // Debug strings
  14. //
  15. const TCHAR c_szGPTDemo[] = TEXT("RIGPSNAP(%x): ");
  16. const TCHAR c_szCRLF[] = TEXT("\r\n");
  17. //
  18. // Registry debug information
  19. //
  20. #define DEBUG_REG_LOCATION TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
  21. #define DEBUG_KEY_NAME TEXT("RIGPSNAP")
  22. //*************************************************************
  23. //
  24. // InitDebugSupport()
  25. //
  26. // Purpose: Sets the debugging level.
  27. // Also checks the registry for a debugging level.
  28. //
  29. // Parameters: None
  30. //
  31. // Return: void
  32. //
  33. // Comments:
  34. //
  35. //
  36. // History: Date Author Comment
  37. // 5/25/95 ericflo Created
  38. //
  39. //*************************************************************
  40. void InitDebugSupport(void)
  41. {
  42. LONG lResult;
  43. HKEY hKey;
  44. DWORD dwType, dwSize;
  45. //
  46. // Initialize the debug level to normal
  47. //
  48. dwDebugLevel = DL_NORMAL;
  49. //
  50. // Check the registry
  51. //
  52. lResult = RegOpenKeyEx(
  53. HKEY_LOCAL_MACHINE,
  54. DEBUG_REG_LOCATION,
  55. 0,
  56. KEY_READ,
  57. &hKey);
  58. if (lResult == ERROR_SUCCESS) {
  59. dwSize = sizeof(dwDebugLevel);
  60. RegQueryValueEx(hKey, DEBUG_KEY_NAME, NULL, &dwType,
  61. (LPBYTE)&dwDebugLevel, &dwSize);
  62. RegCloseKey(hKey);
  63. }
  64. }
  65. //*************************************************************
  66. //
  67. // DebugMsg()
  68. //
  69. // Purpose: Displays debug messages based on the debug level
  70. // and type of debug message.
  71. //
  72. // Parameters: mask - debug message type
  73. // pszMsg - debug message
  74. // ... - variable number of parameters
  75. //
  76. // Return: void
  77. //
  78. //
  79. // Comments:
  80. //
  81. //
  82. // History: Date Author Comment
  83. // 5/25/95 ericflo Created
  84. //
  85. //*************************************************************
  86. void _DebugMsg(UINT mask, LPCTSTR pszMsg, ...)
  87. {
  88. BOOL bOutput;
  89. TCHAR szDebugTitle[30];
  90. TCHAR szDebugBuffer[2*MAX_PATH+40];
  91. va_list marker;
  92. DWORD dwErrCode;
  93. //
  94. // Save the last error code (so the debug output doesn't change it).
  95. //
  96. dwErrCode = GetLastError();
  97. //
  98. // Detemerine the correct amount of debug output
  99. //
  100. switch (LOWORD(dwDebugLevel)) {
  101. case DL_VERBOSE:
  102. bOutput = TRUE;
  103. break;
  104. case DL_NORMAL:
  105. //
  106. // Normal debug output. Don't
  107. // display verbose stuff, but
  108. // do display warnings/asserts.
  109. //
  110. if (mask != DM_VERBOSE) {
  111. bOutput = TRUE;
  112. } else {
  113. bOutput = FALSE;
  114. }
  115. break;
  116. case DL_NONE:
  117. default:
  118. //
  119. // Only display asserts
  120. //
  121. if (mask == DM_ASSERT) {
  122. bOutput = TRUE;
  123. } else {
  124. bOutput = FALSE;
  125. }
  126. break;
  127. }
  128. //
  129. // Display the error message if appropriate
  130. //
  131. if (bOutput) {
  132. wsprintf (szDebugTitle, c_szGPTDemo, GetCurrentProcessId());
  133. OutputDebugString(szDebugTitle);
  134. va_start(marker, pszMsg);
  135. wvsprintf(szDebugBuffer, pszMsg, marker);
  136. OutputDebugString(szDebugBuffer);
  137. OutputDebugString(c_szCRLF);
  138. va_end(marker);
  139. if (dwDebugLevel & DL_LOGFILE) {
  140. HANDLE hFile;
  141. DWORD dwBytesWritten;
  142. hFile = CreateFile(TEXT("c:\\rigpsnap.log"),
  143. GENERIC_WRITE,
  144. FILE_SHARE_READ,
  145. NULL,
  146. OPEN_ALWAYS,
  147. FILE_ATTRIBUTE_NORMAL,
  148. NULL);
  149. if (hFile != INVALID_HANDLE_VALUE) {
  150. if (SetFilePointer (hFile, 0, NULL, FILE_END) != 0xFFFFFFFF) {
  151. WriteFile (hFile, (LPCVOID) szDebugTitle,
  152. lstrlen (szDebugTitle) * sizeof(TCHAR),
  153. &dwBytesWritten,
  154. NULL);
  155. WriteFile (hFile, (LPCVOID) szDebugBuffer,
  156. lstrlen (szDebugBuffer) * sizeof(TCHAR),
  157. &dwBytesWritten,
  158. NULL);
  159. WriteFile (hFile, (LPCVOID) c_szCRLF,
  160. lstrlen (c_szCRLF) * sizeof(TCHAR),
  161. &dwBytesWritten,
  162. NULL);
  163. }
  164. CloseHandle (hFile);
  165. }
  166. }
  167. }
  168. //
  169. // Restore the last error code
  170. //
  171. SetLastError(dwErrCode);
  172. //
  173. // Break to the debugger if appropriate
  174. //
  175. if (mask == DM_ASSERT) {
  176. DebugBreak();
  177. }
  178. }
  179. #endif // DBG