[libcxx-commits] [PATCH] D155823: [libcxx] [test] Make set_windows_crt_report_mode.h more explicit

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 20 05:35:07 PDT 2023


mstorsjo created this revision.
mstorsjo added reviewers: andrewng, Mordante, jyknight.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

This header is included when building with a debug CRT in
MSVC/Clang-cl environments. By default, failed asserts with the
debug CRT pops up a blocking dialog box alerting the user about
the failed assert. When running more than one test in an automated
fashion, this isn't ideal.

This header tries to run initializers to set the behaviour of the
failed asserts to print a message to the console, just like the
default is in release mode.

This is previously done by setting the reporting mode to
_CRTDBG_MODE_DEBUG, which means outputting to the debugger's
output window. In some setups, this is enough for making it work,
but in others it instead can pop up a dialog asking for which
debugger to use.

Instead set the mode explicitly to _CRTDBG_MODE_FILE and set the
destination to be explicitly to stderr.

For setups where the previous code worked correctly, it doesn't make
any difference other than that a failed assert prints an additional
"abort() has been called" message that wasn't printed before.

Patch originally by Andrew Ng.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155823

Files:
  libcxx/test/support/set_windows_crt_report_mode.h


Index: libcxx/test/support/set_windows_crt_report_mode.h
===================================================================
--- libcxx/test/support/set_windows_crt_report_mode.h
+++ libcxx/test/support/set_windows_crt_report_mode.h
@@ -33,9 +33,12 @@
 // that setting and instead changes the assertion handler to log to stderr
 // instead.
 inline int init_crt_report_mode() {
-  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
-  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
-  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
+  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
+  _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
+  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
+  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
   return 0;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155823.542453.patch
Type: text/x-patch
Size: 882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230720/f62e3645/attachment-0001.bin>


More information about the libcxx-commits mailing list