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