1 /* Target signal translation functions for GDB.
2 Copyright (C) 1990-2022 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/>. */
20 #include "common-defs.h"
26 #include "gdb_signals.h"
30 /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest
31 _available_ realtime signal, not the lowest supported; glibc takes
32 several for its own use. */
35 # if defined(__SIGRTMIN)
36 # define REALTIME_LO __SIGRTMIN
37 # define REALTIME_HI (__SIGRTMAX + 1)
38 # elif defined(SIGRTMIN)
39 # define REALTIME_LO SIGRTMIN
40 # define REALTIME_HI (SIGRTMAX + 1)
44 /* This table must match in order and size the signals in enum
53 #define SET(symbol, constant, name, string) { #symbol, name, string },
54 #include "gdb/signals.def"
59 gdb_signal_to_symbol_string (enum gdb_signal sig
)
61 gdb_assert ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
);
63 return signals
[sig
].symbol
;
66 /* Return the string for a signal. */
68 gdb_signal_to_string (enum gdb_signal sig
)
70 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
)
71 return signals
[sig
].string
;
73 return signals
[GDB_SIGNAL_UNKNOWN
].string
;
76 /* Return the name for a signal. */
78 gdb_signal_to_name (enum gdb_signal sig
)
80 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
81 && signals
[sig
].name
!= NULL
)
82 return signals
[sig
].name
;
84 /* I think the code which prints this will always print it along
85 with the string, so no need to be verbose (very old comment). */
89 /* Given a name, return its signal. */
91 gdb_signal_from_name (const char *name
)
95 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
96 for GDB_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
97 questionable; seems like by now people should call it SIGABRT
100 /* This ugly cast brought to you by the native VAX compiler. */
101 for (sig
= GDB_SIGNAL_HUP
;
102 sig
< GDB_SIGNAL_LAST
;
103 sig
= (enum gdb_signal
) ((int) sig
+ 1))
104 if (signals
[sig
].name
!= NULL
105 && strcmp (name
, signals
[sig
].name
) == 0)
107 return GDB_SIGNAL_UNKNOWN
;
110 /* The following functions are to help certain targets deal
111 with the signal/waitstatus stuff. They could just as well be in
112 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
114 /* Convert host signal to our signals. */
116 gdb_signal_from_host (int hostsig
)
118 /* A switch statement would make sense but would require special
119 kludges to deal with the cases where more than one signal has the
120 same number. Signals are ordered ANSI-standard signals first,
121 other signals second, with signals in each block ordered by their
122 numerical values on a typical POSIX platform. */
127 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
128 are ANSI-standard signals and are always available. */
129 if (hostsig
== SIGINT
)
130 return GDB_SIGNAL_INT
;
131 if (hostsig
== SIGILL
)
132 return GDB_SIGNAL_ILL
;
133 if (hostsig
== SIGABRT
)
134 return GDB_SIGNAL_ABRT
;
135 if (hostsig
== SIGFPE
)
136 return GDB_SIGNAL_FPE
;
137 if (hostsig
== SIGSEGV
)
138 return GDB_SIGNAL_SEGV
;
139 if (hostsig
== SIGTERM
)
140 return GDB_SIGNAL_TERM
;
142 /* All other signals need preprocessor conditionals. */
144 if (hostsig
== SIGHUP
)
145 return GDB_SIGNAL_HUP
;
147 #if defined (SIGQUIT)
148 if (hostsig
== SIGQUIT
)
149 return GDB_SIGNAL_QUIT
;
151 #if defined (SIGTRAP)
152 if (hostsig
== SIGTRAP
)
153 return GDB_SIGNAL_TRAP
;
156 if (hostsig
== SIGEMT
)
157 return GDB_SIGNAL_EMT
;
159 #if defined (SIGKILL)
160 if (hostsig
== SIGKILL
)
161 return GDB_SIGNAL_KILL
;
164 if (hostsig
== SIGBUS
)
165 return GDB_SIGNAL_BUS
;
168 if (hostsig
== SIGSYS
)
169 return GDB_SIGNAL_SYS
;
171 #if defined (SIGPIPE)
172 if (hostsig
== SIGPIPE
)
173 return GDB_SIGNAL_PIPE
;
175 #if defined (SIGALRM)
176 if (hostsig
== SIGALRM
)
177 return GDB_SIGNAL_ALRM
;
179 #if defined (SIGUSR1)
180 if (hostsig
== SIGUSR1
)
181 return GDB_SIGNAL_USR1
;
183 #if defined (SIGUSR2)
184 if (hostsig
== SIGUSR2
)
185 return GDB_SIGNAL_USR2
;
188 if (hostsig
== SIGCLD
)
189 return GDB_SIGNAL_CHLD
;
191 #if defined (SIGCHLD)
192 if (hostsig
== SIGCHLD
)
193 return GDB_SIGNAL_CHLD
;
196 if (hostsig
== SIGPWR
)
197 return GDB_SIGNAL_PWR
;
199 #if defined (SIGWINCH)
200 if (hostsig
== SIGWINCH
)
201 return GDB_SIGNAL_WINCH
;
204 if (hostsig
== SIGURG
)
205 return GDB_SIGNAL_URG
;
208 if (hostsig
== SIGIO
)
209 return GDB_SIGNAL_IO
;
211 #if defined (SIGPOLL)
212 if (hostsig
== SIGPOLL
)
213 return GDB_SIGNAL_POLL
;
215 #if defined (SIGSTOP)
216 if (hostsig
== SIGSTOP
)
217 return GDB_SIGNAL_STOP
;
219 #if defined (SIGTSTP)
220 if (hostsig
== SIGTSTP
)
221 return GDB_SIGNAL_TSTP
;
223 #if defined (SIGCONT)
224 if (hostsig
== SIGCONT
)
225 return GDB_SIGNAL_CONT
;
227 #if defined (SIGTTIN)
228 if (hostsig
== SIGTTIN
)
229 return GDB_SIGNAL_TTIN
;
231 #if defined (SIGTTOU)
232 if (hostsig
== SIGTTOU
)
233 return GDB_SIGNAL_TTOU
;
235 #if defined (SIGVTALRM)
236 if (hostsig
== SIGVTALRM
)
237 return GDB_SIGNAL_VTALRM
;
239 #if defined (SIGPROF)
240 if (hostsig
== SIGPROF
)
241 return GDB_SIGNAL_PROF
;
243 #if defined (SIGXCPU)
244 if (hostsig
== SIGXCPU
)
245 return GDB_SIGNAL_XCPU
;
247 #if defined (SIGXFSZ)
248 if (hostsig
== SIGXFSZ
)
249 return GDB_SIGNAL_XFSZ
;
251 #if defined (SIGWIND)
252 if (hostsig
== SIGWIND
)
253 return GDB_SIGNAL_WIND
;
255 #if defined (SIGPHONE)
256 if (hostsig
== SIGPHONE
)
257 return GDB_SIGNAL_PHONE
;
259 #if defined (SIGLOST)
260 if (hostsig
== SIGLOST
)
261 return GDB_SIGNAL_LOST
;
263 #if defined (SIGWAITING)
264 if (hostsig
== SIGWAITING
)
265 return GDB_SIGNAL_WAITING
;
267 #if defined (SIGCANCEL)
268 if (hostsig
== SIGCANCEL
)
269 return GDB_SIGNAL_CANCEL
;
272 if (hostsig
== SIGLWP
)
273 return GDB_SIGNAL_LWP
;
275 #if defined (SIGDANGER)
276 if (hostsig
== SIGDANGER
)
277 return GDB_SIGNAL_DANGER
;
279 #if defined (SIGGRANT)
280 if (hostsig
== SIGGRANT
)
281 return GDB_SIGNAL_GRANT
;
283 #if defined (SIGRETRACT)
284 if (hostsig
== SIGRETRACT
)
285 return GDB_SIGNAL_RETRACT
;
288 if (hostsig
== SIGMSG
)
289 return GDB_SIGNAL_MSG
;
291 #if defined (SIGSOUND)
292 if (hostsig
== SIGSOUND
)
293 return GDB_SIGNAL_SOUND
;
296 if (hostsig
== SIGSAK
)
297 return GDB_SIGNAL_SAK
;
299 #if defined (SIGPRIO)
300 if (hostsig
== SIGPRIO
)
301 return GDB_SIGNAL_PRIO
;
304 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
305 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
306 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
307 return GDB_EXC_BAD_ACCESS
;
309 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
310 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
311 return GDB_EXC_BAD_INSTRUCTION
;
313 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
314 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
315 return GDB_EXC_ARITHMETIC
;
317 #if defined (EXC_EMULATION) && defined (_NSIG)
318 if (hostsig
== _NSIG
+ EXC_EMULATION
)
319 return GDB_EXC_EMULATION
;
321 #if defined (EXC_SOFTWARE) && defined (_NSIG)
322 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
323 return GDB_EXC_SOFTWARE
;
325 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
326 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
327 return GDB_EXC_BREAKPOINT
;
330 #if defined (SIGINFO)
331 if (hostsig
== SIGINFO
)
332 return GDB_SIGNAL_INFO
;
334 #if defined (SIGLIBRT)
335 if (hostsig
== SIGLIBRT
)
336 return GDB_SIGNAL_LIBRT
;
339 #if defined (REALTIME_LO)
340 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
342 /* This block of GDB_SIGNAL_REALTIME value is in order. */
343 if (33 <= hostsig
&& hostsig
<= 63)
344 return (enum gdb_signal
)
345 (hostsig
- 33 + (int) GDB_SIGNAL_REALTIME_33
);
346 else if (hostsig
== 32)
347 return GDB_SIGNAL_REALTIME_32
;
348 else if (64 <= hostsig
&& hostsig
<= 127)
349 return (enum gdb_signal
)
350 (hostsig
- 64 + (int) GDB_SIGNAL_REALTIME_64
);
352 error (_("GDB bug: target.c (gdb_signal_from_host): "
353 "unrecognized real-time signal"));
357 return GDB_SIGNAL_UNKNOWN
;
360 /* Convert a OURSIG (an enum gdb_signal) to the form used by the
361 target operating system (refered to as the ``host'') or zero if the
362 equivalent host signal is not available. Set/clear OURSIG_OK
366 do_gdb_signal_to_host (enum gdb_signal oursig
,
370 /* Silence the 'not used' warning, for targets that
371 do not support signals. */
374 /* Signals are ordered ANSI-standard signals first, other signals
375 second, with signals in each block ordered by their numerical
376 values on a typical POSIX platform. */
384 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
385 are ANSI-standard signals and are always available. */
390 case GDB_SIGNAL_ABRT
:
394 case GDB_SIGNAL_SEGV
:
396 case GDB_SIGNAL_TERM
:
399 /* All other signals need preprocessor conditionals. */
404 #if defined (SIGQUIT)
405 case GDB_SIGNAL_QUIT
:
408 #if defined (SIGTRAP)
409 case GDB_SIGNAL_TRAP
:
416 #if defined (SIGKILL)
417 case GDB_SIGNAL_KILL
:
428 #if defined (SIGPIPE)
429 case GDB_SIGNAL_PIPE
:
432 #if defined (SIGALRM)
433 case GDB_SIGNAL_ALRM
:
436 #if defined (SIGUSR1)
437 case GDB_SIGNAL_USR1
:
440 #if defined (SIGUSR2)
441 case GDB_SIGNAL_USR2
:
444 #if defined (SIGCHLD) || defined (SIGCLD)
445 case GDB_SIGNAL_CHLD
:
446 #if defined (SIGCHLD)
451 #endif /* SIGCLD or SIGCHLD */
456 #if defined (SIGWINCH)
457 case GDB_SIGNAL_WINCH
:
468 #if defined (SIGPOLL)
469 case GDB_SIGNAL_POLL
:
472 #if defined (SIGSTOP)
473 case GDB_SIGNAL_STOP
:
476 #if defined (SIGTSTP)
477 case GDB_SIGNAL_TSTP
:
480 #if defined (SIGCONT)
481 case GDB_SIGNAL_CONT
:
484 #if defined (SIGTTIN)
485 case GDB_SIGNAL_TTIN
:
488 #if defined (SIGTTOU)
489 case GDB_SIGNAL_TTOU
:
492 #if defined (SIGVTALRM)
493 case GDB_SIGNAL_VTALRM
:
496 #if defined (SIGPROF)
497 case GDB_SIGNAL_PROF
:
500 #if defined (SIGXCPU)
501 case GDB_SIGNAL_XCPU
:
504 #if defined (SIGXFSZ)
505 case GDB_SIGNAL_XFSZ
:
508 #if defined (SIGWIND)
509 case GDB_SIGNAL_WIND
:
512 #if defined (SIGPHONE)
513 case GDB_SIGNAL_PHONE
:
516 #if defined (SIGLOST)
517 case GDB_SIGNAL_LOST
:
520 #if defined (SIGWAITING)
521 case GDB_SIGNAL_WAITING
:
524 #if defined (SIGCANCEL)
525 case GDB_SIGNAL_CANCEL
:
532 #if defined (SIGDANGER)
533 case GDB_SIGNAL_DANGER
:
536 #if defined (SIGGRANT)
537 case GDB_SIGNAL_GRANT
:
540 #if defined (SIGRETRACT)
541 case GDB_SIGNAL_RETRACT
:
548 #if defined (SIGSOUND)
549 case GDB_SIGNAL_SOUND
:
556 #if defined (SIGPRIO)
557 case GDB_SIGNAL_PRIO
:
561 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
562 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
563 case GDB_EXC_BAD_ACCESS
:
564 return _NSIG
+ EXC_BAD_ACCESS
;
566 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
567 case GDB_EXC_BAD_INSTRUCTION
:
568 return _NSIG
+ EXC_BAD_INSTRUCTION
;
570 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
571 case GDB_EXC_ARITHMETIC
:
572 return _NSIG
+ EXC_ARITHMETIC
;
574 #if defined (EXC_EMULATION) && defined (_NSIG)
575 case GDB_EXC_EMULATION
:
576 return _NSIG
+ EXC_EMULATION
;
578 #if defined (EXC_SOFTWARE) && defined (_NSIG)
579 case GDB_EXC_SOFTWARE
:
580 return _NSIG
+ EXC_SOFTWARE
;
582 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
583 case GDB_EXC_BREAKPOINT
:
584 return _NSIG
+ EXC_BREAKPOINT
;
587 #if defined (SIGINFO)
588 case GDB_SIGNAL_INFO
:
591 #if defined (SIGLIBRT)
592 case GDB_SIGNAL_LIBRT
:
597 #if defined (REALTIME_LO)
600 if (oursig
>= GDB_SIGNAL_REALTIME_33
601 && oursig
<= GDB_SIGNAL_REALTIME_63
)
603 /* This block of signals is continuous, and
604 GDB_SIGNAL_REALTIME_33 is 33 by definition. */
605 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_33
+ 33;
607 else if (oursig
== GDB_SIGNAL_REALTIME_32
)
609 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
610 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */
613 else if (oursig
>= GDB_SIGNAL_REALTIME_64
614 && oursig
<= GDB_SIGNAL_REALTIME_127
)
616 /* This block of signals is continuous, and
617 GDB_SIGNAL_REALTIME_64 is 64 by definition. */
618 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_64
+ 64;
621 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
631 gdb_signal_to_host_p (enum gdb_signal oursig
)
634 do_gdb_signal_to_host (oursig
, &oursig_ok
);
639 gdb_signal_to_host (enum gdb_signal oursig
)
642 int targ_signo
= do_gdb_signal_to_host (oursig
, &oursig_ok
);
645 /* The user might be trying to do "signal SIGSAK" where this system
646 doesn't have SIGSAK. */
647 warning (_("Signal %s does not exist on this system."),
648 gdb_signal_to_name (oursig
));