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