xref: /dflybsd-src/contrib/gdb-7/gdb/common/signals.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Target signal translation functions for GDB.
2*ef5ccd6cSJohn Marino    Copyright (C) 1990-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert    Contributed by Cygnus Support.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #ifdef GDBSERVER
215796c8dcSSimon Schubert #include "server.h"
225796c8dcSSimon Schubert #else
235796c8dcSSimon Schubert #include "defs.h"
245796c8dcSSimon Schubert #include "gdb_string.h"
255796c8dcSSimon Schubert #endif
265796c8dcSSimon Schubert 
275796c8dcSSimon Schubert #ifdef HAVE_SIGNAL_H
285796c8dcSSimon Schubert #include <signal.h>
295796c8dcSSimon Schubert #endif
305796c8dcSSimon Schubert 
315796c8dcSSimon Schubert #include "gdb_signals.h"
325796c8dcSSimon Schubert 
335796c8dcSSimon Schubert struct gdbarch;
345796c8dcSSimon Schubert 
355796c8dcSSimon Schubert /* Always use __SIGRTMIN if it's available.  SIGRTMIN is the lowest
365796c8dcSSimon Schubert    _available_ realtime signal, not the lowest supported; glibc takes
375796c8dcSSimon Schubert    several for its own use.  */
385796c8dcSSimon Schubert 
395796c8dcSSimon Schubert #ifndef REALTIME_LO
405796c8dcSSimon Schubert # if defined(__SIGRTMIN)
415796c8dcSSimon Schubert #  define REALTIME_LO __SIGRTMIN
425796c8dcSSimon Schubert #  define REALTIME_HI (__SIGRTMAX + 1)
435796c8dcSSimon Schubert # elif defined(SIGRTMIN)
445796c8dcSSimon Schubert #  define REALTIME_LO SIGRTMIN
455796c8dcSSimon Schubert #  define REALTIME_HI (SIGRTMAX + 1)
465796c8dcSSimon Schubert # endif
475796c8dcSSimon Schubert #endif
485796c8dcSSimon Schubert 
49c50c785cSJohn Marino /* This table must match in order and size the signals in enum
50*ef5ccd6cSJohn Marino    gdb_signal.  */
51c50c785cSJohn Marino 
525796c8dcSSimon Schubert static const struct {
535796c8dcSSimon Schubert   const char *name;
545796c8dcSSimon Schubert   const char *string;
555796c8dcSSimon Schubert   } signals [] =
565796c8dcSSimon Schubert {
57c50c785cSJohn Marino #define SET(symbol, constant, name, string) { name, string },
58c50c785cSJohn Marino #include "gdb/signals.def"
59c50c785cSJohn Marino #undef SET
605796c8dcSSimon Schubert };
615796c8dcSSimon Schubert 
625796c8dcSSimon Schubert 
635796c8dcSSimon Schubert /* Return the string for a signal.  */
645796c8dcSSimon Schubert const char *
gdb_signal_to_string(enum gdb_signal sig)65*ef5ccd6cSJohn Marino gdb_signal_to_string (enum gdb_signal sig)
665796c8dcSSimon Schubert {
67*ef5ccd6cSJohn Marino   if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST)
685796c8dcSSimon Schubert     return signals[sig].string;
695796c8dcSSimon Schubert   else
70*ef5ccd6cSJohn Marino     return signals[GDB_SIGNAL_UNKNOWN].string;
715796c8dcSSimon Schubert }
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert /* Return the name for a signal.  */
745796c8dcSSimon Schubert const char *
gdb_signal_to_name(enum gdb_signal sig)75*ef5ccd6cSJohn Marino gdb_signal_to_name (enum gdb_signal sig)
765796c8dcSSimon Schubert {
77*ef5ccd6cSJohn Marino   if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST
785796c8dcSSimon Schubert       && signals[sig].name != NULL)
795796c8dcSSimon Schubert     return signals[sig].name;
805796c8dcSSimon Schubert   else
815796c8dcSSimon Schubert     /* I think the code which prints this will always print it along
825796c8dcSSimon Schubert        with the string, so no need to be verbose (very old comment).  */
835796c8dcSSimon Schubert     return "?";
845796c8dcSSimon Schubert }
855796c8dcSSimon Schubert 
865796c8dcSSimon Schubert /* Given a name, return its signal.  */
87*ef5ccd6cSJohn Marino enum gdb_signal
gdb_signal_from_name(const char * name)88*ef5ccd6cSJohn Marino gdb_signal_from_name (const char *name)
895796c8dcSSimon Schubert {
90*ef5ccd6cSJohn Marino   enum gdb_signal sig;
915796c8dcSSimon Schubert 
925796c8dcSSimon Schubert   /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
93*ef5ccd6cSJohn Marino      for GDB_SIGNAL_SIGCHLD.  SIGIOT, on the other hand, is more
945796c8dcSSimon Schubert      questionable; seems like by now people should call it SIGABRT
955796c8dcSSimon Schubert      instead.  */
965796c8dcSSimon Schubert 
975796c8dcSSimon Schubert   /* This ugly cast brought to you by the native VAX compiler.  */
98*ef5ccd6cSJohn Marino   for (sig = GDB_SIGNAL_HUP;
99*ef5ccd6cSJohn Marino        sig < GDB_SIGNAL_LAST;
100*ef5ccd6cSJohn Marino        sig = (enum gdb_signal) ((int) sig + 1))
1015796c8dcSSimon Schubert     if (signals[sig].name != NULL
1025796c8dcSSimon Schubert 	&& strcmp (name, signals[sig].name) == 0)
1035796c8dcSSimon Schubert       return sig;
104*ef5ccd6cSJohn Marino   return GDB_SIGNAL_UNKNOWN;
1055796c8dcSSimon Schubert }
1065796c8dcSSimon Schubert 
1075796c8dcSSimon Schubert /* The following functions are to help certain targets deal
1085796c8dcSSimon Schubert    with the signal/waitstatus stuff.  They could just as well be in
1095796c8dcSSimon Schubert    a file called native-utils.c or unixwaitstatus-utils.c or whatever.  */
1105796c8dcSSimon Schubert 
1115796c8dcSSimon Schubert /* Convert host signal to our signals.  */
112*ef5ccd6cSJohn Marino enum gdb_signal
gdb_signal_from_host(int hostsig)113*ef5ccd6cSJohn Marino gdb_signal_from_host (int hostsig)
1145796c8dcSSimon Schubert {
1155796c8dcSSimon Schubert   /* A switch statement would make sense but would require special kludges
1165796c8dcSSimon Schubert      to deal with the cases where more than one signal has the same number.  */
1175796c8dcSSimon Schubert 
1185796c8dcSSimon Schubert   if (hostsig == 0)
119*ef5ccd6cSJohn Marino     return GDB_SIGNAL_0;
1205796c8dcSSimon Schubert 
1215796c8dcSSimon Schubert #if defined (SIGHUP)
1225796c8dcSSimon Schubert   if (hostsig == SIGHUP)
123*ef5ccd6cSJohn Marino     return GDB_SIGNAL_HUP;
1245796c8dcSSimon Schubert #endif
1255796c8dcSSimon Schubert #if defined (SIGINT)
1265796c8dcSSimon Schubert   if (hostsig == SIGINT)
127*ef5ccd6cSJohn Marino     return GDB_SIGNAL_INT;
1285796c8dcSSimon Schubert #endif
1295796c8dcSSimon Schubert #if defined (SIGQUIT)
1305796c8dcSSimon Schubert   if (hostsig == SIGQUIT)
131*ef5ccd6cSJohn Marino     return GDB_SIGNAL_QUIT;
1325796c8dcSSimon Schubert #endif
1335796c8dcSSimon Schubert #if defined (SIGILL)
1345796c8dcSSimon Schubert   if (hostsig == SIGILL)
135*ef5ccd6cSJohn Marino     return GDB_SIGNAL_ILL;
1365796c8dcSSimon Schubert #endif
1375796c8dcSSimon Schubert #if defined (SIGTRAP)
1385796c8dcSSimon Schubert   if (hostsig == SIGTRAP)
139*ef5ccd6cSJohn Marino     return GDB_SIGNAL_TRAP;
1405796c8dcSSimon Schubert #endif
1415796c8dcSSimon Schubert #if defined (SIGABRT)
1425796c8dcSSimon Schubert   if (hostsig == SIGABRT)
143*ef5ccd6cSJohn Marino     return GDB_SIGNAL_ABRT;
1445796c8dcSSimon Schubert #endif
1455796c8dcSSimon Schubert #if defined (SIGEMT)
1465796c8dcSSimon Schubert   if (hostsig == SIGEMT)
147*ef5ccd6cSJohn Marino     return GDB_SIGNAL_EMT;
1485796c8dcSSimon Schubert #endif
1495796c8dcSSimon Schubert #if defined (SIGFPE)
1505796c8dcSSimon Schubert   if (hostsig == SIGFPE)
151*ef5ccd6cSJohn Marino     return GDB_SIGNAL_FPE;
1525796c8dcSSimon Schubert #endif
1535796c8dcSSimon Schubert #if defined (SIGKILL)
1545796c8dcSSimon Schubert   if (hostsig == SIGKILL)
155*ef5ccd6cSJohn Marino     return GDB_SIGNAL_KILL;
1565796c8dcSSimon Schubert #endif
1575796c8dcSSimon Schubert #if defined (SIGBUS)
1585796c8dcSSimon Schubert   if (hostsig == SIGBUS)
159*ef5ccd6cSJohn Marino     return GDB_SIGNAL_BUS;
1605796c8dcSSimon Schubert #endif
1615796c8dcSSimon Schubert #if defined (SIGSEGV)
1625796c8dcSSimon Schubert   if (hostsig == SIGSEGV)
163*ef5ccd6cSJohn Marino     return GDB_SIGNAL_SEGV;
1645796c8dcSSimon Schubert #endif
1655796c8dcSSimon Schubert #if defined (SIGSYS)
1665796c8dcSSimon Schubert   if (hostsig == SIGSYS)
167*ef5ccd6cSJohn Marino     return GDB_SIGNAL_SYS;
1685796c8dcSSimon Schubert #endif
1695796c8dcSSimon Schubert #if defined (SIGPIPE)
1705796c8dcSSimon Schubert   if (hostsig == SIGPIPE)
171*ef5ccd6cSJohn Marino     return GDB_SIGNAL_PIPE;
1725796c8dcSSimon Schubert #endif
1735796c8dcSSimon Schubert #if defined (SIGALRM)
1745796c8dcSSimon Schubert   if (hostsig == SIGALRM)
175*ef5ccd6cSJohn Marino     return GDB_SIGNAL_ALRM;
1765796c8dcSSimon Schubert #endif
1775796c8dcSSimon Schubert #if defined (SIGTERM)
1785796c8dcSSimon Schubert   if (hostsig == SIGTERM)
179*ef5ccd6cSJohn Marino     return GDB_SIGNAL_TERM;
1805796c8dcSSimon Schubert #endif
1815796c8dcSSimon Schubert #if defined (SIGUSR1)
1825796c8dcSSimon Schubert   if (hostsig == SIGUSR1)
183*ef5ccd6cSJohn Marino     return GDB_SIGNAL_USR1;
1845796c8dcSSimon Schubert #endif
1855796c8dcSSimon Schubert #if defined (SIGUSR2)
1865796c8dcSSimon Schubert   if (hostsig == SIGUSR2)
187*ef5ccd6cSJohn Marino     return GDB_SIGNAL_USR2;
1885796c8dcSSimon Schubert #endif
1895796c8dcSSimon Schubert #if defined (SIGCLD)
1905796c8dcSSimon Schubert   if (hostsig == SIGCLD)
191*ef5ccd6cSJohn Marino     return GDB_SIGNAL_CHLD;
1925796c8dcSSimon Schubert #endif
1935796c8dcSSimon Schubert #if defined (SIGCHLD)
1945796c8dcSSimon Schubert   if (hostsig == SIGCHLD)
195*ef5ccd6cSJohn Marino     return GDB_SIGNAL_CHLD;
1965796c8dcSSimon Schubert #endif
1975796c8dcSSimon Schubert #if defined (SIGPWR)
1985796c8dcSSimon Schubert   if (hostsig == SIGPWR)
199*ef5ccd6cSJohn Marino     return GDB_SIGNAL_PWR;
2005796c8dcSSimon Schubert #endif
2015796c8dcSSimon Schubert #if defined (SIGWINCH)
2025796c8dcSSimon Schubert   if (hostsig == SIGWINCH)
203*ef5ccd6cSJohn Marino     return GDB_SIGNAL_WINCH;
2045796c8dcSSimon Schubert #endif
2055796c8dcSSimon Schubert #if defined (SIGURG)
2065796c8dcSSimon Schubert   if (hostsig == SIGURG)
207*ef5ccd6cSJohn Marino     return GDB_SIGNAL_URG;
2085796c8dcSSimon Schubert #endif
2095796c8dcSSimon Schubert #if defined (SIGIO)
2105796c8dcSSimon Schubert   if (hostsig == SIGIO)
211*ef5ccd6cSJohn Marino     return GDB_SIGNAL_IO;
2125796c8dcSSimon Schubert #endif
2135796c8dcSSimon Schubert #if defined (SIGPOLL)
2145796c8dcSSimon Schubert   if (hostsig == SIGPOLL)
215*ef5ccd6cSJohn Marino     return GDB_SIGNAL_POLL;
2165796c8dcSSimon Schubert #endif
2175796c8dcSSimon Schubert #if defined (SIGSTOP)
2185796c8dcSSimon Schubert   if (hostsig == SIGSTOP)
219*ef5ccd6cSJohn Marino     return GDB_SIGNAL_STOP;
2205796c8dcSSimon Schubert #endif
2215796c8dcSSimon Schubert #if defined (SIGTSTP)
2225796c8dcSSimon Schubert   if (hostsig == SIGTSTP)
223*ef5ccd6cSJohn Marino     return GDB_SIGNAL_TSTP;
2245796c8dcSSimon Schubert #endif
2255796c8dcSSimon Schubert #if defined (SIGCONT)
2265796c8dcSSimon Schubert   if (hostsig == SIGCONT)
227*ef5ccd6cSJohn Marino     return GDB_SIGNAL_CONT;
2285796c8dcSSimon Schubert #endif
2295796c8dcSSimon Schubert #if defined (SIGTTIN)
2305796c8dcSSimon Schubert   if (hostsig == SIGTTIN)
231*ef5ccd6cSJohn Marino     return GDB_SIGNAL_TTIN;
2325796c8dcSSimon Schubert #endif
2335796c8dcSSimon Schubert #if defined (SIGTTOU)
2345796c8dcSSimon Schubert   if (hostsig == SIGTTOU)
235*ef5ccd6cSJohn Marino     return GDB_SIGNAL_TTOU;
2365796c8dcSSimon Schubert #endif
2375796c8dcSSimon Schubert #if defined (SIGVTALRM)
2385796c8dcSSimon Schubert   if (hostsig == SIGVTALRM)
239*ef5ccd6cSJohn Marino     return GDB_SIGNAL_VTALRM;
2405796c8dcSSimon Schubert #endif
2415796c8dcSSimon Schubert #if defined (SIGPROF)
2425796c8dcSSimon Schubert   if (hostsig == SIGPROF)
243*ef5ccd6cSJohn Marino     return GDB_SIGNAL_PROF;
2445796c8dcSSimon Schubert #endif
2455796c8dcSSimon Schubert #if defined (SIGXCPU)
2465796c8dcSSimon Schubert   if (hostsig == SIGXCPU)
247*ef5ccd6cSJohn Marino     return GDB_SIGNAL_XCPU;
2485796c8dcSSimon Schubert #endif
2495796c8dcSSimon Schubert #if defined (SIGXFSZ)
2505796c8dcSSimon Schubert   if (hostsig == SIGXFSZ)
251*ef5ccd6cSJohn Marino     return GDB_SIGNAL_XFSZ;
2525796c8dcSSimon Schubert #endif
2535796c8dcSSimon Schubert #if defined (SIGWIND)
2545796c8dcSSimon Schubert   if (hostsig == SIGWIND)
255*ef5ccd6cSJohn Marino     return GDB_SIGNAL_WIND;
2565796c8dcSSimon Schubert #endif
2575796c8dcSSimon Schubert #if defined (SIGPHONE)
2585796c8dcSSimon Schubert   if (hostsig == SIGPHONE)
259*ef5ccd6cSJohn Marino     return GDB_SIGNAL_PHONE;
2605796c8dcSSimon Schubert #endif
2615796c8dcSSimon Schubert #if defined (SIGLOST)
2625796c8dcSSimon Schubert   if (hostsig == SIGLOST)
263*ef5ccd6cSJohn Marino     return GDB_SIGNAL_LOST;
2645796c8dcSSimon Schubert #endif
2655796c8dcSSimon Schubert #if defined (SIGWAITING)
2665796c8dcSSimon Schubert   if (hostsig == SIGWAITING)
267*ef5ccd6cSJohn Marino     return GDB_SIGNAL_WAITING;
2685796c8dcSSimon Schubert #endif
2695796c8dcSSimon Schubert #if defined (SIGCANCEL)
2705796c8dcSSimon Schubert   if (hostsig == SIGCANCEL)
271*ef5ccd6cSJohn Marino     return GDB_SIGNAL_CANCEL;
2725796c8dcSSimon Schubert #endif
2735796c8dcSSimon Schubert #if defined (SIGLWP)
2745796c8dcSSimon Schubert   if (hostsig == SIGLWP)
275*ef5ccd6cSJohn Marino     return GDB_SIGNAL_LWP;
2765796c8dcSSimon Schubert #endif
2775796c8dcSSimon Schubert #if defined (SIGDANGER)
2785796c8dcSSimon Schubert   if (hostsig == SIGDANGER)
279*ef5ccd6cSJohn Marino     return GDB_SIGNAL_DANGER;
2805796c8dcSSimon Schubert #endif
2815796c8dcSSimon Schubert #if defined (SIGGRANT)
2825796c8dcSSimon Schubert   if (hostsig == SIGGRANT)
283*ef5ccd6cSJohn Marino     return GDB_SIGNAL_GRANT;
2845796c8dcSSimon Schubert #endif
2855796c8dcSSimon Schubert #if defined (SIGRETRACT)
2865796c8dcSSimon Schubert   if (hostsig == SIGRETRACT)
287*ef5ccd6cSJohn Marino     return GDB_SIGNAL_RETRACT;
2885796c8dcSSimon Schubert #endif
2895796c8dcSSimon Schubert #if defined (SIGMSG)
2905796c8dcSSimon Schubert   if (hostsig == SIGMSG)
291*ef5ccd6cSJohn Marino     return GDB_SIGNAL_MSG;
2925796c8dcSSimon Schubert #endif
2935796c8dcSSimon Schubert #if defined (SIGSOUND)
2945796c8dcSSimon Schubert   if (hostsig == SIGSOUND)
295*ef5ccd6cSJohn Marino     return GDB_SIGNAL_SOUND;
2965796c8dcSSimon Schubert #endif
2975796c8dcSSimon Schubert #if defined (SIGSAK)
2985796c8dcSSimon Schubert   if (hostsig == SIGSAK)
299*ef5ccd6cSJohn Marino     return GDB_SIGNAL_SAK;
3005796c8dcSSimon Schubert #endif
3015796c8dcSSimon Schubert #if defined (SIGPRIO)
3025796c8dcSSimon Schubert   if (hostsig == SIGPRIO)
303*ef5ccd6cSJohn Marino     return GDB_SIGNAL_PRIO;
3045796c8dcSSimon Schubert #endif
3055796c8dcSSimon Schubert 
3065796c8dcSSimon Schubert   /* Mach exceptions.  Assumes that the values for EXC_ are positive! */
3075796c8dcSSimon Schubert #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
3085796c8dcSSimon Schubert   if (hostsig == _NSIG + EXC_BAD_ACCESS)
3095796c8dcSSimon Schubert     return TARGET_EXC_BAD_ACCESS;
3105796c8dcSSimon Schubert #endif
3115796c8dcSSimon Schubert #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
3125796c8dcSSimon Schubert   if (hostsig == _NSIG + EXC_BAD_INSTRUCTION)
3135796c8dcSSimon Schubert     return TARGET_EXC_BAD_INSTRUCTION;
3145796c8dcSSimon Schubert #endif
3155796c8dcSSimon Schubert #if defined (EXC_ARITHMETIC) && defined (_NSIG)
3165796c8dcSSimon Schubert   if (hostsig == _NSIG + EXC_ARITHMETIC)
3175796c8dcSSimon Schubert     return TARGET_EXC_ARITHMETIC;
3185796c8dcSSimon Schubert #endif
3195796c8dcSSimon Schubert #if defined (EXC_EMULATION) && defined (_NSIG)
3205796c8dcSSimon Schubert   if (hostsig == _NSIG + EXC_EMULATION)
3215796c8dcSSimon Schubert     return TARGET_EXC_EMULATION;
3225796c8dcSSimon Schubert #endif
3235796c8dcSSimon Schubert #if defined (EXC_SOFTWARE) && defined (_NSIG)
3245796c8dcSSimon Schubert   if (hostsig == _NSIG + EXC_SOFTWARE)
3255796c8dcSSimon Schubert     return TARGET_EXC_SOFTWARE;
3265796c8dcSSimon Schubert #endif
3275796c8dcSSimon Schubert #if defined (EXC_BREAKPOINT) && defined (_NSIG)
3285796c8dcSSimon Schubert   if (hostsig == _NSIG + EXC_BREAKPOINT)
3295796c8dcSSimon Schubert     return TARGET_EXC_BREAKPOINT;
3305796c8dcSSimon Schubert #endif
3315796c8dcSSimon Schubert 
3325796c8dcSSimon Schubert #if defined (SIGINFO)
3335796c8dcSSimon Schubert   if (hostsig == SIGINFO)
334*ef5ccd6cSJohn Marino     return GDB_SIGNAL_INFO;
3355796c8dcSSimon Schubert #endif
3365796c8dcSSimon Schubert 
3375796c8dcSSimon Schubert #if defined (REALTIME_LO)
3385796c8dcSSimon Schubert   if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
3395796c8dcSSimon Schubert     {
340*ef5ccd6cSJohn Marino       /* This block of GDB_SIGNAL_REALTIME value is in order.  */
3415796c8dcSSimon Schubert       if (33 <= hostsig && hostsig <= 63)
342*ef5ccd6cSJohn Marino 	return (enum gdb_signal)
343*ef5ccd6cSJohn Marino 	  (hostsig - 33 + (int) GDB_SIGNAL_REALTIME_33);
3445796c8dcSSimon Schubert       else if (hostsig == 32)
345*ef5ccd6cSJohn Marino 	return GDB_SIGNAL_REALTIME_32;
3465796c8dcSSimon Schubert       else if (64 <= hostsig && hostsig <= 127)
347*ef5ccd6cSJohn Marino 	return (enum gdb_signal)
348*ef5ccd6cSJohn Marino 	  (hostsig - 64 + (int) GDB_SIGNAL_REALTIME_64);
3495796c8dcSSimon Schubert       else
350*ef5ccd6cSJohn Marino 	error (_("GDB bug: target.c (gdb_signal_from_host): "
351c50c785cSJohn Marino 	       "unrecognized real-time signal"));
3525796c8dcSSimon Schubert     }
3535796c8dcSSimon Schubert #endif
3545796c8dcSSimon Schubert 
355*ef5ccd6cSJohn Marino   return GDB_SIGNAL_UNKNOWN;
3565796c8dcSSimon Schubert }
3575796c8dcSSimon Schubert 
358*ef5ccd6cSJohn Marino /* Convert a OURSIG (an enum gdb_signal) to the form used by the
3595796c8dcSSimon Schubert    target operating system (refered to as the ``host'') or zero if the
3605796c8dcSSimon Schubert    equivalent host signal is not available.  Set/clear OURSIG_OK
3615796c8dcSSimon Schubert    accordingly. */
3625796c8dcSSimon Schubert 
3635796c8dcSSimon Schubert static int
do_gdb_signal_to_host(enum gdb_signal oursig,int * oursig_ok)364*ef5ccd6cSJohn Marino do_gdb_signal_to_host (enum gdb_signal oursig,
3655796c8dcSSimon Schubert 			  int *oursig_ok)
3665796c8dcSSimon Schubert {
3675796c8dcSSimon Schubert   int retsig;
3685796c8dcSSimon Schubert   /* Silence the 'not used' warning, for targets that
3695796c8dcSSimon Schubert      do not support signals.  */
3705796c8dcSSimon Schubert   (void) retsig;
3715796c8dcSSimon Schubert 
3725796c8dcSSimon Schubert   *oursig_ok = 1;
3735796c8dcSSimon Schubert   switch (oursig)
3745796c8dcSSimon Schubert     {
375*ef5ccd6cSJohn Marino     case GDB_SIGNAL_0:
3765796c8dcSSimon Schubert       return 0;
3775796c8dcSSimon Schubert 
3785796c8dcSSimon Schubert #if defined (SIGHUP)
379*ef5ccd6cSJohn Marino     case GDB_SIGNAL_HUP:
3805796c8dcSSimon Schubert       return SIGHUP;
3815796c8dcSSimon Schubert #endif
3825796c8dcSSimon Schubert #if defined (SIGINT)
383*ef5ccd6cSJohn Marino     case GDB_SIGNAL_INT:
3845796c8dcSSimon Schubert       return SIGINT;
3855796c8dcSSimon Schubert #endif
3865796c8dcSSimon Schubert #if defined (SIGQUIT)
387*ef5ccd6cSJohn Marino     case GDB_SIGNAL_QUIT:
3885796c8dcSSimon Schubert       return SIGQUIT;
3895796c8dcSSimon Schubert #endif
3905796c8dcSSimon Schubert #if defined (SIGILL)
391*ef5ccd6cSJohn Marino     case GDB_SIGNAL_ILL:
3925796c8dcSSimon Schubert       return SIGILL;
3935796c8dcSSimon Schubert #endif
3945796c8dcSSimon Schubert #if defined (SIGTRAP)
395*ef5ccd6cSJohn Marino     case GDB_SIGNAL_TRAP:
3965796c8dcSSimon Schubert       return SIGTRAP;
3975796c8dcSSimon Schubert #endif
3985796c8dcSSimon Schubert #if defined (SIGABRT)
399*ef5ccd6cSJohn Marino     case GDB_SIGNAL_ABRT:
4005796c8dcSSimon Schubert       return SIGABRT;
4015796c8dcSSimon Schubert #endif
4025796c8dcSSimon Schubert #if defined (SIGEMT)
403*ef5ccd6cSJohn Marino     case GDB_SIGNAL_EMT:
4045796c8dcSSimon Schubert       return SIGEMT;
4055796c8dcSSimon Schubert #endif
4065796c8dcSSimon Schubert #if defined (SIGFPE)
407*ef5ccd6cSJohn Marino     case GDB_SIGNAL_FPE:
4085796c8dcSSimon Schubert       return SIGFPE;
4095796c8dcSSimon Schubert #endif
4105796c8dcSSimon Schubert #if defined (SIGKILL)
411*ef5ccd6cSJohn Marino     case GDB_SIGNAL_KILL:
4125796c8dcSSimon Schubert       return SIGKILL;
4135796c8dcSSimon Schubert #endif
4145796c8dcSSimon Schubert #if defined (SIGBUS)
415*ef5ccd6cSJohn Marino     case GDB_SIGNAL_BUS:
4165796c8dcSSimon Schubert       return SIGBUS;
4175796c8dcSSimon Schubert #endif
4185796c8dcSSimon Schubert #if defined (SIGSEGV)
419*ef5ccd6cSJohn Marino     case GDB_SIGNAL_SEGV:
4205796c8dcSSimon Schubert       return SIGSEGV;
4215796c8dcSSimon Schubert #endif
4225796c8dcSSimon Schubert #if defined (SIGSYS)
423*ef5ccd6cSJohn Marino     case GDB_SIGNAL_SYS:
4245796c8dcSSimon Schubert       return SIGSYS;
4255796c8dcSSimon Schubert #endif
4265796c8dcSSimon Schubert #if defined (SIGPIPE)
427*ef5ccd6cSJohn Marino     case GDB_SIGNAL_PIPE:
4285796c8dcSSimon Schubert       return SIGPIPE;
4295796c8dcSSimon Schubert #endif
4305796c8dcSSimon Schubert #if defined (SIGALRM)
431*ef5ccd6cSJohn Marino     case GDB_SIGNAL_ALRM:
4325796c8dcSSimon Schubert       return SIGALRM;
4335796c8dcSSimon Schubert #endif
4345796c8dcSSimon Schubert #if defined (SIGTERM)
435*ef5ccd6cSJohn Marino     case GDB_SIGNAL_TERM:
4365796c8dcSSimon Schubert       return SIGTERM;
4375796c8dcSSimon Schubert #endif
4385796c8dcSSimon Schubert #if defined (SIGUSR1)
439*ef5ccd6cSJohn Marino     case GDB_SIGNAL_USR1:
4405796c8dcSSimon Schubert       return SIGUSR1;
4415796c8dcSSimon Schubert #endif
4425796c8dcSSimon Schubert #if defined (SIGUSR2)
443*ef5ccd6cSJohn Marino     case GDB_SIGNAL_USR2:
4445796c8dcSSimon Schubert       return SIGUSR2;
4455796c8dcSSimon Schubert #endif
4465796c8dcSSimon Schubert #if defined (SIGCHLD) || defined (SIGCLD)
447*ef5ccd6cSJohn Marino     case GDB_SIGNAL_CHLD:
4485796c8dcSSimon Schubert #if defined (SIGCHLD)
4495796c8dcSSimon Schubert       return SIGCHLD;
4505796c8dcSSimon Schubert #else
4515796c8dcSSimon Schubert       return SIGCLD;
4525796c8dcSSimon Schubert #endif
4535796c8dcSSimon Schubert #endif /* SIGCLD or SIGCHLD */
4545796c8dcSSimon Schubert #if defined (SIGPWR)
455*ef5ccd6cSJohn Marino     case GDB_SIGNAL_PWR:
4565796c8dcSSimon Schubert       return SIGPWR;
4575796c8dcSSimon Schubert #endif
4585796c8dcSSimon Schubert #if defined (SIGWINCH)
459*ef5ccd6cSJohn Marino     case GDB_SIGNAL_WINCH:
4605796c8dcSSimon Schubert       return SIGWINCH;
4615796c8dcSSimon Schubert #endif
4625796c8dcSSimon Schubert #if defined (SIGURG)
463*ef5ccd6cSJohn Marino     case GDB_SIGNAL_URG:
4645796c8dcSSimon Schubert       return SIGURG;
4655796c8dcSSimon Schubert #endif
4665796c8dcSSimon Schubert #if defined (SIGIO)
467*ef5ccd6cSJohn Marino     case GDB_SIGNAL_IO:
4685796c8dcSSimon Schubert       return SIGIO;
4695796c8dcSSimon Schubert #endif
4705796c8dcSSimon Schubert #if defined (SIGPOLL)
471*ef5ccd6cSJohn Marino     case GDB_SIGNAL_POLL:
4725796c8dcSSimon Schubert       return SIGPOLL;
4735796c8dcSSimon Schubert #endif
4745796c8dcSSimon Schubert #if defined (SIGSTOP)
475*ef5ccd6cSJohn Marino     case GDB_SIGNAL_STOP:
4765796c8dcSSimon Schubert       return SIGSTOP;
4775796c8dcSSimon Schubert #endif
4785796c8dcSSimon Schubert #if defined (SIGTSTP)
479*ef5ccd6cSJohn Marino     case GDB_SIGNAL_TSTP:
4805796c8dcSSimon Schubert       return SIGTSTP;
4815796c8dcSSimon Schubert #endif
4825796c8dcSSimon Schubert #if defined (SIGCONT)
483*ef5ccd6cSJohn Marino     case GDB_SIGNAL_CONT:
4845796c8dcSSimon Schubert       return SIGCONT;
4855796c8dcSSimon Schubert #endif
4865796c8dcSSimon Schubert #if defined (SIGTTIN)
487*ef5ccd6cSJohn Marino     case GDB_SIGNAL_TTIN:
4885796c8dcSSimon Schubert       return SIGTTIN;
4895796c8dcSSimon Schubert #endif
4905796c8dcSSimon Schubert #if defined (SIGTTOU)
491*ef5ccd6cSJohn Marino     case GDB_SIGNAL_TTOU:
4925796c8dcSSimon Schubert       return SIGTTOU;
4935796c8dcSSimon Schubert #endif
4945796c8dcSSimon Schubert #if defined (SIGVTALRM)
495*ef5ccd6cSJohn Marino     case GDB_SIGNAL_VTALRM:
4965796c8dcSSimon Schubert       return SIGVTALRM;
4975796c8dcSSimon Schubert #endif
4985796c8dcSSimon Schubert #if defined (SIGPROF)
499*ef5ccd6cSJohn Marino     case GDB_SIGNAL_PROF:
5005796c8dcSSimon Schubert       return SIGPROF;
5015796c8dcSSimon Schubert #endif
5025796c8dcSSimon Schubert #if defined (SIGXCPU)
503*ef5ccd6cSJohn Marino     case GDB_SIGNAL_XCPU:
5045796c8dcSSimon Schubert       return SIGXCPU;
5055796c8dcSSimon Schubert #endif
5065796c8dcSSimon Schubert #if defined (SIGXFSZ)
507*ef5ccd6cSJohn Marino     case GDB_SIGNAL_XFSZ:
5085796c8dcSSimon Schubert       return SIGXFSZ;
5095796c8dcSSimon Schubert #endif
5105796c8dcSSimon Schubert #if defined (SIGWIND)
511*ef5ccd6cSJohn Marino     case GDB_SIGNAL_WIND:
5125796c8dcSSimon Schubert       return SIGWIND;
5135796c8dcSSimon Schubert #endif
5145796c8dcSSimon Schubert #if defined (SIGPHONE)
515*ef5ccd6cSJohn Marino     case GDB_SIGNAL_PHONE:
5165796c8dcSSimon Schubert       return SIGPHONE;
5175796c8dcSSimon Schubert #endif
5185796c8dcSSimon Schubert #if defined (SIGLOST)
519*ef5ccd6cSJohn Marino     case GDB_SIGNAL_LOST:
5205796c8dcSSimon Schubert       return SIGLOST;
5215796c8dcSSimon Schubert #endif
5225796c8dcSSimon Schubert #if defined (SIGWAITING)
523*ef5ccd6cSJohn Marino     case GDB_SIGNAL_WAITING:
5245796c8dcSSimon Schubert       return SIGWAITING;
5255796c8dcSSimon Schubert #endif
5265796c8dcSSimon Schubert #if defined (SIGCANCEL)
527*ef5ccd6cSJohn Marino     case GDB_SIGNAL_CANCEL:
5285796c8dcSSimon Schubert       return SIGCANCEL;
5295796c8dcSSimon Schubert #endif
5305796c8dcSSimon Schubert #if defined (SIGLWP)
531*ef5ccd6cSJohn Marino     case GDB_SIGNAL_LWP:
5325796c8dcSSimon Schubert       return SIGLWP;
5335796c8dcSSimon Schubert #endif
5345796c8dcSSimon Schubert #if defined (SIGDANGER)
535*ef5ccd6cSJohn Marino     case GDB_SIGNAL_DANGER:
5365796c8dcSSimon Schubert       return SIGDANGER;
5375796c8dcSSimon Schubert #endif
5385796c8dcSSimon Schubert #if defined (SIGGRANT)
539*ef5ccd6cSJohn Marino     case GDB_SIGNAL_GRANT:
5405796c8dcSSimon Schubert       return SIGGRANT;
5415796c8dcSSimon Schubert #endif
5425796c8dcSSimon Schubert #if defined (SIGRETRACT)
543*ef5ccd6cSJohn Marino     case GDB_SIGNAL_RETRACT:
5445796c8dcSSimon Schubert       return SIGRETRACT;
5455796c8dcSSimon Schubert #endif
5465796c8dcSSimon Schubert #if defined (SIGMSG)
547*ef5ccd6cSJohn Marino     case GDB_SIGNAL_MSG:
5485796c8dcSSimon Schubert       return SIGMSG;
5495796c8dcSSimon Schubert #endif
5505796c8dcSSimon Schubert #if defined (SIGSOUND)
551*ef5ccd6cSJohn Marino     case GDB_SIGNAL_SOUND:
5525796c8dcSSimon Schubert       return SIGSOUND;
5535796c8dcSSimon Schubert #endif
5545796c8dcSSimon Schubert #if defined (SIGSAK)
555*ef5ccd6cSJohn Marino     case GDB_SIGNAL_SAK:
5565796c8dcSSimon Schubert       return SIGSAK;
5575796c8dcSSimon Schubert #endif
5585796c8dcSSimon Schubert #if defined (SIGPRIO)
559*ef5ccd6cSJohn Marino     case GDB_SIGNAL_PRIO:
5605796c8dcSSimon Schubert       return SIGPRIO;
5615796c8dcSSimon Schubert #endif
5625796c8dcSSimon Schubert 
5635796c8dcSSimon Schubert       /* Mach exceptions.  Assumes that the values for EXC_ are positive! */
5645796c8dcSSimon Schubert #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
5655796c8dcSSimon Schubert     case TARGET_EXC_BAD_ACCESS:
5665796c8dcSSimon Schubert       return _NSIG + EXC_BAD_ACCESS;
5675796c8dcSSimon Schubert #endif
5685796c8dcSSimon Schubert #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
5695796c8dcSSimon Schubert     case TARGET_EXC_BAD_INSTRUCTION:
5705796c8dcSSimon Schubert       return _NSIG + EXC_BAD_INSTRUCTION;
5715796c8dcSSimon Schubert #endif
5725796c8dcSSimon Schubert #if defined (EXC_ARITHMETIC) && defined (_NSIG)
5735796c8dcSSimon Schubert     case TARGET_EXC_ARITHMETIC:
5745796c8dcSSimon Schubert       return _NSIG + EXC_ARITHMETIC;
5755796c8dcSSimon Schubert #endif
5765796c8dcSSimon Schubert #if defined (EXC_EMULATION) && defined (_NSIG)
5775796c8dcSSimon Schubert     case TARGET_EXC_EMULATION:
5785796c8dcSSimon Schubert       return _NSIG + EXC_EMULATION;
5795796c8dcSSimon Schubert #endif
5805796c8dcSSimon Schubert #if defined (EXC_SOFTWARE) && defined (_NSIG)
5815796c8dcSSimon Schubert     case TARGET_EXC_SOFTWARE:
5825796c8dcSSimon Schubert       return _NSIG + EXC_SOFTWARE;
5835796c8dcSSimon Schubert #endif
5845796c8dcSSimon Schubert #if defined (EXC_BREAKPOINT) && defined (_NSIG)
5855796c8dcSSimon Schubert     case TARGET_EXC_BREAKPOINT:
5865796c8dcSSimon Schubert       return _NSIG + EXC_BREAKPOINT;
5875796c8dcSSimon Schubert #endif
5885796c8dcSSimon Schubert 
5895796c8dcSSimon Schubert #if defined (SIGINFO)
590*ef5ccd6cSJohn Marino     case GDB_SIGNAL_INFO:
5915796c8dcSSimon Schubert       return SIGINFO;
5925796c8dcSSimon Schubert #endif
5935796c8dcSSimon Schubert 
5945796c8dcSSimon Schubert     default:
5955796c8dcSSimon Schubert #if defined (REALTIME_LO)
5965796c8dcSSimon Schubert       retsig = 0;
5975796c8dcSSimon Schubert 
598*ef5ccd6cSJohn Marino       if (oursig >= GDB_SIGNAL_REALTIME_33
599*ef5ccd6cSJohn Marino 	  && oursig <= GDB_SIGNAL_REALTIME_63)
6005796c8dcSSimon Schubert 	{
6015796c8dcSSimon Schubert 	  /* This block of signals is continuous, and
602*ef5ccd6cSJohn Marino              GDB_SIGNAL_REALTIME_33 is 33 by definition.  */
603*ef5ccd6cSJohn Marino 	  retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_33 + 33;
6045796c8dcSSimon Schubert 	}
605*ef5ccd6cSJohn Marino       else if (oursig == GDB_SIGNAL_REALTIME_32)
6065796c8dcSSimon Schubert 	{
607*ef5ccd6cSJohn Marino 	  /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
608*ef5ccd6cSJohn Marino              GDB_SIGNAL_REALTIME_33.  It is 32 by definition.  */
6095796c8dcSSimon Schubert 	  retsig = 32;
6105796c8dcSSimon Schubert 	}
611*ef5ccd6cSJohn Marino       else if (oursig >= GDB_SIGNAL_REALTIME_64
612*ef5ccd6cSJohn Marino 	  && oursig <= GDB_SIGNAL_REALTIME_127)
6135796c8dcSSimon Schubert 	{
6145796c8dcSSimon Schubert 	  /* This block of signals is continuous, and
615*ef5ccd6cSJohn Marino              GDB_SIGNAL_REALTIME_64 is 64 by definition.  */
616*ef5ccd6cSJohn Marino 	  retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_64 + 64;
6175796c8dcSSimon Schubert 	}
6185796c8dcSSimon Schubert 
6195796c8dcSSimon Schubert       if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
6205796c8dcSSimon Schubert 	return retsig;
6215796c8dcSSimon Schubert #endif
6225796c8dcSSimon Schubert 
6235796c8dcSSimon Schubert       *oursig_ok = 0;
6245796c8dcSSimon Schubert       return 0;
6255796c8dcSSimon Schubert     }
6265796c8dcSSimon Schubert }
6275796c8dcSSimon Schubert 
6285796c8dcSSimon Schubert int
gdb_signal_to_host_p(enum gdb_signal oursig)629*ef5ccd6cSJohn Marino gdb_signal_to_host_p (enum gdb_signal oursig)
6305796c8dcSSimon Schubert {
6315796c8dcSSimon Schubert   int oursig_ok;
632*ef5ccd6cSJohn Marino   do_gdb_signal_to_host (oursig, &oursig_ok);
6335796c8dcSSimon Schubert   return oursig_ok;
6345796c8dcSSimon Schubert }
6355796c8dcSSimon Schubert 
6365796c8dcSSimon Schubert int
gdb_signal_to_host(enum gdb_signal oursig)637*ef5ccd6cSJohn Marino gdb_signal_to_host (enum gdb_signal oursig)
6385796c8dcSSimon Schubert {
6395796c8dcSSimon Schubert   int oursig_ok;
640*ef5ccd6cSJohn Marino   int targ_signo = do_gdb_signal_to_host (oursig, &oursig_ok);
6415796c8dcSSimon Schubert   if (!oursig_ok)
6425796c8dcSSimon Schubert     {
6435796c8dcSSimon Schubert       /* The user might be trying to do "signal SIGSAK" where this system
6445796c8dcSSimon Schubert          doesn't have SIGSAK.  */
645c50c785cSJohn Marino       warning (_("Signal %s does not exist on this system."),
646*ef5ccd6cSJohn Marino 	       gdb_signal_to_name (oursig));
6475796c8dcSSimon Schubert       return 0;
6485796c8dcSSimon Schubert     }
6495796c8dcSSimon Schubert   else
6505796c8dcSSimon Schubert     return targ_signo;
6515796c8dcSSimon Schubert }
652