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. */
34 # if defined(__SIGRTMIN)
35 # define REALTIME_LO __SIGRTMIN
36 # define REALTIME_HI (__SIGRTMAX + 1)
37 # elif defined(SIGRTMIN)
38 # define REALTIME_LO SIGRTMIN
39 # define REALTIME_HI (SIGRTMAX + 1)
43 /* This table must match in order and size the signals in enum
52 #define SET(symbol, constant, name, string) { #symbol, name, string },
53 #include "gdb/signals.def"
58 gdb_signal_to_symbol_string (enum gdb_signal sig
)
60 gdb_assert ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
);
62 return signals
[sig
].symbol
;
65 /* Return the string for a signal. */
67 gdb_signal_to_string (enum gdb_signal sig
)
69 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
)
70 return signals
[sig
].string
;
72 return signals
[GDB_SIGNAL_UNKNOWN
].string
;
75 /* Return the name for a signal. */
77 gdb_signal_to_name (enum gdb_signal sig
)
79 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
80 && signals
[sig
].name
!= NULL
)
81 return signals
[sig
].name
;
83 /* I think the code which prints this will always print it along
84 with the string, so no need to be verbose (very old comment). */
88 /* Given a name, return its signal. */
90 gdb_signal_from_name (const char *name
)
94 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
95 for GDB_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
96 questionable; seems like by now people should call it SIGABRT
99 /* This ugly cast brought to you by the native VAX compiler. */
100 for (sig
= GDB_SIGNAL_HUP
;
101 sig
< GDB_SIGNAL_LAST
;
102 sig
= (enum gdb_signal
) ((int) sig
+ 1))
103 if (signals
[sig
].name
!= NULL
104 && strcmp (name
, signals
[sig
].name
) == 0)
106 return GDB_SIGNAL_UNKNOWN
;
109 /* The following functions are to help certain targets deal
110 with the signal/waitstatus stuff. They could just as well be in
111 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
113 /* Convert host signal to our signals. */
115 gdb_signal_from_host (int hostsig
)
117 /* A switch statement would make sense but would require special
118 kludges to deal with the cases where more than one signal has the
119 same number. Signals are ordered ANSI-standard signals first,
120 other signals second, with signals in each block ordered by their
121 numerical values on a typical POSIX platform. */
126 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
127 are ANSI-standard signals and are always available. */
128 if (hostsig
== SIGINT
)
129 return GDB_SIGNAL_INT
;
130 if (hostsig
== SIGILL
)
131 return GDB_SIGNAL_ILL
;
132 if (hostsig
== SIGABRT
)
133 return GDB_SIGNAL_ABRT
;
134 if (hostsig
== SIGFPE
)
135 return GDB_SIGNAL_FPE
;
136 if (hostsig
== SIGSEGV
)
137 return GDB_SIGNAL_SEGV
;
138 if (hostsig
== SIGTERM
)
139 return GDB_SIGNAL_TERM
;
141 /* All other signals need preprocessor conditionals. */
143 if (hostsig
== SIGHUP
)
144 return GDB_SIGNAL_HUP
;
146 #if defined (SIGQUIT)
147 if (hostsig
== SIGQUIT
)
148 return GDB_SIGNAL_QUIT
;
150 #if defined (SIGTRAP)
151 if (hostsig
== SIGTRAP
)
152 return GDB_SIGNAL_TRAP
;
155 if (hostsig
== SIGEMT
)
156 return GDB_SIGNAL_EMT
;
158 #if defined (SIGKILL)
159 if (hostsig
== SIGKILL
)
160 return GDB_SIGNAL_KILL
;
163 if (hostsig
== SIGBUS
)
164 return GDB_SIGNAL_BUS
;
167 if (hostsig
== SIGSYS
)
168 return GDB_SIGNAL_SYS
;
170 #if defined (SIGPIPE)
171 if (hostsig
== SIGPIPE
)
172 return GDB_SIGNAL_PIPE
;
174 #if defined (SIGALRM)
175 if (hostsig
== SIGALRM
)
176 return GDB_SIGNAL_ALRM
;
178 #if defined (SIGUSR1)
179 if (hostsig
== SIGUSR1
)
180 return GDB_SIGNAL_USR1
;
182 #if defined (SIGUSR2)
183 if (hostsig
== SIGUSR2
)
184 return GDB_SIGNAL_USR2
;
187 if (hostsig
== SIGCLD
)
188 return GDB_SIGNAL_CHLD
;
190 #if defined (SIGCHLD)
191 if (hostsig
== SIGCHLD
)
192 return GDB_SIGNAL_CHLD
;
195 if (hostsig
== SIGPWR
)
196 return GDB_SIGNAL_PWR
;
198 #if defined (SIGWINCH)
199 if (hostsig
== SIGWINCH
)
200 return GDB_SIGNAL_WINCH
;
203 if (hostsig
== SIGURG
)
204 return GDB_SIGNAL_URG
;
207 if (hostsig
== SIGIO
)
208 return GDB_SIGNAL_IO
;
210 #if defined (SIGPOLL)
211 if (hostsig
== SIGPOLL
)
212 return GDB_SIGNAL_POLL
;
214 #if defined (SIGSTOP)
215 if (hostsig
== SIGSTOP
)
216 return GDB_SIGNAL_STOP
;
218 #if defined (SIGTSTP)
219 if (hostsig
== SIGTSTP
)
220 return GDB_SIGNAL_TSTP
;
222 #if defined (SIGCONT)
223 if (hostsig
== SIGCONT
)
224 return GDB_SIGNAL_CONT
;
226 #if defined (SIGTTIN)
227 if (hostsig
== SIGTTIN
)
228 return GDB_SIGNAL_TTIN
;
230 #if defined (SIGTTOU)
231 if (hostsig
== SIGTTOU
)
232 return GDB_SIGNAL_TTOU
;
234 #if defined (SIGVTALRM)
235 if (hostsig
== SIGVTALRM
)
236 return GDB_SIGNAL_VTALRM
;
238 #if defined (SIGPROF)
239 if (hostsig
== SIGPROF
)
240 return GDB_SIGNAL_PROF
;
242 #if defined (SIGXCPU)
243 if (hostsig
== SIGXCPU
)
244 return GDB_SIGNAL_XCPU
;
246 #if defined (SIGXFSZ)
247 if (hostsig
== SIGXFSZ
)
248 return GDB_SIGNAL_XFSZ
;
250 #if defined (SIGWIND)
251 if (hostsig
== SIGWIND
)
252 return GDB_SIGNAL_WIND
;
254 #if defined (SIGPHONE)
255 if (hostsig
== SIGPHONE
)
256 return GDB_SIGNAL_PHONE
;
258 #if defined (SIGLOST)
259 if (hostsig
== SIGLOST
)
260 return GDB_SIGNAL_LOST
;
262 #if defined (SIGWAITING)
263 if (hostsig
== SIGWAITING
)
264 return GDB_SIGNAL_WAITING
;
266 #if defined (SIGCANCEL)
267 if (hostsig
== SIGCANCEL
)
268 return GDB_SIGNAL_CANCEL
;
271 if (hostsig
== SIGLWP
)
272 return GDB_SIGNAL_LWP
;
274 #if defined (SIGDANGER)
275 if (hostsig
== SIGDANGER
)
276 return GDB_SIGNAL_DANGER
;
278 #if defined (SIGGRANT)
279 if (hostsig
== SIGGRANT
)
280 return GDB_SIGNAL_GRANT
;
282 #if defined (SIGRETRACT)
283 if (hostsig
== SIGRETRACT
)
284 return GDB_SIGNAL_RETRACT
;
287 if (hostsig
== SIGMSG
)
288 return GDB_SIGNAL_MSG
;
290 #if defined (SIGSOUND)
291 if (hostsig
== SIGSOUND
)
292 return GDB_SIGNAL_SOUND
;
295 if (hostsig
== SIGSAK
)
296 return GDB_SIGNAL_SAK
;
298 #if defined (SIGPRIO)
299 if (hostsig
== SIGPRIO
)
300 return GDB_SIGNAL_PRIO
;
303 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
304 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
305 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
306 return GDB_EXC_BAD_ACCESS
;
308 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
309 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
310 return GDB_EXC_BAD_INSTRUCTION
;
312 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
313 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
314 return GDB_EXC_ARITHMETIC
;
316 #if defined (EXC_EMULATION) && defined (_NSIG)
317 if (hostsig
== _NSIG
+ EXC_EMULATION
)
318 return GDB_EXC_EMULATION
;
320 #if defined (EXC_SOFTWARE) && defined (_NSIG)
321 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
322 return GDB_EXC_SOFTWARE
;
324 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
325 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
326 return GDB_EXC_BREAKPOINT
;
329 #if defined (SIGINFO)
330 if (hostsig
== SIGINFO
)
331 return GDB_SIGNAL_INFO
;
333 #if defined (SIGLIBRT)
334 if (hostsig
== SIGLIBRT
)
335 return GDB_SIGNAL_LIBRT
;
338 #if defined (REALTIME_LO)
339 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
341 /* This block of GDB_SIGNAL_REALTIME value is in order. */
342 if (33 <= hostsig
&& hostsig
<= 63)
343 return (enum gdb_signal
)
344 (hostsig
- 33 + (int) GDB_SIGNAL_REALTIME_33
);
345 else if (hostsig
== 32)
346 return GDB_SIGNAL_REALTIME_32
;
347 else if (64 <= hostsig
&& hostsig
<= 127)
348 return (enum gdb_signal
)
349 (hostsig
- 64 + (int) GDB_SIGNAL_REALTIME_64
);
351 error (_("GDB bug: target.c (gdb_signal_from_host): "
352 "unrecognized real-time signal"));
356 return GDB_SIGNAL_UNKNOWN
;
359 /* Convert a OURSIG (an enum gdb_signal) to the form used by the
360 target operating system (referred to as the ``host'') or zero if the
361 equivalent host signal is not available. Set/clear OURSIG_OK
365 do_gdb_signal_to_host (enum gdb_signal oursig
,
369 /* Silence the 'not used' warning, for targets that
370 do not support signals. */
373 /* Signals are ordered ANSI-standard signals first, other signals
374 second, with signals in each block ordered by their numerical
375 values on a typical POSIX platform. */
383 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
384 are ANSI-standard signals and are always available. */
389 case GDB_SIGNAL_ABRT
:
393 case GDB_SIGNAL_SEGV
:
395 case GDB_SIGNAL_TERM
:
398 /* All other signals need preprocessor conditionals. */
403 #if defined (SIGQUIT)
404 case GDB_SIGNAL_QUIT
:
407 #if defined (SIGTRAP)
408 case GDB_SIGNAL_TRAP
:
415 #if defined (SIGKILL)
416 case GDB_SIGNAL_KILL
:
427 #if defined (SIGPIPE)
428 case GDB_SIGNAL_PIPE
:
431 #if defined (SIGALRM)
432 case GDB_SIGNAL_ALRM
:
435 #if defined (SIGUSR1)
436 case GDB_SIGNAL_USR1
:
439 #if defined (SIGUSR2)
440 case GDB_SIGNAL_USR2
:
443 #if defined (SIGCHLD) || defined (SIGCLD)
444 case GDB_SIGNAL_CHLD
:
445 #if defined (SIGCHLD)
450 #endif /* SIGCLD or SIGCHLD */
455 #if defined (SIGWINCH)
456 case GDB_SIGNAL_WINCH
:
467 #if defined (SIGPOLL)
468 case GDB_SIGNAL_POLL
:
471 #if defined (SIGSTOP)
472 case GDB_SIGNAL_STOP
:
475 #if defined (SIGTSTP)
476 case GDB_SIGNAL_TSTP
:
479 #if defined (SIGCONT)
480 case GDB_SIGNAL_CONT
:
483 #if defined (SIGTTIN)
484 case GDB_SIGNAL_TTIN
:
487 #if defined (SIGTTOU)
488 case GDB_SIGNAL_TTOU
:
491 #if defined (SIGVTALRM)
492 case GDB_SIGNAL_VTALRM
:
495 #if defined (SIGPROF)
496 case GDB_SIGNAL_PROF
:
499 #if defined (SIGXCPU)
500 case GDB_SIGNAL_XCPU
:
503 #if defined (SIGXFSZ)
504 case GDB_SIGNAL_XFSZ
:
507 #if defined (SIGWIND)
508 case GDB_SIGNAL_WIND
:
511 #if defined (SIGPHONE)
512 case GDB_SIGNAL_PHONE
:
515 #if defined (SIGLOST)
516 case GDB_SIGNAL_LOST
:
519 #if defined (SIGWAITING)
520 case GDB_SIGNAL_WAITING
:
523 #if defined (SIGCANCEL)
524 case GDB_SIGNAL_CANCEL
:
531 #if defined (SIGDANGER)
532 case GDB_SIGNAL_DANGER
:
535 #if defined (SIGGRANT)
536 case GDB_SIGNAL_GRANT
:
539 #if defined (SIGRETRACT)
540 case GDB_SIGNAL_RETRACT
:
547 #if defined (SIGSOUND)
548 case GDB_SIGNAL_SOUND
:
555 #if defined (SIGPRIO)
556 case GDB_SIGNAL_PRIO
:
560 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
561 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
562 case GDB_EXC_BAD_ACCESS
:
563 return _NSIG
+ EXC_BAD_ACCESS
;
565 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
566 case GDB_EXC_BAD_INSTRUCTION
:
567 return _NSIG
+ EXC_BAD_INSTRUCTION
;
569 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
570 case GDB_EXC_ARITHMETIC
:
571 return _NSIG
+ EXC_ARITHMETIC
;
573 #if defined (EXC_EMULATION) && defined (_NSIG)
574 case GDB_EXC_EMULATION
:
575 return _NSIG
+ EXC_EMULATION
;
577 #if defined (EXC_SOFTWARE) && defined (_NSIG)
578 case GDB_EXC_SOFTWARE
:
579 return _NSIG
+ EXC_SOFTWARE
;
581 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
582 case GDB_EXC_BREAKPOINT
:
583 return _NSIG
+ EXC_BREAKPOINT
;
586 #if defined (SIGINFO)
587 case GDB_SIGNAL_INFO
:
590 #if defined (SIGLIBRT)
591 case GDB_SIGNAL_LIBRT
:
596 #if defined (REALTIME_LO)
599 if (oursig
>= GDB_SIGNAL_REALTIME_33
600 && oursig
<= GDB_SIGNAL_REALTIME_63
)
602 /* This block of signals is continuous, and
603 GDB_SIGNAL_REALTIME_33 is 33 by definition. */
604 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_33
+ 33;
606 else if (oursig
== GDB_SIGNAL_REALTIME_32
)
608 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
609 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */
612 else if (oursig
>= GDB_SIGNAL_REALTIME_64
613 && oursig
<= GDB_SIGNAL_REALTIME_127
)
615 /* This block of signals is continuous, and
616 GDB_SIGNAL_REALTIME_64 is 64 by definition. */
617 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_64
+ 64;
620 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
630 gdb_signal_to_host_p (enum gdb_signal oursig
)
633 do_gdb_signal_to_host (oursig
, &oursig_ok
);
638 gdb_signal_to_host (enum gdb_signal oursig
)
641 int targ_signo
= do_gdb_signal_to_host (oursig
, &oursig_ok
);
644 /* The user might be trying to do "signal SIGSAK" where this system
645 doesn't have SIGSAK. */
646 warning (_("Signal %s does not exist on this system."),
647 gdb_signal_to_name (oursig
));