1 /* Target signal translation functions for GDB.
2 Copyright (C) 1990-2014 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/>. */
31 #include "gdb_signals.h"
32 #include "gdb_assert.h"
36 /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest
37 _available_ realtime signal, not the lowest supported; glibc takes
38 several for its own use. */
41 # if defined(__SIGRTMIN)
42 # define REALTIME_LO __SIGRTMIN
43 # define REALTIME_HI (__SIGRTMAX + 1)
44 # elif defined(SIGRTMIN)
45 # define REALTIME_LO SIGRTMIN
46 # define REALTIME_HI (SIGRTMAX + 1)
50 /* This table must match in order and size the signals in enum
59 #define SET(symbol, constant, name, string) { #symbol, name, string },
60 #include "gdb/signals.def"
65 gdb_signal_to_symbol_string (enum gdb_signal sig
)
67 gdb_assert ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
);
69 return signals
[sig
].symbol
;
72 /* Return the string for a signal. */
74 gdb_signal_to_string (enum gdb_signal sig
)
76 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
)
77 return signals
[sig
].string
;
79 return signals
[GDB_SIGNAL_UNKNOWN
].string
;
82 /* Return the name for a signal. */
84 gdb_signal_to_name (enum gdb_signal sig
)
86 if ((int) sig
>= GDB_SIGNAL_FIRST
&& (int) sig
<= GDB_SIGNAL_LAST
87 && signals
[sig
].name
!= NULL
)
88 return signals
[sig
].name
;
90 /* I think the code which prints this will always print it along
91 with the string, so no need to be verbose (very old comment). */
95 /* Given a name, return its signal. */
97 gdb_signal_from_name (const char *name
)
101 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
102 for GDB_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
103 questionable; seems like by now people should call it SIGABRT
106 /* This ugly cast brought to you by the native VAX compiler. */
107 for (sig
= GDB_SIGNAL_HUP
;
108 sig
< GDB_SIGNAL_LAST
;
109 sig
= (enum gdb_signal
) ((int) sig
+ 1))
110 if (signals
[sig
].name
!= NULL
111 && strcmp (name
, signals
[sig
].name
) == 0)
113 return GDB_SIGNAL_UNKNOWN
;
116 /* The following functions are to help certain targets deal
117 with the signal/waitstatus stuff. They could just as well be in
118 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
120 /* Convert host signal to our signals. */
122 gdb_signal_from_host (int hostsig
)
124 /* A switch statement would make sense but would require special kludges
125 to deal with the cases where more than one signal has the same number. */
131 if (hostsig
== SIGHUP
)
132 return GDB_SIGNAL_HUP
;
135 if (hostsig
== SIGINT
)
136 return GDB_SIGNAL_INT
;
138 #if defined (SIGQUIT)
139 if (hostsig
== SIGQUIT
)
140 return GDB_SIGNAL_QUIT
;
143 if (hostsig
== SIGILL
)
144 return GDB_SIGNAL_ILL
;
146 #if defined (SIGTRAP)
147 if (hostsig
== SIGTRAP
)
148 return GDB_SIGNAL_TRAP
;
150 #if defined (SIGABRT)
151 if (hostsig
== SIGABRT
)
152 return GDB_SIGNAL_ABRT
;
155 if (hostsig
== SIGEMT
)
156 return GDB_SIGNAL_EMT
;
159 if (hostsig
== SIGFPE
)
160 return GDB_SIGNAL_FPE
;
162 #if defined (SIGKILL)
163 if (hostsig
== SIGKILL
)
164 return GDB_SIGNAL_KILL
;
167 if (hostsig
== SIGBUS
)
168 return GDB_SIGNAL_BUS
;
170 #if defined (SIGSEGV)
171 if (hostsig
== SIGSEGV
)
172 return GDB_SIGNAL_SEGV
;
175 if (hostsig
== SIGSYS
)
176 return GDB_SIGNAL_SYS
;
178 #if defined (SIGPIPE)
179 if (hostsig
== SIGPIPE
)
180 return GDB_SIGNAL_PIPE
;
182 #if defined (SIGALRM)
183 if (hostsig
== SIGALRM
)
184 return GDB_SIGNAL_ALRM
;
186 #if defined (SIGTERM)
187 if (hostsig
== SIGTERM
)
188 return GDB_SIGNAL_TERM
;
190 #if defined (SIGUSR1)
191 if (hostsig
== SIGUSR1
)
192 return GDB_SIGNAL_USR1
;
194 #if defined (SIGUSR2)
195 if (hostsig
== SIGUSR2
)
196 return GDB_SIGNAL_USR2
;
199 if (hostsig
== SIGCLD
)
200 return GDB_SIGNAL_CHLD
;
202 #if defined (SIGCHLD)
203 if (hostsig
== SIGCHLD
)
204 return GDB_SIGNAL_CHLD
;
207 if (hostsig
== SIGPWR
)
208 return GDB_SIGNAL_PWR
;
210 #if defined (SIGWINCH)
211 if (hostsig
== SIGWINCH
)
212 return GDB_SIGNAL_WINCH
;
215 if (hostsig
== SIGURG
)
216 return GDB_SIGNAL_URG
;
219 if (hostsig
== SIGIO
)
220 return GDB_SIGNAL_IO
;
222 #if defined (SIGPOLL)
223 if (hostsig
== SIGPOLL
)
224 return GDB_SIGNAL_POLL
;
226 #if defined (SIGSTOP)
227 if (hostsig
== SIGSTOP
)
228 return GDB_SIGNAL_STOP
;
230 #if defined (SIGTSTP)
231 if (hostsig
== SIGTSTP
)
232 return GDB_SIGNAL_TSTP
;
234 #if defined (SIGCONT)
235 if (hostsig
== SIGCONT
)
236 return GDB_SIGNAL_CONT
;
238 #if defined (SIGTTIN)
239 if (hostsig
== SIGTTIN
)
240 return GDB_SIGNAL_TTIN
;
242 #if defined (SIGTTOU)
243 if (hostsig
== SIGTTOU
)
244 return GDB_SIGNAL_TTOU
;
246 #if defined (SIGVTALRM)
247 if (hostsig
== SIGVTALRM
)
248 return GDB_SIGNAL_VTALRM
;
250 #if defined (SIGPROF)
251 if (hostsig
== SIGPROF
)
252 return GDB_SIGNAL_PROF
;
254 #if defined (SIGXCPU)
255 if (hostsig
== SIGXCPU
)
256 return GDB_SIGNAL_XCPU
;
258 #if defined (SIGXFSZ)
259 if (hostsig
== SIGXFSZ
)
260 return GDB_SIGNAL_XFSZ
;
262 #if defined (SIGWIND)
263 if (hostsig
== SIGWIND
)
264 return GDB_SIGNAL_WIND
;
266 #if defined (SIGPHONE)
267 if (hostsig
== SIGPHONE
)
268 return GDB_SIGNAL_PHONE
;
270 #if defined (SIGLOST)
271 if (hostsig
== SIGLOST
)
272 return GDB_SIGNAL_LOST
;
274 #if defined (SIGWAITING)
275 if (hostsig
== SIGWAITING
)
276 return GDB_SIGNAL_WAITING
;
278 #if defined (SIGCANCEL)
279 if (hostsig
== SIGCANCEL
)
280 return GDB_SIGNAL_CANCEL
;
283 if (hostsig
== SIGLWP
)
284 return GDB_SIGNAL_LWP
;
286 #if defined (SIGDANGER)
287 if (hostsig
== SIGDANGER
)
288 return GDB_SIGNAL_DANGER
;
290 #if defined (SIGGRANT)
291 if (hostsig
== SIGGRANT
)
292 return GDB_SIGNAL_GRANT
;
294 #if defined (SIGRETRACT)
295 if (hostsig
== SIGRETRACT
)
296 return GDB_SIGNAL_RETRACT
;
299 if (hostsig
== SIGMSG
)
300 return GDB_SIGNAL_MSG
;
302 #if defined (SIGSOUND)
303 if (hostsig
== SIGSOUND
)
304 return GDB_SIGNAL_SOUND
;
307 if (hostsig
== SIGSAK
)
308 return GDB_SIGNAL_SAK
;
310 #if defined (SIGPRIO)
311 if (hostsig
== SIGPRIO
)
312 return GDB_SIGNAL_PRIO
;
315 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
316 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
317 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
318 return GDB_EXC_BAD_ACCESS
;
320 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
321 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
322 return GDB_EXC_BAD_INSTRUCTION
;
324 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
325 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
326 return GDB_EXC_ARITHMETIC
;
328 #if defined (EXC_EMULATION) && defined (_NSIG)
329 if (hostsig
== _NSIG
+ EXC_EMULATION
)
330 return GDB_EXC_EMULATION
;
332 #if defined (EXC_SOFTWARE) && defined (_NSIG)
333 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
334 return GDB_EXC_SOFTWARE
;
336 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
337 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
338 return GDB_EXC_BREAKPOINT
;
341 #if defined (SIGINFO)
342 if (hostsig
== SIGINFO
)
343 return GDB_SIGNAL_INFO
;
346 #if defined (REALTIME_LO)
347 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
349 /* This block of GDB_SIGNAL_REALTIME value is in order. */
350 if (33 <= hostsig
&& hostsig
<= 63)
351 return (enum gdb_signal
)
352 (hostsig
- 33 + (int) GDB_SIGNAL_REALTIME_33
);
353 else if (hostsig
== 32)
354 return GDB_SIGNAL_REALTIME_32
;
355 else if (64 <= hostsig
&& hostsig
<= 127)
356 return (enum gdb_signal
)
357 (hostsig
- 64 + (int) GDB_SIGNAL_REALTIME_64
);
359 error (_("GDB bug: target.c (gdb_signal_from_host): "
360 "unrecognized real-time signal"));
364 return GDB_SIGNAL_UNKNOWN
;
367 /* Convert a OURSIG (an enum gdb_signal) to the form used by the
368 target operating system (refered to as the ``host'') or zero if the
369 equivalent host signal is not available. Set/clear OURSIG_OK
373 do_gdb_signal_to_host (enum gdb_signal oursig
,
377 /* Silence the 'not used' warning, for targets that
378 do not support signals. */
395 #if defined (SIGQUIT)
396 case GDB_SIGNAL_QUIT
:
403 #if defined (SIGTRAP)
404 case GDB_SIGNAL_TRAP
:
407 #if defined (SIGABRT)
408 case GDB_SIGNAL_ABRT
:
419 #if defined (SIGKILL)
420 case GDB_SIGNAL_KILL
:
427 #if defined (SIGSEGV)
428 case GDB_SIGNAL_SEGV
:
435 #if defined (SIGPIPE)
436 case GDB_SIGNAL_PIPE
:
439 #if defined (SIGALRM)
440 case GDB_SIGNAL_ALRM
:
443 #if defined (SIGTERM)
444 case GDB_SIGNAL_TERM
:
447 #if defined (SIGUSR1)
448 case GDB_SIGNAL_USR1
:
451 #if defined (SIGUSR2)
452 case GDB_SIGNAL_USR2
:
455 #if defined (SIGCHLD) || defined (SIGCLD)
456 case GDB_SIGNAL_CHLD
:
457 #if defined (SIGCHLD)
462 #endif /* SIGCLD or SIGCHLD */
467 #if defined (SIGWINCH)
468 case GDB_SIGNAL_WINCH
:
479 #if defined (SIGPOLL)
480 case GDB_SIGNAL_POLL
:
483 #if defined (SIGSTOP)
484 case GDB_SIGNAL_STOP
:
487 #if defined (SIGTSTP)
488 case GDB_SIGNAL_TSTP
:
491 #if defined (SIGCONT)
492 case GDB_SIGNAL_CONT
:
495 #if defined (SIGTTIN)
496 case GDB_SIGNAL_TTIN
:
499 #if defined (SIGTTOU)
500 case GDB_SIGNAL_TTOU
:
503 #if defined (SIGVTALRM)
504 case GDB_SIGNAL_VTALRM
:
507 #if defined (SIGPROF)
508 case GDB_SIGNAL_PROF
:
511 #if defined (SIGXCPU)
512 case GDB_SIGNAL_XCPU
:
515 #if defined (SIGXFSZ)
516 case GDB_SIGNAL_XFSZ
:
519 #if defined (SIGWIND)
520 case GDB_SIGNAL_WIND
:
523 #if defined (SIGPHONE)
524 case GDB_SIGNAL_PHONE
:
527 #if defined (SIGLOST)
528 case GDB_SIGNAL_LOST
:
531 #if defined (SIGWAITING)
532 case GDB_SIGNAL_WAITING
:
535 #if defined (SIGCANCEL)
536 case GDB_SIGNAL_CANCEL
:
543 #if defined (SIGDANGER)
544 case GDB_SIGNAL_DANGER
:
547 #if defined (SIGGRANT)
548 case GDB_SIGNAL_GRANT
:
551 #if defined (SIGRETRACT)
552 case GDB_SIGNAL_RETRACT
:
559 #if defined (SIGSOUND)
560 case GDB_SIGNAL_SOUND
:
567 #if defined (SIGPRIO)
568 case GDB_SIGNAL_PRIO
:
572 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
573 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
574 case GDB_EXC_BAD_ACCESS
:
575 return _NSIG
+ EXC_BAD_ACCESS
;
577 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
578 case GDB_EXC_BAD_INSTRUCTION
:
579 return _NSIG
+ EXC_BAD_INSTRUCTION
;
581 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
582 case GDB_EXC_ARITHMETIC
:
583 return _NSIG
+ EXC_ARITHMETIC
;
585 #if defined (EXC_EMULATION) && defined (_NSIG)
586 case GDB_EXC_EMULATION
:
587 return _NSIG
+ EXC_EMULATION
;
589 #if defined (EXC_SOFTWARE) && defined (_NSIG)
590 case GDB_EXC_SOFTWARE
:
591 return _NSIG
+ EXC_SOFTWARE
;
593 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
594 case GDB_EXC_BREAKPOINT
:
595 return _NSIG
+ EXC_BREAKPOINT
;
598 #if defined (SIGINFO)
599 case GDB_SIGNAL_INFO
:
604 #if defined (REALTIME_LO)
607 if (oursig
>= GDB_SIGNAL_REALTIME_33
608 && oursig
<= GDB_SIGNAL_REALTIME_63
)
610 /* This block of signals is continuous, and
611 GDB_SIGNAL_REALTIME_33 is 33 by definition. */
612 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_33
+ 33;
614 else if (oursig
== GDB_SIGNAL_REALTIME_32
)
616 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
617 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */
620 else if (oursig
>= GDB_SIGNAL_REALTIME_64
621 && oursig
<= GDB_SIGNAL_REALTIME_127
)
623 /* This block of signals is continuous, and
624 GDB_SIGNAL_REALTIME_64 is 64 by definition. */
625 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_64
+ 64;
628 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
638 gdb_signal_to_host_p (enum gdb_signal oursig
)
641 do_gdb_signal_to_host (oursig
, &oursig_ok
);
646 gdb_signal_to_host (enum gdb_signal oursig
)
649 int targ_signo
= do_gdb_signal_to_host (oursig
, &oursig_ok
);
652 /* The user might be trying to do "signal SIGSAK" where this system
653 doesn't have SIGSAK. */
654 warning (_("Signal %s does not exist on this system."),
655 gdb_signal_to_name (oursig
));
This page took 0.047425 seconds and 4 git commands to generate.