|
18 | 18 |
|
19 | 19 | #include <windows.h>
|
20 | 20 |
|
| 21 | +#include <crtdbg.h> |
| 22 | +#include <stdio.h> |
| 23 | + |
| 24 | +void |
| 25 | +jerry_port_init (void) |
| 26 | +{ |
| 27 | + if (!IsDebuggerPresent ()) |
| 28 | + { |
| 29 | + /* Make output streams unbuffered by default */ |
| 30 | + setvbuf (stdout, NULL, _IONBF, 0); |
| 31 | + setvbuf (stderr, NULL, _IONBF, 0); |
| 32 | + |
| 33 | + /* |
| 34 | + * By default abort() only generates a crash-dump in *non* debug |
| 35 | + * builds. As our Assert() / ExceptionalCondition() uses abort(), |
| 36 | + * leaving the default in place would make debugging harder. |
| 37 | + * |
| 38 | + * MINGW's own C runtime doesn't have _set_abort_behavior(). When |
| 39 | + * targeting Microsoft's UCRT with mingw, it never links to the debug |
| 40 | + * version of the library and thus doesn't need the call to |
| 41 | + * _set_abort_behavior() either. |
| 42 | + */ |
| 43 | +#if !defined(__MINGW32__) && !defined(__MINGW64__) |
| 44 | + _set_abort_behavior (_CALL_REPORTFAULT | _WRITE_ABORT_MSG, _CALL_REPORTFAULT | _WRITE_ABORT_MSG); |
| 45 | +#endif /* !defined(__MINGW32__) && !defined(__MINGW64__) */ |
| 46 | + |
| 47 | + /* |
| 48 | + * SEM_FAILCRITICALERRORS causes more errors to be reported to |
| 49 | + * callers. |
| 50 | + * |
| 51 | + * We used to also specify SEM_NOGPFAULTERRORBOX, but that prevents |
| 52 | + * windows crash reporting from working. Which includes registered |
| 53 | + * just-in-time debuggers, making it unnecessarily hard to debug |
| 54 | + * problems on windows. Now we try to disable sources of popups |
| 55 | + * separately below (note that SEM_NOGPFAULTERRORBOX did not actually |
| 56 | + * prevent all sources of such popups). |
| 57 | + */ |
| 58 | + SetErrorMode (SEM_FAILCRITICALERRORS); |
| 59 | + |
| 60 | + /* |
| 61 | + * Show errors on stderr instead of popup box (note this doesn't |
| 62 | + * affect errors originating in the C runtime, see below). |
| 63 | + */ |
| 64 | + _set_error_mode (_OUT_TO_STDERR); |
| 65 | + |
| 66 | + /* |
| 67 | + * In DEBUG builds, errors, including assertions, C runtime errors are |
| 68 | + * reported via _CrtDbgReport. By default such errors are displayed |
| 69 | + * with a popup (even with NOGPFAULTERRORBOX), preventing forward |
| 70 | + * progress. Instead report such errors stderr (and the debugger). |
| 71 | + * This is C runtime specific and thus the above incantations aren't |
| 72 | + * sufficient to suppress these popups. |
| 73 | + */ |
| 74 | + _CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 75 | + _CrtSetReportFile (_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 76 | + _CrtSetReportMode (_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 77 | + _CrtSetReportFile (_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 78 | + _CrtSetReportMode (_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 79 | + _CrtSetReportFile (_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 80 | + } |
| 81 | +} /* jerry_port_init */ |
| 82 | + |
21 | 83 | /**
|
22 | 84 | * Default implementation of jerry_port_sleep, uses 'Sleep'.
|
23 | 85 | */
|
|
0 commit comments