ada-lang.c: Rename gnat_encoded_fixed_type_info
[binutils-gdb.git] / gdbsupport / gdb_wait.cc
blob32139949c62709ee975d68d372960a3033a9e640
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"
22 #include "gdb_wait.h"
24 #ifdef __MINGW32__
26 /* The underlying idea is that when a Windows program is terminated by
27 a fatal exception, its exit code is the value of that exception, as
28 defined by the various EXCEPTION_* symbols in the Windows API
29 headers. We thus emulate WTERMSIG etc. by translating the fatal
30 exception codes to more-or-less equivalent Posix signals.
32 The translation below is not perfect, because a program could
33 legitimately exit normally with a status whose value happens to
34 have the high bits set, but that's extremely rare, to say the
35 least, and it is deemed such a negligibly small probability of
36 false positives is justified by the utility of reporting the
37 terminating signal in the "normal" cases. */
39 # include <signal.h>
41 # define WIN32_LEAN_AND_MEAN
42 # include <windows.h> /* for EXCEPTION_* constants */
44 struct xlate_status
46 /* The exit status (actually, fatal exception code). */
47 DWORD status;
49 /* The corresponding signal value. */
50 int sig;
53 int
54 windows_status_to_termsig (unsigned long status)
56 static const xlate_status status_xlate_tbl[] =
58 {EXCEPTION_ACCESS_VIOLATION, SIGSEGV},
59 {EXCEPTION_IN_PAGE_ERROR, SIGSEGV},
60 {EXCEPTION_INVALID_HANDLE, SIGSEGV},
61 {EXCEPTION_ILLEGAL_INSTRUCTION, SIGILL},
62 {EXCEPTION_NONCONTINUABLE_EXCEPTION, SIGILL},
63 {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, SIGSEGV},
64 {EXCEPTION_FLT_DENORMAL_OPERAND, SIGFPE},
65 {EXCEPTION_FLT_DIVIDE_BY_ZERO, SIGFPE},
66 {EXCEPTION_FLT_INEXACT_RESULT, SIGFPE},
67 {EXCEPTION_FLT_INVALID_OPERATION, SIGFPE},
68 {EXCEPTION_FLT_OVERFLOW, SIGFPE},
69 {EXCEPTION_FLT_STACK_CHECK, SIGFPE},
70 {EXCEPTION_FLT_UNDERFLOW, SIGFPE},
71 {EXCEPTION_INT_DIVIDE_BY_ZERO, SIGFPE},
72 {EXCEPTION_INT_OVERFLOW, SIGFPE},
73 {EXCEPTION_PRIV_INSTRUCTION, SIGILL},
74 {EXCEPTION_STACK_OVERFLOW, SIGSEGV},
75 {CONTROL_C_EXIT, SIGTERM}
78 for (const xlate_status &x : status_xlate_tbl)
79 if (x.status == status)
80 return x.sig;
82 return -1;
85 #endif /* __MINGW32__ */