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
;
134 if (hostsig
== SIGINT
)
135 return GDB_SIGNAL_INT
;
136 #if defined (SIGQUIT)
137 if (hostsig
== SIGQUIT
)
138 return GDB_SIGNAL_QUIT
;
140 if (hostsig
== SIGILL
)
141 return GDB_SIGNAL_ILL
;
142 #if defined (SIGTRAP)
143 if (hostsig
== SIGTRAP
)
144 return GDB_SIGNAL_TRAP
;
146 if (hostsig
== SIGABRT
)
147 return GDB_SIGNAL_ABRT
;
149 if (hostsig
== SIGEMT
)
150 return GDB_SIGNAL_EMT
;
152 if (hostsig
== SIGFPE
)
153 return GDB_SIGNAL_FPE
;
154 #if defined (SIGKILL)
155 if (hostsig
== SIGKILL
)
156 return GDB_SIGNAL_KILL
;
159 if (hostsig
== SIGBUS
)
160 return GDB_SIGNAL_BUS
;
162 if (hostsig
== SIGSEGV
)
163 return GDB_SIGNAL_SEGV
;
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 (hostsig
== SIGTERM
)
177 return GDB_SIGNAL_TERM
;
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
;
334 #if defined (REALTIME_LO)
335 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
337 /* This block of GDB_SIGNAL_REALTIME value is in order. */
338 if (33 <= hostsig
&& hostsig
<= 63)
339 return (enum gdb_signal
)
340 (hostsig
- 33 + (int) GDB_SIGNAL_REALTIME_33
);
341 else if (hostsig
== 32)
342 return GDB_SIGNAL_REALTIME_32
;
343 else if (64 <= hostsig
&& hostsig
<= 127)
344 return (enum gdb_signal
)
345 (hostsig
- 64 + (int) GDB_SIGNAL_REALTIME_64
);
347 error (_("GDB bug: target.c (gdb_signal_from_host): "
348 "unrecognized real-time signal"));
352 return GDB_SIGNAL_UNKNOWN
;
355 /* Convert a OURSIG (an enum gdb_signal) to the form used by the
356 target operating system (refered to as the ``host'') or zero if the
357 equivalent host signal is not available. Set/clear OURSIG_OK
361 do_gdb_signal_to_host (enum gdb_signal oursig
,
365 /* Silence the 'not used' warning, for targets that
366 do not support signals. */
381 #if defined (SIGQUIT)
382 case GDB_SIGNAL_QUIT
:
387 #if defined (SIGTRAP)
388 case GDB_SIGNAL_TRAP
:
391 case GDB_SIGNAL_ABRT
:
399 #if defined (SIGKILL)
400 case GDB_SIGNAL_KILL
:
407 case GDB_SIGNAL_SEGV
:
413 #if defined (SIGPIPE)
414 case GDB_SIGNAL_PIPE
:
417 #if defined (SIGALRM)
418 case GDB_SIGNAL_ALRM
:
421 case GDB_SIGNAL_TERM
:
423 #if defined (SIGUSR1)
424 case GDB_SIGNAL_USR1
:
427 #if defined (SIGUSR2)
428 case GDB_SIGNAL_USR2
:
431 #if defined (SIGCHLD) || defined (SIGCLD)
432 case GDB_SIGNAL_CHLD
:
433 #if defined (SIGCHLD)
438 #endif /* SIGCLD or SIGCHLD */
443 #if defined (SIGWINCH)
444 case GDB_SIGNAL_WINCH
:
455 #if defined (SIGPOLL)
456 case GDB_SIGNAL_POLL
:
459 #if defined (SIGSTOP)
460 case GDB_SIGNAL_STOP
:
463 #if defined (SIGTSTP)
464 case GDB_SIGNAL_TSTP
:
467 #if defined (SIGCONT)
468 case GDB_SIGNAL_CONT
:
471 #if defined (SIGTTIN)
472 case GDB_SIGNAL_TTIN
:
475 #if defined (SIGTTOU)
476 case GDB_SIGNAL_TTOU
:
479 #if defined (SIGVTALRM)
480 case GDB_SIGNAL_VTALRM
:
483 #if defined (SIGPROF)
484 case GDB_SIGNAL_PROF
:
487 #if defined (SIGXCPU)
488 case GDB_SIGNAL_XCPU
:
491 #if defined (SIGXFSZ)
492 case GDB_SIGNAL_XFSZ
:
495 #if defined (SIGWIND)
496 case GDB_SIGNAL_WIND
:
499 #if defined (SIGPHONE)
500 case GDB_SIGNAL_PHONE
:
503 #if defined (SIGLOST)
504 case GDB_SIGNAL_LOST
:
507 #if defined (SIGWAITING)
508 case GDB_SIGNAL_WAITING
:
511 #if defined (SIGCANCEL)
512 case GDB_SIGNAL_CANCEL
:
519 #if defined (SIGDANGER)
520 case GDB_SIGNAL_DANGER
:
523 #if defined (SIGGRANT)
524 case GDB_SIGNAL_GRANT
:
527 #if defined (SIGRETRACT)
528 case GDB_SIGNAL_RETRACT
:
535 #if defined (SIGSOUND)
536 case GDB_SIGNAL_SOUND
:
543 #if defined (SIGPRIO)
544 case GDB_SIGNAL_PRIO
:
548 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
549 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
550 case GDB_EXC_BAD_ACCESS
:
551 return _NSIG
+ EXC_BAD_ACCESS
;
553 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
554 case GDB_EXC_BAD_INSTRUCTION
:
555 return _NSIG
+ EXC_BAD_INSTRUCTION
;
557 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
558 case GDB_EXC_ARITHMETIC
:
559 return _NSIG
+ EXC_ARITHMETIC
;
561 #if defined (EXC_EMULATION) && defined (_NSIG)
562 case GDB_EXC_EMULATION
:
563 return _NSIG
+ EXC_EMULATION
;
565 #if defined (EXC_SOFTWARE) && defined (_NSIG)
566 case GDB_EXC_SOFTWARE
:
567 return _NSIG
+ EXC_SOFTWARE
;
569 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
570 case GDB_EXC_BREAKPOINT
:
571 return _NSIG
+ EXC_BREAKPOINT
;
574 #if defined (SIGINFO)
575 case GDB_SIGNAL_INFO
:
580 #if defined (REALTIME_LO)
583 if (oursig
>= GDB_SIGNAL_REALTIME_33
584 && oursig
<= GDB_SIGNAL_REALTIME_63
)
586 /* This block of signals is continuous, and
587 GDB_SIGNAL_REALTIME_33 is 33 by definition. */
588 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_33
+ 33;
590 else if (oursig
== GDB_SIGNAL_REALTIME_32
)
592 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
593 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */
596 else if (oursig
>= GDB_SIGNAL_REALTIME_64
597 && oursig
<= GDB_SIGNAL_REALTIME_127
)
599 /* This block of signals is continuous, and
600 GDB_SIGNAL_REALTIME_64 is 64 by definition. */
601 retsig
= (int) oursig
- (int) GDB_SIGNAL_REALTIME_64
+ 64;
604 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
614 gdb_signal_to_host_p (enum gdb_signal oursig
)
617 do_gdb_signal_to_host (oursig
, &oursig_ok
);
622 gdb_signal_to_host (enum gdb_signal oursig
)
625 int targ_signo
= do_gdb_signal_to_host (oursig
, &oursig_ok
);
628 /* The user might be trying to do "signal SIGSAK" where this system
629 doesn't have SIGSAK. */
630 warning (_("Signal %s does not exist on this system."),
631 gdb_signal_to_name (oursig
));
This page took 0.041757 seconds and 5 git commands to generate.