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.

170 lines
4.0 KiB

  1. // This file provides dbgout implementations for use when the property
  2. // set code is built into a standalone dll (so that we don't require a
  3. // checked OLE32).
  4. #include <pch.cxx>
  5. #if DBG == 1
  6. unsigned long Win4InfoLevel = DEF_INFOLEVEL;
  7. unsigned long Win4InfoMask = 0xffffffff;
  8. unsigned long Win4AssertLevel = ASSRT_MESSAGE | ASSRT_BREAK | ASSRT_POPUP;
  9. static CRITICAL_SECTION s_csMessageBuf;
  10. static char g_szMessageBuf[500]; // this is the message buffer
  11. #include <dprintf.h> // w4printf, w4dprintf prototypes
  12. static int _cdecl w4dprintf(const char *format, ...)
  13. {
  14. int ret;
  15. va_list va;
  16. va_start(va, format);
  17. ret = w4vdprintf(format, va);
  18. va_end(va);
  19. return ret;
  20. }
  21. static int _cdecl w4vdprintf(const char *format, va_list arglist)
  22. {
  23. int ret;
  24. EnterCriticalSection(&s_csMessageBuf);
  25. ret = vsprintf(g_szMessageBuf, format, arglist);
  26. OutputDebugStringA(g_szMessageBuf);
  27. LeaveCriticalSection(&s_csMessageBuf);
  28. return ret;
  29. }
  30. void APINOT vdprintf(unsigned long ulCompMask,
  31. char const *pszComp,
  32. char const *ppszfmt,
  33. va_list pargs)
  34. {
  35. if ((ulCompMask & DEB_FORCE) == DEB_FORCE ||
  36. ((ulCompMask | Win4InfoLevel) & Win4InfoMask))
  37. {
  38. {
  39. if (! (ulCompMask & DEB_NOCOMPNAME))
  40. {
  41. w4dprintf("%s: ", pszComp);
  42. }
  43. w4vdprintf(ppszfmt, pargs);
  44. // Chicago and Win32s debugging is usually through wdeb386
  45. // which needs carriage returns
  46. #if WIN32 == 50 || WIN32 == 200
  47. w4dprintf("\r");
  48. #endif
  49. }
  50. }
  51. }
  52. // Private version of RtlAssert so debug versions really assert on free builds.
  53. VOID PropAssertFailed(
  54. IN PVOID FailedAssertion,
  55. IN PVOID FileName,
  56. IN ULONG LineNumber,
  57. IN PCHAR Message OPTIONAL
  58. )
  59. {
  60. CHAR szMessage[ 512 ];
  61. int nResponse;
  62. sprintf( szMessage, "File:\t%s\nLine:\t%d\nMessage:\t%s\n"
  63. "\nPress Abort to kill the process, Retry to debug",
  64. FileName, LineNumber, NULL == Message ? "" : Message );
  65. nResponse = MessageBoxA( NULL, szMessage, "Assertion failed in NT5Props.dll", MB_ABORTRETRYIGNORE );
  66. if( IDRETRY == nResponse )
  67. DebugBreak();
  68. else if( IDABORT == nResponse )
  69. NtTerminateProcess( NtCurrentProcess(), STATUS_UNSUCCESSFUL );
  70. return;
  71. /*
  72. char Response[ 2 ] = { "B" }; // In MSDEV there is no input, so default to break
  73. for ( ; ; ) {
  74. DbgPrint( "\n*** Assertion failed: %s%s\n*** Source File: %s, line %ld\n\n",
  75. Message ? Message : "",
  76. FailedAssertion,
  77. FileName,
  78. LineNumber
  79. );
  80. DbgPrompt( "Break, Ignore, terminate Process, Sleep 30 seconds, or terminate Thread (bipst)? ",
  81. Response, sizeof( Response));
  82. switch ( toupper(Response[0])) {
  83. case 'B':
  84. DbgBreakPoint();
  85. break;
  86. case 'I':
  87. return;
  88. break;
  89. case 'P':
  90. NtTerminateProcess( NtCurrentProcess(), STATUS_UNSUCCESSFUL );
  91. break;
  92. case 'S':
  93. Sleep( 30000L);
  94. break;
  95. case 'T':
  96. NtTerminateThread( NtCurrentThread(), STATUS_UNSUCCESSFUL );
  97. break;
  98. default:
  99. DbgBreakPoint();
  100. break;
  101. }
  102. }
  103. DbgBreakPoint();
  104. NtTerminateProcess( NtCurrentProcess(), STATUS_UNSUCCESSFUL );
  105. */
  106. }
  107. void
  108. InitializeDebugging()
  109. {
  110. CHAR szValue[ 30 ];
  111. InitializeCriticalSection( &s_csMessageBuf );
  112. if (GetProfileStringA("CairOLE InfoLevels", // section
  113. "prop", // key
  114. "3", // default value
  115. szValue, // return buffer
  116. sizeof(szValue)))
  117. {
  118. propInfoLevel = DEB_ERROR | DEB_WARN | strtoul (szValue, NULL, 16);
  119. }
  120. }
  121. void
  122. UnInitializeDebugging()
  123. {
  124. DeleteCriticalSection( &s_csMessageBuf );
  125. }
  126. #endif // #if DBG == 1