[vm/win] Redirect warn/error/assert informaion into stderr.

Currently crt warn/error/asserts will disappear, so redirecting them to stderr sounds like a better approach.

TEST=manual win run

Change-Id: Iee0a2effd93fbe104dbeab77abebc54beaecb5dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340583
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2023-12-08 20:20:10 +00:00 committed by Commit Queue
parent 229e8ef687
commit 7850a1cf99

View file

@ -35,12 +35,19 @@ class PlatformWin {
// hitting an assertion failure.
// See: https://msdn.microsoft.com/en-us/library/a9yf33zb.aspx
_set_invalid_parameter_handler(InvalidParameterHandler);
// Disable the message box for assertions, errors and warnings in the CRT
// Ensure no dialog boxes for assertions, errors and warnings in the CRT
// in Debug builds.
// See: https://msdn.microsoft.com/en-us/library/1y71x448.aspx
_CrtSetReportMode(_CRT_ASSERT, 0);
_CrtSetReportMode(_CRT_ERROR, 0);
_CrtSetReportMode(_CRT_WARN, 0);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
// Set location where the C runtime writes an error message for an error
// that might end the program.
_set_error_mode(_OUT_TO_STDERR);
// Disable dialog boxes for "critical" errors or when OpenFile cannot find
// the requested file. However only disable error boxes for general
@ -51,11 +58,12 @@ class PlatformWin {
// Our test runner would set DART_SUPPRESS_WER to suppress WER UI during
// test suite execution.
// See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621(v=vs.85).aspx
UINT uMode = SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
UINT new_mode = SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX;
if (getenv("DART_SUPPRESS_WER") != nullptr) {
uMode |= SEM_NOGPFAULTERRORBOX;
new_mode |= SEM_NOGPFAULTERRORBOX;
}
SetErrorMode(uMode);
UINT existing_mode = SetErrorMode(new_mode);
SetErrorMode(new_mode | existing_mode);
// Set up global exception handler to be able to dump stack trace on crash.
SetExceptionHandler();
}