1 /* Target signal translation functions for GDB.
2 Copyright (C) 1990-2024 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
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.
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.
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/>. */
25 #include "gdb_signals.h"
29 /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest
30 _available_ realtime signal, not the lowest supported; glibc takes
31 several for its own use. */
33 #if defined(__SIGRTMIN)
34 # define REALTIME_LO __SIGRTMIN
35 # define REALTIME_HI (__SIGRTMAX + 1)
36 #elif defined(SIGRTMIN)
37 # define REALTIME_LO SIGRTMIN
38 # define REALTIME_HI (SIGRTMAX + 1)
41 /* This table must match in order and size the signals in enum
50 #define SET(symbol, constant, name, string) { #symbol, name, string },
51 #include "gdb/signals.def"
56 gdb_signal_to_symbol_string (enum gdb_signal sig
)
58 gdb_assert ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
);
60 return signals
[sig
].symbol
;
63 /* Return the string for a signal. */
65 gdb_signal_to_string (enum gdb_signal sig
)
67 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
)
68 return signals
[sig
].string
;
70 return signals
[GDB_SIGNAL_UNKNOWN
].string
;
73 /* Return the name for a signal. */
75 gdb_signal_to_name (enum gdb_signal sig
)
77 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
78 && signals
[sig
].name
!= NULL
)
79 return signals
[sig
].name
;
81 /* I think the code which prints this will always print it along
82 with the string, so no need to be verbose (very old comment). */
86 /* Given a name, return its signal. */
88 gdb_signal_from_name (const char *name
)
92 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
93 for GDB_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
94 questionable; seems like by now people should call it SIGABRT
97 /* This ugly cast brought to you by the native VAX compiler. */
98 for (sig
= GDB_SIGNAL_HUP
;
99 sig
< GDB_SIGNAL_LAST
;
100 sig
= (enum gdb_signal
) ((int) sig
+ 1))
101 if (signals
[sig
].name
!= NULL
102 && strcmp (name
, signals
[sig
].name
) == 0)
104 return GDB_SIGNAL_UNKNOWN
;
107 /* The following functions are to help certain targets deal
108 with the signal/waitstatus stuff. They could just as well be in
109 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
111 /* Convert host signal to our signals. */
113 gdb_signal_from_host (int hostsig
)
115 /* A switch statement would make sense but would require special
116 kludges to deal with the cases where more than one signal has the
117 same number. Signals are ordered ANSI-standard signals first,
118 other signals second, with signals in each block ordered by their
119 numerical values on a typical POSIX platform. */
124 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
125 are ANSI-standard signals and are always available. */
126 if (hostsig
== SIGINT
)
127 return GDB_SIGNAL_INT
;
128 if (hostsig
== SIGILL
)
129 return GDB_SIGNAL_ILL
;
130 if (hostsig
== SIGABRT
)
131 return GDB_SIGNAL_ABRT
;
132 if (hostsig
== SIGFPE
)
133 return GDB_SIGNAL_FPE
;
134 if (hostsig
== SIGSEGV
)
135 return GDB_SIGNAL_SEGV
;
136 if (hostsig
== SIGTERM
)
137 return GDB_SIGNAL_TERM
;
139 /* All other signals need preprocessor conditionals. */
141 if (hostsig
== SIGHUP
)
142 return GDB_SIGNAL_HUP
;
144 #if defined (SIGQUIT)
145 if (hostsig
== SIGQUIT
)
146 return GDB_SIGNAL_QUIT
;
148 #if defined (SIGTRAP)
149 if (hostsig
== SIGTRAP
)
150 return GDB_SIGNAL_TRAP
;
153 if (hostsig
== SIGEMT
)
154 return GDB_SIGNAL_EMT
;
156 #if defined (SIGKILL)
157 if (hostsig
== SIGKILL
)
158 return GDB_SIGNAL_KILL
;
161 if (hostsig
== SIGBUS
)
162 return GDB_SIGNAL_BUS
;
165 if (hostsig
== SIGSYS
)
166 return GDB_SIGNAL_SYS
;
168 #if defined (SIGPIPE)
169 if (hostsig
== SIGPIPE
)
170 return GDB_SIGNAL_PIPE
;
172 #if defined (SIGALRM)
173 if (hostsig
== SIGALRM
)
174 return GDB_SIGNAL_ALRM
;
176 #if defined (SIGUSR1)
177 if (hostsig
== SIGUSR1
)
178 return GDB_SIGNAL_USR1
;
180 #if defined (SIGUSR2)
181 if (hostsig
== SIGUSR2
)
182 return GDB_SIGNAL_USR2
;
185 if (hostsig
== SIGCLD
)
186 return GDB_SIGNAL_CHLD
;
188 #if defined (SIGCHLD)
189 if (hostsig
== SIGCHLD
)
190 return GDB_SIGNAL_CHLD
;
193 if (hostsig
== SIGPWR
)
194 return GDB_SIGNAL_PWR
;
196 #if defined (SIGWINCH)
197 if (hostsig
== SIGWINCH
)
198 return GDB_SIGNAL_WINCH
;
201 if (hostsig
== SIGURG
)
202 return GDB_SIGNAL_URG
;
205 if (hostsig
== SIGIO
)
206 return GDB_SIGNAL_IO
;
208 #if defined (SIGPOLL)
209 if (hostsig
== SIGPOLL
)
210 return GDB_SIGNAL_POLL
;
212 #if defined (SIGSTOP)
213 if (hostsig
== SIGSTOP
)
214 return GDB_SIGNAL_STOP
;
216 #if defined (SIGTSTP)
217 if (hostsig
== SIGTSTP
)
218 return GDB_SIGNAL_TSTP
;
220 #if defined (SIGCONT)
221 if (hostsig
== SIGCONT
)
222 return GDB_SIGNAL_CONT
;
224 #if defined (SIGTTIN)
225 if (hostsig
== SIGTTIN
)
226 return GDB_SIGNAL_TTIN
;
228 #if defined (SIGTTOU)
229 if (hostsig
== SIGTTOU
)
230 return GDB_SIGNAL_TTOU
;
232 #if defined (SIGVTALRM)
233 if (hostsig
== SIGVTALRM
)
234 return GDB_SIGNAL_VTALRM
;
236 #if defined (SIGPROF)
237 if (hostsig
== SIGPROF
)
238 return GDB_SIGNAL_PROF
;
240 #if defined (SIGXCPU)
241 if (hostsig
== SIGXCPU
)
242 return GDB_SIGNAL_XCPU
;
244 #if defined (SIGXFSZ)
245 if (hostsig
== SIGXFSZ
)
246 return GDB_SIGNAL_XFSZ
;
248 #if defined (SIGWIND)
249 if (hostsig
== SIGWIND
)
250 return GDB_SIGNAL_WIND
;
252 #if defined (SIGPHONE)
253 if (hostsig
== SIGPHONE
)
254 return GDB_SIGNAL_PHONE
;
256 #if defined (SIGLOST)
257 if (hostsig
== SIGLOST
)
258 return GDB_SIGNAL_LOST
;
260 #if defined (SIGWAITING)
261 if (hostsig
== SIGWAITING
)
262 return GDB_SIGNAL_WAITING
;
264 #if defined (SIGCANCEL)
265 if (hostsig
== SIGCANCEL
)
266 return GDB_SIGNAL_CANCEL
;
269 if (hostsig
== SIGLWP
)
270 return GDB_SIGNAL_LWP
;
272 #if defined (SIGDANGER)
273 if (hostsig
== SIGDANGER
)
274 return GDB_SIGNAL_DANGER
;
276 #if defined (SIGGRANT)
277 if (hostsig
== SIGGRANT
)
278 return GDB_SIGNAL_GRANT
;
280 #if defined (SIGRETRACT)
281 if (hostsig
== SIGRETRACT
)
282 return GDB_SIGNAL_RETRACT
;
285 if (hostsig
== SIGMSG
)
286 return GDB_SIGNAL_MSG
;
288 #if defined (SIGSOUND)
289 if (hostsig
== SIGSOUND
)
290 return GDB_SIGNAL_SOUND
;
293 if (hostsig
== SIGSAK
)
294 return GDB_SIGNAL_SAK
;
296 #if defined (SIGPRIO)
297 if (hostsig
== SIGPRIO
)
298 return GDB_SIGNAL_PRIO
;
301 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
302 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
303 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
304 return GDB_EXC_BAD_ACCESS
;
306 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
307 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
308 return GDB_EXC_BAD_INSTRUCTION
;
310 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
311 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
312 return GDB_EXC_ARITHMETIC
;
314 #if defined (EXC_EMULATION) && defined (_NSIG)
315 if (hostsig
== _NSIG
+ EXC_EMULATION
)
316 return GDB_EXC_EMULATION
;
318 #if defined (EXC_SOFTWARE) && defined (_NSIG)
319 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
320 return GDB_EXC_SOFTWARE
;
322 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
323 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
324 return GDB_EXC_BREAKPOINT
;
327 #if defined (SIGINFO)
328 if (hostsig
== SIGINFO
)
329 return GDB_SIGNAL_INFO
;
331 #if defined (SIGLIBRT)
332 if (hostsig
== SIGLIBRT
)
333 return GDB_SIGNAL_LIBRT
;
336 #if defined (REALTIME_LO)
337 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
339 /* This block of GDB_SIGNAL_REALTIME value is in order. */
340 if (33 <= hostsig
&& hostsig
<= 63)
341 return (enum gdb_signal
)
342 (hostsig
- 33 + (int) GDB_SIGNAL_REALTIME_33
);
343 else if (hostsig
== 32)
344 return GDB_SIGNAL_REALTIME_32
;
345 else if (64 <= hostsig
&& hostsig
<= 127)
346 return (enum gdb_signal
)
347 (hostsig
- 64 + (int) GDB_SIGNAL_REALTIME_64
);
349 error (_("GDB bug: target.c (gdb_signal_from_host): "
350 "unrecognized real-time signal"));
354 return GDB_SIGNAL_UNKNOWN
;
357 /* Convert a OURSIG (an enum gdb_signal) to the form used by the
358 target operating system (referred to as the ``host'') or zero if the
359 equivalent host signal is not available. Set/clear OURSIG_OK
363 do_gdb_signal_to_host (enum gdb_signal oursig
,
367 /* Silence the 'not used' warning, for targets that
368 do not support signals. */
371 /* Signals are ordered ANSI-standard signals first, other signals
372 second, with signals in each block ordered by their numerical
373 values on a typical POSIX platform. */
381 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
382 are ANSI-standard signals and are always available. */
387 case GDB_SIGNAL_ABRT
:
391 case GDB_SIGNAL_SEGV
:
393 case GDB_SIGNAL_TERM
:
396 /* All other signals need preprocessor conditionals. */
401 #if defined (SIGQUIT)
402 case GDB_SIGNAL_QUIT
:
405 #if defined (SIGTRAP)
406 case GDB_SIGNAL_TRAP
:
413 #if defined (SIGKILL)
414 case GDB_SIGNAL_KILL
:
425 #if defined (SIGPIPE)
426 case GDB_SIGNAL_PIPE
:
429 #if defined (SIGALRM)
430 case GDB_SIGNAL_ALRM
:
433 #if defined (SIGUSR1)
434 case GDB_SIGNAL_USR1
:
437 #if defined (SIGUSR2)
438 case GDB_SIGNAL_USR2
:
441 #if defined (SIGCHLD) || defined (SIGCLD)
442 case GDB_SIGNAL_CHLD
:
443 #if defined (SIGCHLD)
448 #endif /* SIGCLD or SIGCHLD */
453 #if defined (SIGWINCH)
454 case GDB_SIGNAL_WINCH
:
465 #if defined (SIGPOLL)
466 case GDB_SIGNAL_POLL
:
469 #if defined (SIGSTOP)
470 case GDB_SIGNAL_STOP
:
473 #if defined (SIGTSTP)
474 case GDB_SIGNAL_TSTP
:
477 #if defined (SIGCONT)
478 case GDB_SIGNAL_CONT
:
481 #if defined (SIGTTIN)
482 case GDB_SIGNAL_TTIN
:
485 #if defined (SIGTTOU)
486 case GDB_SIGNAL_TTOU
:
489 #if defined (SIGVTALRM)
490 case GDB_SIGNAL_VTALRM
:
493 #if defined (SIGPROF)
494 case GDB_SIGNAL_PROF
:
497 #if defined (SIGXCPU)
498 case GDB_SIGNAL_XCPU
:
501 #if defined (SIGXFSZ)
502 case GDB_SIGNAL_XFSZ
:
505 #if defined (SIGWIND)
506 case GDB_SIGNAL_WIND
:
509 #if defined (SIGPHONE)
510 case GDB_SIGNAL_PHONE
:
513 #if defined (SIGLOST)
514 case GDB_SIGNAL_LOST
:
517 #if defined (SIGWAITING)
518 case GDB_SIGNAL_WAITING
:
521 #if defined (SIGCANCEL)
522 case GDB_SIGNAL_CANCEL
:
529 #if defined (SIGDANGER)
530 case GDB_SIGNAL_DANGER
:
533 #if defined (SIGGRANT)
534 case GDB_SIGNAL_GRANT
:
537 #if defined (SIGRETRACT)
538 case GDB_SIGNAL_RETRACT
:
545 #if defined (SIGSOUND)
546 case GDB_SIGNAL_SOUND
:
553 #if defined (SIGPRIO)
554 case GDB_SIGNAL_PRIO
:
558 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
559 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
560 case GDB_EXC_BAD_ACCESS
:
561 return _NSIG
+ EXC_BAD_ACCESS
;
563 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
564 case GDB_EXC_BAD_INSTRUCTION
:
565 return _NSIG
+ EXC_BAD_INSTRUCTION
;
567 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
568 case GDB_EXC_ARITHMETIC
:
569 return _NSIG
+ EXC_ARITHMETIC
;
571 #if defined (EXC_EMULATION) && defined (_NSIG)
572 case GDB_EXC_EMULATION
:
573 return _NSIG
+ EXC_EMULATION
;
575 #if defined (EXC_SOFTWARE) && defined (_NSIG)
576 case GDB_EXC_SOFTWARE
:
577 return _NSIG
+ EXC_SOFTWARE
;
579 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
580 case GDB_EXC_BREAKPOINT
:
581 return _NSIG
+ EXC_BREAKPOINT
;
584 #if defined (SIGINFO)
585 case GDB_SIGNAL_INFO
:
588 #if defined (SIGLIBRT)
589 case GDB_SIGNAL_LIBRT
:
594 #if defined (REALTIME_LO)
597 if (oursig
>= GDB_SIGNAL_REALTIME_33
598 && oursig
<= GDB_SIGNAL_REALTIME_63
)
600 /* This block of signals is continuous, and
601 GDB_SIGNAL_REALTIME_33 is 33 by definition. */
602 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_33
+ 33;
604 else if (oursig
== GDB_SIGNAL_REALTIME_32
)
606 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
607 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */
610 else if (oursig
>= GDB_SIGNAL_REALTIME_64
611 && oursig
<= GDB_SIGNAL_REALTIME_127
)
613 /* This block of signals is continuous, and
614 GDB_SIGNAL_REALTIME_64 is 64 by definition. */
615 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_64
+ 64;
618 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
628 gdb_signal_to_host_p (enum gdb_signal oursig
)
631 do_gdb_signal_to_host (oursig
, &oursig_ok
);
636 gdb_signal_to_host (enum gdb_signal oursig
)
639 int targ_signo
= do_gdb_signal_to_host (oursig
, &oursig_ok
);
642 /* The user might be trying to do "signal SIGSAK" where this system
643 doesn't have SIGSAK. */
644 warning (_("Signal %s does not exist on this system."),
645 gdb_signal_to_name (oursig
));