]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-signal.c
f9fef4c24c64bf61a0ac901cf970ff6ae26bf4e9
[thirdparty/binutils-gdb.git] / sim / common / sim-signal.c
1 /* Simulator signal support
2 Copyright (C) 1997-2021 Free Software Foundation, Inc.
3 Contributed by Cygnus Support
4
5 This file is part of the GNU Simulators.
6
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.
11
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.
16
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/>. */
19
20 /* This must come before any other includes. */
21 #include "defs.h"
22
23 #include <signal.h>
24 #include "sim-main.h"
25
26 /* Convert SIM_SIGFOO to SIGFOO.
27 What to do when the host doesn't have SIGFOO is handled on a case by case
28 basis. Generally, in the case of passing a value back to gdb, we want gdb
29 to not think the process has died (so it can be debugged at the point of
30 failure). */
31
32 #ifdef _WIN32
33 #ifndef SIGTRAP
34 #define SIGTRAP 5
35 #endif
36 #ifndef SIGBUS
37 #define SIGBUS 10
38 #endif
39 #ifndef SIGQUIT
40 #define SIGQUIT 3
41 #endif
42 #endif
43
44 int
45 sim_signal_to_host (SIM_DESC sd, SIM_SIGNAL sig)
46 {
47 switch (sig)
48 {
49 case SIM_SIGINT :
50 return SIGINT;
51
52 case SIM_SIGABRT :
53 return SIGABRT;
54
55 case SIM_SIGILL :
56 #ifdef SIGILL
57 return SIGILL;
58 #else
59 return SIGSEGV;
60 #endif
61
62 case SIM_SIGTRAP :
63 return SIGTRAP;
64
65 case SIM_SIGBUS :
66 #ifdef SIGBUS
67 return SIGBUS;
68 #else
69 return SIGSEGV;
70 #endif
71
72 case SIM_SIGSEGV :
73 return SIGSEGV;
74
75 case SIM_SIGXCPU :
76 #ifdef SIGXCPU
77 return SIGXCPU;
78 #endif
79 break;
80
81 case SIM_SIGFPE:
82 #ifdef SIGFPE
83 return SIGFPE;
84 #endif
85 break;
86
87 case SIM_SIGNONE:
88 return 0;
89 break;
90 }
91
92 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
93 #ifdef SIGHUP
94 return SIGHUP; /* FIXME: Suggestions? */
95 #else
96 return 1;
97 #endif
98 }
99
100 enum gdb_signal
101 sim_signal_to_gdb_signal (SIM_DESC sd, SIM_SIGNAL sig)
102 {
103 switch (sig)
104 {
105 case SIM_SIGINT :
106 return GDB_SIGNAL_INT;
107
108 case SIM_SIGABRT :
109 return GDB_SIGNAL_ABRT;
110
111 case SIM_SIGILL :
112 return GDB_SIGNAL_ILL;
113
114 case SIM_SIGTRAP :
115 return GDB_SIGNAL_TRAP;
116
117 case SIM_SIGBUS :
118 return GDB_SIGNAL_BUS;
119
120 case SIM_SIGSEGV :
121 return GDB_SIGNAL_SEGV;
122
123 case SIM_SIGXCPU :
124 return GDB_SIGNAL_XCPU;
125
126 case SIM_SIGFPE:
127 return GDB_SIGNAL_FPE;
128 break;
129
130 case SIM_SIGNONE:
131 return GDB_SIGNAL_0;
132 break;
133 }
134
135 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
136 return GDB_SIGNAL_HUP;
137 }