|
22 | 22 |
|
23 | 23 | #include <unistd.h>
|
24 | 24 |
|
| 25 | +#if defined(WIN32) |
| 26 | +#include <crtdbg.h> |
| 27 | +#endif |
| 28 | + |
25 | 29 | #if defined(__NetBSD__)
|
26 | 30 | #include <sys/param.h>
|
27 | 31 | #endif
|
@@ -237,8 +241,55 @@ startup_hacks(const char *progname)
|
237 | 241 | exit(1);
|
238 | 242 | }
|
239 | 243 |
|
240 |
| - /* In case of general protection fault, don't show GUI popup box */ |
241 |
| - SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
| 244 | + /* |
| 245 | + * By default abort() only generates a crash-dump in *non* debug |
| 246 | + * builds. As our Assert() / ExceptionalCondition() uses abort(), |
| 247 | + * leaving the default in place would make debugging harder. |
| 248 | + * |
| 249 | + * MINGW's own C runtime doesn't have _set_abort_behavior(). When |
| 250 | + * targetting Microsoft's UCRT with mingw, it never links to the debug |
| 251 | + * version of the library and thus doesn't need the call to |
| 252 | + * _set_abort_behavior() either. |
| 253 | + */ |
| 254 | +#if !defined(__MINGW32__) && !defined(__MINGW64__) |
| 255 | + _set_abort_behavior(_CALL_REPORTFAULT | _WRITE_ABORT_MSG, |
| 256 | + _CALL_REPORTFAULT | _WRITE_ABORT_MSG); |
| 257 | +#endif /* !defined(__MINGW32__) && |
| 258 | + * !defined(__MINGW64__) */ |
| 259 | + |
| 260 | + /* |
| 261 | + * SEM_FAILCRITICALERRORS causes more errors to be reported to |
| 262 | + * callers. |
| 263 | + * |
| 264 | + * We used to also specify SEM_NOGPFAULTERRORBOX, but that prevents |
| 265 | + * windows crash reporting from working. Which includes registered |
| 266 | + * just-in-time debuggers, making it unnecessarily hard to debug |
| 267 | + * problems on windows. Now we try to disable sources of popups |
| 268 | + * separately below (note that SEM_NOGPFAULTERRORBOX did not actually |
| 269 | + * prevent all sources of such popups). |
| 270 | + */ |
| 271 | + SetErrorMode(SEM_FAILCRITICALERRORS); |
| 272 | + |
| 273 | + /* |
| 274 | + * Show errors on stderr instead of popup box (note this doesn't |
| 275 | + * affect errors originating in the C runtime, see below). |
| 276 | + */ |
| 277 | + _set_error_mode(_OUT_TO_STDERR); |
| 278 | + |
| 279 | + /* |
| 280 | + * In DEBUG builds, errors, including assertions, C runtime errors are |
| 281 | + * reported via _CrtDbgReport. By default such errors are displayed |
| 282 | + * with a popup (even with NOGPFAULTERRORBOX), preventing forward |
| 283 | + * progress. Instead report such errors stderr (and the debugger). |
| 284 | + * This is C runtime specific and thus the above incantations aren't |
| 285 | + * sufficient to suppress these popups. |
| 286 | + */ |
| 287 | + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 288 | + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 289 | + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 290 | + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 291 | + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 292 | + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
242 | 293 |
|
243 | 294 | #if defined(_M_AMD64) && _MSC_VER == 1800
|
244 | 295 |
|
|
0 commit comments