]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/common/sim-signal.c
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / sim / common / sim-signal.c
1 /* Simulator signal support
2 Copyright (C) 1997-2022 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
25 #include "sim-main.h"
26 #include "sim-signal.h"
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
34 #ifdef _WIN32
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
46 int
47 sim_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:
84 #ifdef SIGFPE
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 }
101
102 enum gdb_signal
103 sim_signal_to_gdb_signal (SIM_DESC sd, SIM_SIGNAL sig)
104 {
105 switch (sig)
106 {
107 case SIM_SIGINT :
108 return GDB_SIGNAL_INT;
109
110 case SIM_SIGABRT :
111 return GDB_SIGNAL_ABRT;
112
113 case SIM_SIGILL :
114 return GDB_SIGNAL_ILL;
115
116 case SIM_SIGTRAP :
117 return GDB_SIGNAL_TRAP;
118
119 case SIM_SIGBUS :
120 return GDB_SIGNAL_BUS;
121
122 case SIM_SIGSEGV :
123 return GDB_SIGNAL_SEGV;
124
125 case SIM_SIGXCPU :
126 return GDB_SIGNAL_XCPU;
127
128 case SIM_SIGFPE:
129 return GDB_SIGNAL_FPE;
130 break;
131
132 case SIM_SIGNONE:
133 return GDB_SIGNAL_0;
134 break;
135 }
136
137 sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
138 return GDB_SIGNAL_HUP;
139 }