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.

199 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This file implements the debug code for the
  7. fax project. All components that require
  8. debug prints, asserts, etc.
  9. Author:
  10. Wesley Witt (wesw) 22-Dec-1995
  11. Minor modifications by Brian Dewey (t-briand) 4-Aug-1997
  12. -- to work with the FAX migration DLL.
  13. Environment:
  14. User Mode
  15. --*/
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <tchar.h>
  20. #include <setupapi.h>
  21. BOOL ConsoleDebugOutput = FALSE;
  22. VOID
  23. ConsoleDebugPrint(
  24. LPTSTR buf
  25. )
  26. {
  27. }
  28. void
  29. dprintf(
  30. LPTSTR Format,
  31. ...
  32. )
  33. /*++
  34. Routine Description:
  35. Prints a debug string
  36. Arguments:
  37. format - printf() format string
  38. ... - Variable data
  39. Return Value:
  40. None.
  41. --*/
  42. {
  43. TCHAR buf[1024];
  44. DWORD len;
  45. static TCHAR AppName[16];
  46. va_list arg_ptr;
  47. SYSTEMTIME CurrentTime;
  48. if (AppName[0] == 0) {
  49. if (GetModuleFileName( NULL, buf, sizeof(buf) )) {
  50. _tsplitpath( buf, NULL, NULL, AppName, NULL );
  51. }
  52. }
  53. va_start(arg_ptr, Format);
  54. GetLocalTime( &CurrentTime );
  55. _stprintf( buf, TEXT("%x %02d:%02d:%02d.%03d %s: "),
  56. GetCurrentThreadId(),
  57. CurrentTime.wHour,
  58. CurrentTime.wMinute,
  59. CurrentTime.wSecond,
  60. CurrentTime.wMilliseconds,
  61. AppName[0] ? AppName : TEXT("")
  62. );
  63. len = _tcslen( buf );
  64. _vsntprintf(&buf[len], sizeof(buf)-len, Format, arg_ptr);
  65. len = _tcslen( buf );
  66. if (buf[len-1] != TEXT('\n')) {
  67. buf[len] = TEXT('\r');
  68. buf[len+1] = TEXT('\n');
  69. buf[len+2] = 0;
  70. }
  71. OutputDebugString( buf );
  72. #ifndef TEST_WIN95
  73. SetupLogError(buf, LogSevInformation);
  74. #else
  75. // When testing win95, we write to the console instead of the
  76. // setup log.
  77. _ftprintf(stderr, buf);
  78. #endif
  79. _stprintf( buf, TEXT("%02d:%02d:%02d.%03d "),
  80. CurrentTime.wHour,
  81. CurrentTime.wMinute,
  82. CurrentTime.wSecond,
  83. CurrentTime.wMilliseconds
  84. );
  85. len = _tcslen( buf );
  86. _vsntprintf(&buf[len], sizeof(buf)-len, Format, arg_ptr);
  87. ConsoleDebugPrint( buf );
  88. }
  89. VOID
  90. AssertError(
  91. LPTSTR Expression,
  92. LPTSTR File,
  93. ULONG LineNumber
  94. )
  95. /*++
  96. Routine Description:
  97. Thie function is use together with the Assert MACRO.
  98. It checks to see if an expression is FALSE. if the
  99. expression is FALSE, then you end up here.
  100. Arguments:
  101. Expression - The text of the 'C' expression
  102. File - The file that caused the assertion
  103. LineNumber - The line number in the file.
  104. Return Value:
  105. None.
  106. --*/
  107. {
  108. dprintf(
  109. TEXT("Assertion error: [%s] %s @ %d\n"),
  110. Expression,
  111. File,
  112. LineNumber
  113. );
  114. __try {
  115. DebugBreak();
  116. } __except (UnhandledExceptionFilter(GetExceptionInformation())) {
  117. // Nothing to do in here.
  118. }
  119. }
  120. // DebugSystemError
  121. //
  122. // Displays a system error message on the debug console.
  123. //
  124. // Parameters:
  125. // dwSysErrorCode The system error code returned by GetLastError().
  126. //
  127. // Returns:
  128. // Nothing.
  129. //
  130. // Side effects:
  131. // Does a dprintf() of the message associated with an error code.
  132. //
  133. // Author:
  134. // Brian Dewey (t-briand) 1997-7-25
  135. void
  136. DebugSystemError(DWORD dwSysErrorCode)
  137. {
  138. TCHAR szErrorMsg[MAX_PATH]; // Holds our message.
  139. FormatMessage(
  140. FORMAT_MESSAGE_FROM_SYSTEM, // We're given a system error code.
  141. NULL, // No string.
  142. dwSysErrorCode, // The error code.
  143. 0, // Default language.
  144. szErrorMsg, // The error message.
  145. sizeof(szErrorMsg), // Size of our buffer.
  146. NULL // No arguments.
  147. );
  148. dprintf(szErrorMsg);
  149. }