]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/sim-signal.c
sim: reorder header includes
[thirdparty/binutils-gdb.git] / sim / common / sim-signal.c
CommitLineData
c906108c 1/* Simulator signal support
3666a048 2 Copyright (C) 1997-2021 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Support
4
5This file is part of the GNU Simulators.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4744ac1b
JB
9the Free Software Foundation; either version 3 of the License, or
10(at your option) any later version.
c906108c
SS
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
4744ac1b
JB
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 19
6df01ab8
MF
20/* This must come before any other includes. */
21#include "defs.h"
22
c906108c 23#include <signal.h>
20a8e078 24
c906108c 25#include "sim-main.h"
1fef66b0 26#include "sim-signal.h"
c906108c
SS
27
28/* Convert SIM_SIGFOO to SIGFOO.
29 What to do when the host doesn't have SIGFOO is handled on a case by case
30 basis. Generally, in the case of passing a value back to gdb, we want gdb
31 to not think the process has died (so it can be debugged at the point of
32 failure). */
33
a4e64307 34#ifdef _WIN32
c906108c
SS
35#ifndef SIGTRAP
36#define SIGTRAP 5
37#endif
38#ifndef SIGBUS
39#define SIGBUS 10
40#endif
41#ifndef SIGQUIT
42#define SIGQUIT 3
43#endif
44#endif
45
46int
47sim_signal_to_host (SIM_DESC sd, SIM_SIGNAL sig)
48{
49 switch (sig)
50 {
51 case SIM_SIGINT :
52 return SIGINT;
53
54 case SIM_SIGABRT :
55 return SIGABRT;
56
57 case SIM_SIGILL :
58#ifdef SIGILL
59 return SIGILL;
60#else
61 return SIGSEGV;
62#endif
63
64 case SIM_SIGTRAP :
65 return SIGTRAP;
66
67 case SIM_SIGBUS :
68#ifdef SIGBUS
69 return SIGBUS;
70#else
71 return SIGSEGV;
72#endif
73
74 case SIM_SIGSEGV :
75 return SIGSEGV;
76
77 case SIM_SIGXCPU :
78#ifdef SIGXCPU
79 return SIGXCPU;
80#endif
81 break;
82
83 case SIM_SIGFPE:
aba6488e 84#ifdef SIGFPE
c906108c
SS
85 return SIGFPE;
86#endif
87 break;
88
89 case SIM_SIGNONE:
90 return 0;
91 break;
92 }
93
94 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
95#ifdef SIGHUP
96 return SIGHUP; /* FIXME: Suggestions? */
97#else
98 return 1;
99#endif
100}
aba6488e 101
2ea28649 102enum gdb_signal
2c1fa544 103sim_signal_to_gdb_signal (SIM_DESC sd, SIM_SIGNAL sig)
aba6488e
MM
104{
105 switch (sig)
106 {
107 case SIM_SIGINT :
a493e3e2 108 return GDB_SIGNAL_INT;
aba6488e
MM
109
110 case SIM_SIGABRT :
a493e3e2 111 return GDB_SIGNAL_ABRT;
aba6488e
MM
112
113 case SIM_SIGILL :
a493e3e2 114 return GDB_SIGNAL_ILL;
aba6488e
MM
115
116 case SIM_SIGTRAP :
a493e3e2 117 return GDB_SIGNAL_TRAP;
aba6488e
MM
118
119 case SIM_SIGBUS :
a493e3e2 120 return GDB_SIGNAL_BUS;
aba6488e 121
25520859 122 case SIM_SIGSEGV :
a493e3e2 123 return GDB_SIGNAL_SEGV;
aba6488e
MM
124
125 case SIM_SIGXCPU :
a493e3e2 126 return GDB_SIGNAL_XCPU;
aba6488e
MM
127
128 case SIM_SIGFPE:
a493e3e2 129 return GDB_SIGNAL_FPE;
aba6488e
MM
130 break;
131
132 case SIM_SIGNONE:
a493e3e2 133 return GDB_SIGNAL_0;
aba6488e
MM
134 break;
135 }
136
137 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
a493e3e2 138 return GDB_SIGNAL_HUP;
aba6488e 139}