1 /* Target signal translation functions for GDB.
2 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdb_string.h"
33 #include "gdb_signals.h"
37 /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest
38 _available_ realtime signal, not the lowest supported; glibc takes
39 several for its own use. */
42 # if defined(__SIGRTMIN)
43 # define REALTIME_LO __SIGRTMIN
44 # define REALTIME_HI (__SIGRTMAX + 1)
45 # elif defined(SIGRTMIN)
46 # define REALTIME_LO SIGRTMIN
47 # define REALTIME_HI (SIGRTMAX + 1)
51 /* This table must match in order and size the signals in enum target_signal. */
58 #define SET(symbol, constant, name, string) { name, string },
59 #include "gdb/signals.def"
64 /* Return the string for a signal. */
66 target_signal_to_string (enum target_signal sig
)
68 if ((int) sig
>= TARGET_SIGNAL_FIRST
&& (int) sig
<= TARGET_SIGNAL_LAST
)
69 return signals
[sig
].string
;
71 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
74 /* Return the name for a signal. */
76 target_signal_to_name (enum target_signal sig
)
78 if ((int) sig
>= TARGET_SIGNAL_FIRST
&& (int) sig
<= TARGET_SIGNAL_LAST
79 && signals
[sig
].name
!= NULL
)
80 return signals
[sig
].name
;
82 /* I think the code which prints this will always print it along
83 with the string, so no need to be verbose (very old comment). */
87 /* Given a name, return its signal. */
89 target_signal_from_name (const char *name
)
91 enum target_signal sig
;
93 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
94 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
95 questionable; seems like by now people should call it SIGABRT
98 /* This ugly cast brought to you by the native VAX compiler. */
99 for (sig
= TARGET_SIGNAL_HUP
;
100 sig
< TARGET_SIGNAL_LAST
;
101 sig
= (enum target_signal
) ((int) sig
+ 1))
102 if (signals
[sig
].name
!= NULL
103 && strcmp (name
, signals
[sig
].name
) == 0)
105 return TARGET_SIGNAL_UNKNOWN
;
108 /* The following functions are to help certain targets deal
109 with the signal/waitstatus stuff. They could just as well be in
110 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
112 /* Convert host signal to our signals. */
114 target_signal_from_host (int hostsig
)
116 /* A switch statement would make sense but would require special kludges
117 to deal with the cases where more than one signal has the same number. */
120 return TARGET_SIGNAL_0
;
123 if (hostsig
== SIGHUP
)
124 return TARGET_SIGNAL_HUP
;
127 if (hostsig
== SIGINT
)
128 return TARGET_SIGNAL_INT
;
130 #if defined (SIGQUIT)
131 if (hostsig
== SIGQUIT
)
132 return TARGET_SIGNAL_QUIT
;
135 if (hostsig
== SIGILL
)
136 return TARGET_SIGNAL_ILL
;
138 #if defined (SIGTRAP)
139 if (hostsig
== SIGTRAP
)
140 return TARGET_SIGNAL_TRAP
;
142 #if defined (SIGABRT)
143 if (hostsig
== SIGABRT
)
144 return TARGET_SIGNAL_ABRT
;
147 if (hostsig
== SIGEMT
)
148 return TARGET_SIGNAL_EMT
;
151 if (hostsig
== SIGFPE
)
152 return TARGET_SIGNAL_FPE
;
154 #if defined (SIGKILL)
155 if (hostsig
== SIGKILL
)
156 return TARGET_SIGNAL_KILL
;
159 if (hostsig
== SIGBUS
)
160 return TARGET_SIGNAL_BUS
;
162 #if defined (SIGSEGV)
163 if (hostsig
== SIGSEGV
)
164 return TARGET_SIGNAL_SEGV
;
167 if (hostsig
== SIGSYS
)
168 return TARGET_SIGNAL_SYS
;
170 #if defined (SIGPIPE)
171 if (hostsig
== SIGPIPE
)
172 return TARGET_SIGNAL_PIPE
;
174 #if defined (SIGALRM)
175 if (hostsig
== SIGALRM
)
176 return TARGET_SIGNAL_ALRM
;
178 #if defined (SIGTERM)
179 if (hostsig
== SIGTERM
)
180 return TARGET_SIGNAL_TERM
;
182 #if defined (SIGUSR1)
183 if (hostsig
== SIGUSR1
)
184 return TARGET_SIGNAL_USR1
;
186 #if defined (SIGUSR2)
187 if (hostsig
== SIGUSR2
)
188 return TARGET_SIGNAL_USR2
;
191 if (hostsig
== SIGCLD
)
192 return TARGET_SIGNAL_CHLD
;
194 #if defined (SIGCHLD)
195 if (hostsig
== SIGCHLD
)
196 return TARGET_SIGNAL_CHLD
;
199 if (hostsig
== SIGPWR
)
200 return TARGET_SIGNAL_PWR
;
202 #if defined (SIGWINCH)
203 if (hostsig
== SIGWINCH
)
204 return TARGET_SIGNAL_WINCH
;
207 if (hostsig
== SIGURG
)
208 return TARGET_SIGNAL_URG
;
211 if (hostsig
== SIGIO
)
212 return TARGET_SIGNAL_IO
;
214 #if defined (SIGPOLL)
215 if (hostsig
== SIGPOLL
)
216 return TARGET_SIGNAL_POLL
;
218 #if defined (SIGSTOP)
219 if (hostsig
== SIGSTOP
)
220 return TARGET_SIGNAL_STOP
;
222 #if defined (SIGTSTP)
223 if (hostsig
== SIGTSTP
)
224 return TARGET_SIGNAL_TSTP
;
226 #if defined (SIGCONT)
227 if (hostsig
== SIGCONT
)
228 return TARGET_SIGNAL_CONT
;
230 #if defined (SIGTTIN)
231 if (hostsig
== SIGTTIN
)
232 return TARGET_SIGNAL_TTIN
;
234 #if defined (SIGTTOU)
235 if (hostsig
== SIGTTOU
)
236 return TARGET_SIGNAL_TTOU
;
238 #if defined (SIGVTALRM)
239 if (hostsig
== SIGVTALRM
)
240 return TARGET_SIGNAL_VTALRM
;
242 #if defined (SIGPROF)
243 if (hostsig
== SIGPROF
)
244 return TARGET_SIGNAL_PROF
;
246 #if defined (SIGXCPU)
247 if (hostsig
== SIGXCPU
)
248 return TARGET_SIGNAL_XCPU
;
250 #if defined (SIGXFSZ)
251 if (hostsig
== SIGXFSZ
)
252 return TARGET_SIGNAL_XFSZ
;
254 #if defined (SIGWIND)
255 if (hostsig
== SIGWIND
)
256 return TARGET_SIGNAL_WIND
;
258 #if defined (SIGPHONE)
259 if (hostsig
== SIGPHONE
)
260 return TARGET_SIGNAL_PHONE
;
262 #if defined (SIGLOST)
263 if (hostsig
== SIGLOST
)
264 return TARGET_SIGNAL_LOST
;
266 #if defined (SIGWAITING)
267 if (hostsig
== SIGWAITING
)
268 return TARGET_SIGNAL_WAITING
;
270 #if defined (SIGCANCEL)
271 if (hostsig
== SIGCANCEL
)
272 return TARGET_SIGNAL_CANCEL
;
275 if (hostsig
== SIGLWP
)
276 return TARGET_SIGNAL_LWP
;
278 #if defined (SIGDANGER)
279 if (hostsig
== SIGDANGER
)
280 return TARGET_SIGNAL_DANGER
;
282 #if defined (SIGGRANT)
283 if (hostsig
== SIGGRANT
)
284 return TARGET_SIGNAL_GRANT
;
286 #if defined (SIGRETRACT)
287 if (hostsig
== SIGRETRACT
)
288 return TARGET_SIGNAL_RETRACT
;
291 if (hostsig
== SIGMSG
)
292 return TARGET_SIGNAL_MSG
;
294 #if defined (SIGSOUND)
295 if (hostsig
== SIGSOUND
)
296 return TARGET_SIGNAL_SOUND
;
299 if (hostsig
== SIGSAK
)
300 return TARGET_SIGNAL_SAK
;
302 #if defined (SIGPRIO)
303 if (hostsig
== SIGPRIO
)
304 return TARGET_SIGNAL_PRIO
;
307 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
308 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
309 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
310 return TARGET_EXC_BAD_ACCESS
;
312 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
313 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
314 return TARGET_EXC_BAD_INSTRUCTION
;
316 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
317 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
318 return TARGET_EXC_ARITHMETIC
;
320 #if defined (EXC_EMULATION) && defined (_NSIG)
321 if (hostsig
== _NSIG
+ EXC_EMULATION
)
322 return TARGET_EXC_EMULATION
;
324 #if defined (EXC_SOFTWARE) && defined (_NSIG)
325 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
326 return TARGET_EXC_SOFTWARE
;
328 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
329 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
330 return TARGET_EXC_BREAKPOINT
;
333 #if defined (SIGINFO)
334 if (hostsig
== SIGINFO
)
335 return TARGET_SIGNAL_INFO
;
338 #if defined (REALTIME_LO)
339 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
341 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
342 if (33 <= hostsig
&& hostsig
<= 63)
343 return (enum target_signal
)
344 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
345 else if (hostsig
== 32)
346 return TARGET_SIGNAL_REALTIME_32
;
347 else if (64 <= hostsig
&& hostsig
<= 127)
348 return (enum target_signal
)
349 (hostsig
- 64 + (int) TARGET_SIGNAL_REALTIME_64
);
351 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
355 return TARGET_SIGNAL_UNKNOWN
;
358 /* Convert a OURSIG (an enum target_signal) to the form used by the
359 target operating system (refered to as the ``host'') or zero if the
360 equivalent host signal is not available. Set/clear OURSIG_OK
364 do_target_signal_to_host (enum target_signal oursig
,
368 /* Silence the 'not used' warning, for targets that
369 do not support signals. */
375 case TARGET_SIGNAL_0
:
379 case TARGET_SIGNAL_HUP
:
383 case TARGET_SIGNAL_INT
:
386 #if defined (SIGQUIT)
387 case TARGET_SIGNAL_QUIT
:
391 case TARGET_SIGNAL_ILL
:
394 #if defined (SIGTRAP)
395 case TARGET_SIGNAL_TRAP
:
398 #if defined (SIGABRT)
399 case TARGET_SIGNAL_ABRT
:
403 case TARGET_SIGNAL_EMT
:
407 case TARGET_SIGNAL_FPE
:
410 #if defined (SIGKILL)
411 case TARGET_SIGNAL_KILL
:
415 case TARGET_SIGNAL_BUS
:
418 #if defined (SIGSEGV)
419 case TARGET_SIGNAL_SEGV
:
423 case TARGET_SIGNAL_SYS
:
426 #if defined (SIGPIPE)
427 case TARGET_SIGNAL_PIPE
:
430 #if defined (SIGALRM)
431 case TARGET_SIGNAL_ALRM
:
434 #if defined (SIGTERM)
435 case TARGET_SIGNAL_TERM
:
438 #if defined (SIGUSR1)
439 case TARGET_SIGNAL_USR1
:
442 #if defined (SIGUSR2)
443 case TARGET_SIGNAL_USR2
:
446 #if defined (SIGCHLD) || defined (SIGCLD)
447 case TARGET_SIGNAL_CHLD
:
448 #if defined (SIGCHLD)
453 #endif /* SIGCLD or SIGCHLD */
455 case TARGET_SIGNAL_PWR
:
458 #if defined (SIGWINCH)
459 case TARGET_SIGNAL_WINCH
:
463 case TARGET_SIGNAL_URG
:
467 case TARGET_SIGNAL_IO
:
470 #if defined (SIGPOLL)
471 case TARGET_SIGNAL_POLL
:
474 #if defined (SIGSTOP)
475 case TARGET_SIGNAL_STOP
:
478 #if defined (SIGTSTP)
479 case TARGET_SIGNAL_TSTP
:
482 #if defined (SIGCONT)
483 case TARGET_SIGNAL_CONT
:
486 #if defined (SIGTTIN)
487 case TARGET_SIGNAL_TTIN
:
490 #if defined (SIGTTOU)
491 case TARGET_SIGNAL_TTOU
:
494 #if defined (SIGVTALRM)
495 case TARGET_SIGNAL_VTALRM
:
498 #if defined (SIGPROF)
499 case TARGET_SIGNAL_PROF
:
502 #if defined (SIGXCPU)
503 case TARGET_SIGNAL_XCPU
:
506 #if defined (SIGXFSZ)
507 case TARGET_SIGNAL_XFSZ
:
510 #if defined (SIGWIND)
511 case TARGET_SIGNAL_WIND
:
514 #if defined (SIGPHONE)
515 case TARGET_SIGNAL_PHONE
:
518 #if defined (SIGLOST)
519 case TARGET_SIGNAL_LOST
:
522 #if defined (SIGWAITING)
523 case TARGET_SIGNAL_WAITING
:
526 #if defined (SIGCANCEL)
527 case TARGET_SIGNAL_CANCEL
:
531 case TARGET_SIGNAL_LWP
:
534 #if defined (SIGDANGER)
535 case TARGET_SIGNAL_DANGER
:
538 #if defined (SIGGRANT)
539 case TARGET_SIGNAL_GRANT
:
542 #if defined (SIGRETRACT)
543 case TARGET_SIGNAL_RETRACT
:
547 case TARGET_SIGNAL_MSG
:
550 #if defined (SIGSOUND)
551 case TARGET_SIGNAL_SOUND
:
555 case TARGET_SIGNAL_SAK
:
558 #if defined (SIGPRIO)
559 case TARGET_SIGNAL_PRIO
:
563 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
564 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
565 case TARGET_EXC_BAD_ACCESS
:
566 return _NSIG
+ EXC_BAD_ACCESS
;
568 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
569 case TARGET_EXC_BAD_INSTRUCTION
:
570 return _NSIG
+ EXC_BAD_INSTRUCTION
;
572 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
573 case TARGET_EXC_ARITHMETIC
:
574 return _NSIG
+ EXC_ARITHMETIC
;
576 #if defined (EXC_EMULATION) && defined (_NSIG)
577 case TARGET_EXC_EMULATION
:
578 return _NSIG
+ EXC_EMULATION
;
580 #if defined (EXC_SOFTWARE) && defined (_NSIG)
581 case TARGET_EXC_SOFTWARE
:
582 return _NSIG
+ EXC_SOFTWARE
;
584 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
585 case TARGET_EXC_BREAKPOINT
:
586 return _NSIG
+ EXC_BREAKPOINT
;
589 #if defined (SIGINFO)
590 case TARGET_SIGNAL_INFO
:
595 #if defined (REALTIME_LO)
598 if (oursig
>= TARGET_SIGNAL_REALTIME_33
599 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
601 /* This block of signals is continuous, and
602 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
603 retsig
= (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
605 else if (oursig
== TARGET_SIGNAL_REALTIME_32
)
607 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
608 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
611 else if (oursig
>= TARGET_SIGNAL_REALTIME_64
612 && oursig
<= TARGET_SIGNAL_REALTIME_127
)
614 /* This block of signals is continuous, and
615 TARGET_SIGNAL_REALTIME_64 is 64 by definition. */
616 retsig
= (int) oursig
- (int) TARGET_SIGNAL_REALTIME_64
+ 64;
619 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
629 target_signal_to_host_p (enum target_signal oursig
)
632 do_target_signal_to_host (oursig
, &oursig_ok
);
637 target_signal_to_host (enum target_signal oursig
)
640 int targ_signo
= do_target_signal_to_host (oursig
, &oursig_ok
);
643 /* The user might be trying to do "signal SIGSAK" where this system
644 doesn't have SIGSAK. */
645 warning ("Signal %s does not exist on this system.\n",
646 target_signal_to_name (oursig
));
655 /* In some circumstances we allow a command to specify a numeric
656 signal. The idea is to keep these circumstances limited so that
657 users (and scripts) develop portable habits. For comparison,
658 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
659 numeric signal at all is obsolescent. We are slightly more
660 lenient and allow 1-15 which should match host signal numbers on
661 most systems. Use of symbolic signal names is strongly encouraged. */
664 target_signal_from_command (int num
)
666 if (num
>= 1 && num
<= 15)
667 return (enum target_signal
) num
;
668 error ("Only signals 1-15 are valid as numeric signals.\n\
669 Use \"info signals\" for a list of symbolic signals.");
672 extern initialize_file_ftype _initialize_signals
; /* -Wmissing-prototype */
675 _initialize_signals (void)
677 if (strcmp (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC") != 0)
678 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
682 default_target_signal_to_host (struct gdbarch
*gdbarch
, enum target_signal ts
)
684 return target_signal_to_host (ts
);
688 default_target_signal_from_host (struct gdbarch
*gdbarch
, int signo
)
690 return target_signal_from_host (signo
);
693 #endif /* ! GDBSERVER */