1 /* Support code for standard wait macros in gdb_wait.h.
3 Copyright (C) 2019 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "common-defs.h"
24 /* The underlying idea is that when a Windows program is terminated by
25 a fatal exception, its exit code is the value of that exception, as
26 defined by the various EXCEPTION_* symbols in the Windows API
27 headers. We thus emulate WTERMSIG etc. by translating the fatal
28 exception codes to more-or-less equivalent Posix signals.
30 The translation below is not perfect, because a program could
31 legitimately exit normally with a status whose value happens to
32 have the high bits set, but that's extremely rare, to say the
33 least, and it is deemed such a negligibly small probability of
34 false positives is justified by the utility of reporting the
35 terminating signal in the "normal" cases. */
39 # define WIN32_LEAN_AND_MEAN
40 # include <windows.h> /* for EXCEPTION_* constants */
44 /* The exit status (actually, fatal exception code). */
47 /* The corresponding signal value. */
52 windows_status_to_termsig (unsigned long status
)
54 static const xlate_status status_xlate_tbl
[] =
56 {EXCEPTION_ACCESS_VIOLATION
, SIGSEGV
},
57 {EXCEPTION_IN_PAGE_ERROR
, SIGSEGV
},
58 {EXCEPTION_INVALID_HANDLE
, SIGSEGV
},
59 {EXCEPTION_ILLEGAL_INSTRUCTION
, SIGILL
},
60 {EXCEPTION_NONCONTINUABLE_EXCEPTION
, SIGILL
},
61 {EXCEPTION_ARRAY_BOUNDS_EXCEEDED
, SIGSEGV
},
62 {EXCEPTION_FLT_DENORMAL_OPERAND
, SIGFPE
},
63 {EXCEPTION_FLT_DIVIDE_BY_ZERO
, SIGFPE
},
64 {EXCEPTION_FLT_INEXACT_RESULT
, SIGFPE
},
65 {EXCEPTION_FLT_INVALID_OPERATION
, SIGFPE
},
66 {EXCEPTION_FLT_OVERFLOW
, SIGFPE
},
67 {EXCEPTION_FLT_STACK_CHECK
, SIGFPE
},
68 {EXCEPTION_FLT_UNDERFLOW
, SIGFPE
},
69 {EXCEPTION_INT_DIVIDE_BY_ZERO
, SIGFPE
},
70 {EXCEPTION_INT_OVERFLOW
, SIGFPE
},
71 {EXCEPTION_PRIV_INSTRUCTION
, SIGILL
},
72 {EXCEPTION_STACK_OVERFLOW
, SIGSEGV
},
73 {CONTROL_C_EXIT
, SIGTERM
}
76 for (const xlate_status
&x
: status_xlate_tbl
)
77 if (x
.status
== status
)
83 #endif /* __MINGW32__ */