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
125 kludges to deal with the cases where more than one signal has the
126 same number. Signals are ordered ANSI-standard signals first,
127 other signals second, with signals in each block ordered by their
128 numerical values on a typical POSIX platform. */
133 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
134 are ANSI-standard signals and are always available. */
135 if (hostsig == SIGINT)
136 return GDB_SIGNAL_INT;
137 if (hostsig == SIGILL)
138 return GDB_SIGNAL_ILL;
139 if (hostsig == SIGABRT)
140 return GDB_SIGNAL_ABRT;
141 if (hostsig == SIGFPE)
142 return GDB_SIGNAL_FPE;
143 if (hostsig == SIGSEGV)
144 return GDB_SIGNAL_SEGV;
145 if (hostsig == SIGTERM)
146 return GDB_SIGNAL_TERM;
148 /* All other signals need preprocessor conditionals. */
150 if (hostsig == SIGHUP)
151 return GDB_SIGNAL_HUP;
153 #if defined (SIGQUIT)
154 if (hostsig == SIGQUIT)
155 return GDB_SIGNAL_QUIT;
157 #if defined (SIGTRAP)
158 if (hostsig == SIGTRAP)
159 return GDB_SIGNAL_TRAP;
162 if (hostsig == SIGEMT)
163 return GDB_SIGNAL_EMT;
165 #if defined (SIGKILL)
166 if (hostsig == SIGKILL)
167 return GDB_SIGNAL_KILL;
170 if (hostsig == SIGBUS)
171 return GDB_SIGNAL_BUS;
174 if (hostsig == SIGSYS)
175 return GDB_SIGNAL_SYS;
177 #if defined (SIGPIPE)
178 if (hostsig == SIGPIPE)
179 return GDB_SIGNAL_PIPE;
181 #if defined (SIGALRM)
182 if (hostsig == SIGALRM)
183 return GDB_SIGNAL_ALRM;
185 #if defined (SIGUSR1)
186 if (hostsig == SIGUSR1)
187 return GDB_SIGNAL_USR1;
189 #if defined (SIGUSR2)
190 if (hostsig == SIGUSR2)
191 return GDB_SIGNAL_USR2;
194 if (hostsig == SIGCLD)
195 return GDB_SIGNAL_CHLD;
197 #if defined (SIGCHLD)
198 if (hostsig == SIGCHLD)
199 return GDB_SIGNAL_CHLD;
202 if (hostsig == SIGPWR)
203 return GDB_SIGNAL_PWR;
205 #if defined (SIGWINCH)
206 if (hostsig == SIGWINCH)
207 return GDB_SIGNAL_WINCH;
210 if (hostsig == SIGURG)
211 return GDB_SIGNAL_URG;
214 if (hostsig == SIGIO)
215 return GDB_SIGNAL_IO;
217 #if defined (SIGPOLL)
218 if (hostsig == SIGPOLL)
219 return GDB_SIGNAL_POLL;
221 #if defined (SIGSTOP)
222 if (hostsig == SIGSTOP)
223 return GDB_SIGNAL_STOP;
225 #if defined (SIGTSTP)
226 if (hostsig == SIGTSTP)
227 return GDB_SIGNAL_TSTP;
229 #if defined (SIGCONT)
230 if (hostsig == SIGCONT)
231 return GDB_SIGNAL_CONT;
233 #if defined (SIGTTIN)
234 if (hostsig == SIGTTIN)
235 return GDB_SIGNAL_TTIN;
237 #if defined (SIGTTOU)
238 if (hostsig == SIGTTOU)
239 return GDB_SIGNAL_TTOU;
241 #if defined (SIGVTALRM)
242 if (hostsig == SIGVTALRM)
243 return GDB_SIGNAL_VTALRM;
245 #if defined (SIGPROF)
246 if (hostsig == SIGPROF)
247 return GDB_SIGNAL_PROF;
249 #if defined (SIGXCPU)
250 if (hostsig == SIGXCPU)
251 return GDB_SIGNAL_XCPU;
253 #if defined (SIGXFSZ)
254 if (hostsig == SIGXFSZ)
255 return GDB_SIGNAL_XFSZ;
257 #if defined (SIGWIND)
258 if (hostsig == SIGWIND)
259 return GDB_SIGNAL_WIND;
261 #if defined (SIGPHONE)
262 if (hostsig == SIGPHONE)
263 return GDB_SIGNAL_PHONE;
265 #if defined (SIGLOST)
266 if (hostsig == SIGLOST)
267 return GDB_SIGNAL_LOST;
269 #if defined (SIGWAITING)
270 if (hostsig == SIGWAITING)
271 return GDB_SIGNAL_WAITING;
273 #if defined (SIGCANCEL)
274 if (hostsig == SIGCANCEL)
275 return GDB_SIGNAL_CANCEL;
278 if (hostsig == SIGLWP)
279 return GDB_SIGNAL_LWP;
281 #if defined (SIGDANGER)
282 if (hostsig == SIGDANGER)
283 return GDB_SIGNAL_DANGER;
285 #if defined (SIGGRANT)
286 if (hostsig == SIGGRANT)
287 return GDB_SIGNAL_GRANT;
289 #if defined (SIGRETRACT)
290 if (hostsig == SIGRETRACT)
291 return GDB_SIGNAL_RETRACT;
294 if (hostsig == SIGMSG)
295 return GDB_SIGNAL_MSG;
297 #if defined (SIGSOUND)
298 if (hostsig == SIGSOUND)
299 return GDB_SIGNAL_SOUND;
302 if (hostsig == SIGSAK)
303 return GDB_SIGNAL_SAK;
305 #if defined (SIGPRIO)
306 if (hostsig == SIGPRIO)
307 return GDB_SIGNAL_PRIO;
310 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
311 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
312 if (hostsig == _NSIG + EXC_BAD_ACCESS)
313 return GDB_EXC_BAD_ACCESS;
315 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
316 if (hostsig == _NSIG + EXC_BAD_INSTRUCTION)
317 return GDB_EXC_BAD_INSTRUCTION;
319 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
320 if (hostsig == _NSIG + EXC_ARITHMETIC)
321 return GDB_EXC_ARITHMETIC;
323 #if defined (EXC_EMULATION) && defined (_NSIG)
324 if (hostsig == _NSIG + EXC_EMULATION)
325 return GDB_EXC_EMULATION;
327 #if defined (EXC_SOFTWARE) && defined (_NSIG)
328 if (hostsig == _NSIG + EXC_SOFTWARE)
329 return GDB_EXC_SOFTWARE;
331 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
332 if (hostsig == _NSIG + EXC_BREAKPOINT)
333 return GDB_EXC_BREAKPOINT;
336 #if defined (SIGINFO)
337 if (hostsig == SIGINFO)
338 return GDB_SIGNAL_INFO;
341 #if defined (REALTIME_LO)
342 if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
344 /* This block of GDB_SIGNAL_REALTIME value is in order. */
345 if (33 <= hostsig && hostsig <= 63)
346 return (enum gdb_signal)
347 (hostsig - 33 + (int) GDB_SIGNAL_REALTIME_33);
348 else if (hostsig == 32)
349 return GDB_SIGNAL_REALTIME_32;
350 else if (64 <= hostsig && hostsig <= 127)
351 return (enum gdb_signal)
352 (hostsig - 64 + (int) GDB_SIGNAL_REALTIME_64);
354 error (_("GDB bug: target.c (gdb_signal_from_host): "
355 "unrecognized real-time signal"));
359 return GDB_SIGNAL_UNKNOWN;
362 /* Convert a OURSIG (an enum gdb_signal) to the form used by the
363 target operating system (refered to as the ``host'') or zero if the
364 equivalent host signal is not available. Set/clear OURSIG_OK
368 do_gdb_signal_to_host (enum gdb_signal oursig,
372 /* Silence the 'not used' warning, for targets that
373 do not support signals. */
376 /* Signals are ordered ANSI-standard signals first, other signals
377 second, with signals in each block ordered by their numerical
378 values on a typical POSIX platform. */
386 /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
387 are ANSI-standard signals and are always available. */
392 case GDB_SIGNAL_ABRT:
396 case GDB_SIGNAL_SEGV:
398 case GDB_SIGNAL_TERM:
401 /* All other signals need preprocessor conditionals. */
406 #if defined (SIGQUIT)
407 case GDB_SIGNAL_QUIT:
410 #if defined (SIGTRAP)
411 case GDB_SIGNAL_TRAP:
418 #if defined (SIGKILL)
419 case GDB_SIGNAL_KILL:
430 #if defined (SIGPIPE)
431 case GDB_SIGNAL_PIPE:
434 #if defined (SIGALRM)
435 case GDB_SIGNAL_ALRM:
438 #if defined (SIGUSR1)
439 case GDB_SIGNAL_USR1:
442 #if defined (SIGUSR2)
443 case GDB_SIGNAL_USR2:
446 #if defined (SIGCHLD) || defined (SIGCLD)
447 case GDB_SIGNAL_CHLD:
448 #if defined (SIGCHLD)
453 #endif /* SIGCLD or SIGCHLD */
458 #if defined (SIGWINCH)
459 case GDB_SIGNAL_WINCH:
470 #if defined (SIGPOLL)
471 case GDB_SIGNAL_POLL:
474 #if defined (SIGSTOP)
475 case GDB_SIGNAL_STOP:
478 #if defined (SIGTSTP)
479 case GDB_SIGNAL_TSTP:
482 #if defined (SIGCONT)
483 case GDB_SIGNAL_CONT:
486 #if defined (SIGTTIN)
487 case GDB_SIGNAL_TTIN:
490 #if defined (SIGTTOU)
491 case GDB_SIGNAL_TTOU:
494 #if defined (SIGVTALRM)
495 case GDB_SIGNAL_VTALRM:
498 #if defined (SIGPROF)
499 case GDB_SIGNAL_PROF:
502 #if defined (SIGXCPU)
503 case GDB_SIGNAL_XCPU:
506 #if defined (SIGXFSZ)
507 case GDB_SIGNAL_XFSZ:
510 #if defined (SIGWIND)
511 case GDB_SIGNAL_WIND:
514 #if defined (SIGPHONE)
515 case GDB_SIGNAL_PHONE:
518 #if defined (SIGLOST)
519 case GDB_SIGNAL_LOST:
522 #if defined (SIGWAITING)
523 case GDB_SIGNAL_WAITING:
526 #if defined (SIGCANCEL)
527 case GDB_SIGNAL_CANCEL:
534 #if defined (SIGDANGER)
535 case GDB_SIGNAL_DANGER:
538 #if defined (SIGGRANT)
539 case GDB_SIGNAL_GRANT:
542 #if defined (SIGRETRACT)
543 case GDB_SIGNAL_RETRACT:
550 #if defined (SIGSOUND)
551 case GDB_SIGNAL_SOUND:
558 #if defined (SIGPRIO)
559 case GDB_SIGNAL_PRIO:
563 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
564 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
565 case GDB_EXC_BAD_ACCESS:
566 return _NSIG + EXC_BAD_ACCESS;
568 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
569 case GDB_EXC_BAD_INSTRUCTION:
570 return _NSIG + EXC_BAD_INSTRUCTION;
572 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
573 case GDB_EXC_ARITHMETIC:
574 return _NSIG + EXC_ARITHMETIC;
576 #if defined (EXC_EMULATION) && defined (_NSIG)
577 case GDB_EXC_EMULATION:
578 return _NSIG + EXC_EMULATION;
580 #if defined (EXC_SOFTWARE) && defined (_NSIG)
581 case GDB_EXC_SOFTWARE:
582 return _NSIG + EXC_SOFTWARE;
584 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
585 case GDB_EXC_BREAKPOINT:
586 return _NSIG + EXC_BREAKPOINT;
589 #if defined (SIGINFO)
590 case GDB_SIGNAL_INFO:
595 #if defined (REALTIME_LO)
598 if (oursig >= GDB_SIGNAL_REALTIME_33
599 && oursig <= GDB_SIGNAL_REALTIME_63)
601 /* This block of signals is continuous, and
602 GDB_SIGNAL_REALTIME_33 is 33 by definition. */
603 retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_33 + 33;
605 else if (oursig == GDB_SIGNAL_REALTIME_32)
607 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
608 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */
611 else if (oursig >= GDB_SIGNAL_REALTIME_64
612 && oursig <= GDB_SIGNAL_REALTIME_127)
614 /* This block of signals is continuous, and
615 GDB_SIGNAL_REALTIME_64 is 64 by definition. */
616 retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_64 + 64;
619 if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
629 gdb_signal_to_host_p (enum gdb_signal oursig)
632 do_gdb_signal_to_host (oursig, &oursig_ok);
637 gdb_signal_to_host (enum gdb_signal oursig)
640 int targ_signo = do_gdb_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."),
646 gdb_signal_to_name (oursig));