xref: /netbsd-src/external/gpl3/gdb.old/dist/gdbsupport/signals.cc (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
17d62b00eSchristos /* Target signal translation functions for GDB.
2*6881a400Schristos    Copyright (C) 1990-2023 Free Software Foundation, Inc.
37d62b00eSchristos    Contributed by Cygnus Support.
47d62b00eSchristos 
57d62b00eSchristos    This file is part of GDB.
67d62b00eSchristos 
77d62b00eSchristos    This program is free software; you can redistribute it and/or modify
87d62b00eSchristos    it under the terms of the GNU General Public License as published by
97d62b00eSchristos    the Free Software Foundation; either version 3 of the License, or
107d62b00eSchristos    (at your option) any later version.
117d62b00eSchristos 
127d62b00eSchristos    This program is distributed in the hope that it will be useful,
137d62b00eSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
147d62b00eSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
157d62b00eSchristos    GNU General Public License for more details.
167d62b00eSchristos 
177d62b00eSchristos    You should have received a copy of the GNU General Public License
187d62b00eSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
197d62b00eSchristos 
207d62b00eSchristos #include "common-defs.h"
217d62b00eSchristos 
227d62b00eSchristos #ifdef HAVE_SIGNAL_H
237d62b00eSchristos #include <signal.h>
247d62b00eSchristos #endif
257d62b00eSchristos 
267d62b00eSchristos #include "gdb_signals.h"
277d62b00eSchristos 
287d62b00eSchristos struct gdbarch;
297d62b00eSchristos 
307d62b00eSchristos /* Always use __SIGRTMIN if it's available.  SIGRTMIN is the lowest
317d62b00eSchristos    _available_ realtime signal, not the lowest supported; glibc takes
327d62b00eSchristos    several for its own use.  */
337d62b00eSchristos 
347d62b00eSchristos #ifndef REALTIME_LO
357d62b00eSchristos # if defined(__SIGRTMIN)
367d62b00eSchristos #  define REALTIME_LO __SIGRTMIN
377d62b00eSchristos #  define REALTIME_HI (__SIGRTMAX + 1)
387d62b00eSchristos # elif defined(SIGRTMIN)
397d62b00eSchristos #  define REALTIME_LO SIGRTMIN
407d62b00eSchristos #  define REALTIME_HI (SIGRTMAX + 1)
417d62b00eSchristos # endif
427d62b00eSchristos #endif
437d62b00eSchristos 
447d62b00eSchristos /* This table must match in order and size the signals in enum
457d62b00eSchristos    gdb_signal.  */
467d62b00eSchristos 
477d62b00eSchristos static const struct {
487d62b00eSchristos   const char *symbol;
497d62b00eSchristos   const char *name;
507d62b00eSchristos   const char *string;
517d62b00eSchristos   } signals [] =
527d62b00eSchristos {
537d62b00eSchristos #define SET(symbol, constant, name, string) { #symbol, name, string },
547d62b00eSchristos #include "gdb/signals.def"
557d62b00eSchristos #undef SET
567d62b00eSchristos };
577d62b00eSchristos 
587d62b00eSchristos const char *
597d62b00eSchristos gdb_signal_to_symbol_string (enum gdb_signal sig)
607d62b00eSchristos {
617d62b00eSchristos   gdb_assert ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST);
627d62b00eSchristos 
637d62b00eSchristos   return signals[sig].symbol;
647d62b00eSchristos }
657d62b00eSchristos 
667d62b00eSchristos /* Return the string for a signal.  */
677d62b00eSchristos const char *
687d62b00eSchristos gdb_signal_to_string (enum gdb_signal sig)
697d62b00eSchristos {
707d62b00eSchristos   if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST)
717d62b00eSchristos     return signals[sig].string;
727d62b00eSchristos   else
737d62b00eSchristos     return signals[GDB_SIGNAL_UNKNOWN].string;
747d62b00eSchristos }
757d62b00eSchristos 
767d62b00eSchristos /* Return the name for a signal.  */
777d62b00eSchristos const char *
787d62b00eSchristos gdb_signal_to_name (enum gdb_signal sig)
797d62b00eSchristos {
807d62b00eSchristos   if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST
817d62b00eSchristos       && signals[sig].name != NULL)
827d62b00eSchristos     return signals[sig].name;
837d62b00eSchristos   else
847d62b00eSchristos     /* I think the code which prints this will always print it along
857d62b00eSchristos        with the string, so no need to be verbose (very old comment).  */
867d62b00eSchristos     return "?";
877d62b00eSchristos }
887d62b00eSchristos 
897d62b00eSchristos /* Given a name, return its signal.  */
907d62b00eSchristos enum gdb_signal
917d62b00eSchristos gdb_signal_from_name (const char *name)
927d62b00eSchristos {
937d62b00eSchristos   enum gdb_signal sig;
947d62b00eSchristos 
957d62b00eSchristos   /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
967d62b00eSchristos      for GDB_SIGNAL_SIGCHLD.  SIGIOT, on the other hand, is more
977d62b00eSchristos      questionable; seems like by now people should call it SIGABRT
987d62b00eSchristos      instead.  */
997d62b00eSchristos 
1007d62b00eSchristos   /* This ugly cast brought to you by the native VAX compiler.  */
1017d62b00eSchristos   for (sig = GDB_SIGNAL_HUP;
1027d62b00eSchristos        sig < GDB_SIGNAL_LAST;
1037d62b00eSchristos        sig = (enum gdb_signal) ((int) sig + 1))
1047d62b00eSchristos     if (signals[sig].name != NULL
1057d62b00eSchristos 	&& strcmp (name, signals[sig].name) == 0)
1067d62b00eSchristos       return sig;
1077d62b00eSchristos   return GDB_SIGNAL_UNKNOWN;
1087d62b00eSchristos }
1097d62b00eSchristos 
1107d62b00eSchristos /* The following functions are to help certain targets deal
1117d62b00eSchristos    with the signal/waitstatus stuff.  They could just as well be in
1127d62b00eSchristos    a file called native-utils.c or unixwaitstatus-utils.c or whatever.  */
1137d62b00eSchristos 
1147d62b00eSchristos /* Convert host signal to our signals.  */
1157d62b00eSchristos enum gdb_signal
1167d62b00eSchristos gdb_signal_from_host (int hostsig)
1177d62b00eSchristos {
1187d62b00eSchristos   /* A switch statement would make sense but would require special
1197d62b00eSchristos      kludges to deal with the cases where more than one signal has the
1207d62b00eSchristos      same number.  Signals are ordered ANSI-standard signals first,
1217d62b00eSchristos      other signals second, with signals in each block ordered by their
1227d62b00eSchristos      numerical values on a typical POSIX platform.  */
1237d62b00eSchristos 
1247d62b00eSchristos   if (hostsig == 0)
1257d62b00eSchristos     return GDB_SIGNAL_0;
1267d62b00eSchristos 
1277d62b00eSchristos   /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
1287d62b00eSchristos      are ANSI-standard signals and are always available.  */
1297d62b00eSchristos   if (hostsig == SIGINT)
1307d62b00eSchristos     return GDB_SIGNAL_INT;
1317d62b00eSchristos   if (hostsig == SIGILL)
1327d62b00eSchristos     return GDB_SIGNAL_ILL;
1337d62b00eSchristos   if (hostsig == SIGABRT)
1347d62b00eSchristos     return GDB_SIGNAL_ABRT;
1357d62b00eSchristos   if (hostsig == SIGFPE)
1367d62b00eSchristos     return GDB_SIGNAL_FPE;
1377d62b00eSchristos   if (hostsig == SIGSEGV)
1387d62b00eSchristos     return GDB_SIGNAL_SEGV;
1397d62b00eSchristos   if (hostsig == SIGTERM)
1407d62b00eSchristos     return GDB_SIGNAL_TERM;
1417d62b00eSchristos 
1427d62b00eSchristos   /* All other signals need preprocessor conditionals.  */
1437d62b00eSchristos #if defined (SIGHUP)
1447d62b00eSchristos   if (hostsig == SIGHUP)
1457d62b00eSchristos     return GDB_SIGNAL_HUP;
1467d62b00eSchristos #endif
1477d62b00eSchristos #if defined (SIGQUIT)
1487d62b00eSchristos   if (hostsig == SIGQUIT)
1497d62b00eSchristos     return GDB_SIGNAL_QUIT;
1507d62b00eSchristos #endif
1517d62b00eSchristos #if defined (SIGTRAP)
1527d62b00eSchristos   if (hostsig == SIGTRAP)
1537d62b00eSchristos     return GDB_SIGNAL_TRAP;
1547d62b00eSchristos #endif
1557d62b00eSchristos #if defined (SIGEMT)
1567d62b00eSchristos   if (hostsig == SIGEMT)
1577d62b00eSchristos     return GDB_SIGNAL_EMT;
1587d62b00eSchristos #endif
1597d62b00eSchristos #if defined (SIGKILL)
1607d62b00eSchristos   if (hostsig == SIGKILL)
1617d62b00eSchristos     return GDB_SIGNAL_KILL;
1627d62b00eSchristos #endif
1637d62b00eSchristos #if defined (SIGBUS)
1647d62b00eSchristos   if (hostsig == SIGBUS)
1657d62b00eSchristos     return GDB_SIGNAL_BUS;
1667d62b00eSchristos #endif
1677d62b00eSchristos #if defined (SIGSYS)
1687d62b00eSchristos   if (hostsig == SIGSYS)
1697d62b00eSchristos     return GDB_SIGNAL_SYS;
1707d62b00eSchristos #endif
1717d62b00eSchristos #if defined (SIGPIPE)
1727d62b00eSchristos   if (hostsig == SIGPIPE)
1737d62b00eSchristos     return GDB_SIGNAL_PIPE;
1747d62b00eSchristos #endif
1757d62b00eSchristos #if defined (SIGALRM)
1767d62b00eSchristos   if (hostsig == SIGALRM)
1777d62b00eSchristos     return GDB_SIGNAL_ALRM;
1787d62b00eSchristos #endif
1797d62b00eSchristos #if defined (SIGUSR1)
1807d62b00eSchristos   if (hostsig == SIGUSR1)
1817d62b00eSchristos     return GDB_SIGNAL_USR1;
1827d62b00eSchristos #endif
1837d62b00eSchristos #if defined (SIGUSR2)
1847d62b00eSchristos   if (hostsig == SIGUSR2)
1857d62b00eSchristos     return GDB_SIGNAL_USR2;
1867d62b00eSchristos #endif
1877d62b00eSchristos #if defined (SIGCLD)
1887d62b00eSchristos   if (hostsig == SIGCLD)
1897d62b00eSchristos     return GDB_SIGNAL_CHLD;
1907d62b00eSchristos #endif
1917d62b00eSchristos #if defined (SIGCHLD)
1927d62b00eSchristos   if (hostsig == SIGCHLD)
1937d62b00eSchristos     return GDB_SIGNAL_CHLD;
1947d62b00eSchristos #endif
1957d62b00eSchristos #if defined (SIGPWR)
1967d62b00eSchristos   if (hostsig == SIGPWR)
1977d62b00eSchristos     return GDB_SIGNAL_PWR;
1987d62b00eSchristos #endif
1997d62b00eSchristos #if defined (SIGWINCH)
2007d62b00eSchristos   if (hostsig == SIGWINCH)
2017d62b00eSchristos     return GDB_SIGNAL_WINCH;
2027d62b00eSchristos #endif
2037d62b00eSchristos #if defined (SIGURG)
2047d62b00eSchristos   if (hostsig == SIGURG)
2057d62b00eSchristos     return GDB_SIGNAL_URG;
2067d62b00eSchristos #endif
2077d62b00eSchristos #if defined (SIGIO)
2087d62b00eSchristos   if (hostsig == SIGIO)
2097d62b00eSchristos     return GDB_SIGNAL_IO;
2107d62b00eSchristos #endif
2117d62b00eSchristos #if defined (SIGPOLL)
2127d62b00eSchristos   if (hostsig == SIGPOLL)
2137d62b00eSchristos     return GDB_SIGNAL_POLL;
2147d62b00eSchristos #endif
2157d62b00eSchristos #if defined (SIGSTOP)
2167d62b00eSchristos   if (hostsig == SIGSTOP)
2177d62b00eSchristos     return GDB_SIGNAL_STOP;
2187d62b00eSchristos #endif
2197d62b00eSchristos #if defined (SIGTSTP)
2207d62b00eSchristos   if (hostsig == SIGTSTP)
2217d62b00eSchristos     return GDB_SIGNAL_TSTP;
2227d62b00eSchristos #endif
2237d62b00eSchristos #if defined (SIGCONT)
2247d62b00eSchristos   if (hostsig == SIGCONT)
2257d62b00eSchristos     return GDB_SIGNAL_CONT;
2267d62b00eSchristos #endif
2277d62b00eSchristos #if defined (SIGTTIN)
2287d62b00eSchristos   if (hostsig == SIGTTIN)
2297d62b00eSchristos     return GDB_SIGNAL_TTIN;
2307d62b00eSchristos #endif
2317d62b00eSchristos #if defined (SIGTTOU)
2327d62b00eSchristos   if (hostsig == SIGTTOU)
2337d62b00eSchristos     return GDB_SIGNAL_TTOU;
2347d62b00eSchristos #endif
2357d62b00eSchristos #if defined (SIGVTALRM)
2367d62b00eSchristos   if (hostsig == SIGVTALRM)
2377d62b00eSchristos     return GDB_SIGNAL_VTALRM;
2387d62b00eSchristos #endif
2397d62b00eSchristos #if defined (SIGPROF)
2407d62b00eSchristos   if (hostsig == SIGPROF)
2417d62b00eSchristos     return GDB_SIGNAL_PROF;
2427d62b00eSchristos #endif
2437d62b00eSchristos #if defined (SIGXCPU)
2447d62b00eSchristos   if (hostsig == SIGXCPU)
2457d62b00eSchristos     return GDB_SIGNAL_XCPU;
2467d62b00eSchristos #endif
2477d62b00eSchristos #if defined (SIGXFSZ)
2487d62b00eSchristos   if (hostsig == SIGXFSZ)
2497d62b00eSchristos     return GDB_SIGNAL_XFSZ;
2507d62b00eSchristos #endif
2517d62b00eSchristos #if defined (SIGWIND)
2527d62b00eSchristos   if (hostsig == SIGWIND)
2537d62b00eSchristos     return GDB_SIGNAL_WIND;
2547d62b00eSchristos #endif
2557d62b00eSchristos #if defined (SIGPHONE)
2567d62b00eSchristos   if (hostsig == SIGPHONE)
2577d62b00eSchristos     return GDB_SIGNAL_PHONE;
2587d62b00eSchristos #endif
2597d62b00eSchristos #if defined (SIGLOST)
2607d62b00eSchristos   if (hostsig == SIGLOST)
2617d62b00eSchristos     return GDB_SIGNAL_LOST;
2627d62b00eSchristos #endif
2637d62b00eSchristos #if defined (SIGWAITING)
2647d62b00eSchristos   if (hostsig == SIGWAITING)
2657d62b00eSchristos     return GDB_SIGNAL_WAITING;
2667d62b00eSchristos #endif
2677d62b00eSchristos #if defined (SIGCANCEL)
2687d62b00eSchristos   if (hostsig == SIGCANCEL)
2697d62b00eSchristos     return GDB_SIGNAL_CANCEL;
2707d62b00eSchristos #endif
2717d62b00eSchristos #if defined (SIGLWP)
2727d62b00eSchristos   if (hostsig == SIGLWP)
2737d62b00eSchristos     return GDB_SIGNAL_LWP;
2747d62b00eSchristos #endif
2757d62b00eSchristos #if defined (SIGDANGER)
2767d62b00eSchristos   if (hostsig == SIGDANGER)
2777d62b00eSchristos     return GDB_SIGNAL_DANGER;
2787d62b00eSchristos #endif
2797d62b00eSchristos #if defined (SIGGRANT)
2807d62b00eSchristos   if (hostsig == SIGGRANT)
2817d62b00eSchristos     return GDB_SIGNAL_GRANT;
2827d62b00eSchristos #endif
2837d62b00eSchristos #if defined (SIGRETRACT)
2847d62b00eSchristos   if (hostsig == SIGRETRACT)
2857d62b00eSchristos     return GDB_SIGNAL_RETRACT;
2867d62b00eSchristos #endif
2877d62b00eSchristos #if defined (SIGMSG)
2887d62b00eSchristos   if (hostsig == SIGMSG)
2897d62b00eSchristos     return GDB_SIGNAL_MSG;
2907d62b00eSchristos #endif
2917d62b00eSchristos #if defined (SIGSOUND)
2927d62b00eSchristos   if (hostsig == SIGSOUND)
2937d62b00eSchristos     return GDB_SIGNAL_SOUND;
2947d62b00eSchristos #endif
2957d62b00eSchristos #if defined (SIGSAK)
2967d62b00eSchristos   if (hostsig == SIGSAK)
2977d62b00eSchristos     return GDB_SIGNAL_SAK;
2987d62b00eSchristos #endif
2997d62b00eSchristos #if defined (SIGPRIO)
3007d62b00eSchristos   if (hostsig == SIGPRIO)
3017d62b00eSchristos     return GDB_SIGNAL_PRIO;
3027d62b00eSchristos #endif
3037d62b00eSchristos 
3047d62b00eSchristos   /* Mach exceptions.  Assumes that the values for EXC_ are positive! */
3057d62b00eSchristos #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
3067d62b00eSchristos   if (hostsig == _NSIG + EXC_BAD_ACCESS)
3077d62b00eSchristos     return GDB_EXC_BAD_ACCESS;
3087d62b00eSchristos #endif
3097d62b00eSchristos #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
3107d62b00eSchristos   if (hostsig == _NSIG + EXC_BAD_INSTRUCTION)
3117d62b00eSchristos     return GDB_EXC_BAD_INSTRUCTION;
3127d62b00eSchristos #endif
3137d62b00eSchristos #if defined (EXC_ARITHMETIC) && defined (_NSIG)
3147d62b00eSchristos   if (hostsig == _NSIG + EXC_ARITHMETIC)
3157d62b00eSchristos     return GDB_EXC_ARITHMETIC;
3167d62b00eSchristos #endif
3177d62b00eSchristos #if defined (EXC_EMULATION) && defined (_NSIG)
3187d62b00eSchristos   if (hostsig == _NSIG + EXC_EMULATION)
3197d62b00eSchristos     return GDB_EXC_EMULATION;
3207d62b00eSchristos #endif
3217d62b00eSchristos #if defined (EXC_SOFTWARE) && defined (_NSIG)
3227d62b00eSchristos   if (hostsig == _NSIG + EXC_SOFTWARE)
3237d62b00eSchristos     return GDB_EXC_SOFTWARE;
3247d62b00eSchristos #endif
3257d62b00eSchristos #if defined (EXC_BREAKPOINT) && defined (_NSIG)
3267d62b00eSchristos   if (hostsig == _NSIG + EXC_BREAKPOINT)
3277d62b00eSchristos     return GDB_EXC_BREAKPOINT;
3287d62b00eSchristos #endif
3297d62b00eSchristos 
3307d62b00eSchristos #if defined (SIGINFO)
3317d62b00eSchristos   if (hostsig == SIGINFO)
3327d62b00eSchristos     return GDB_SIGNAL_INFO;
3337d62b00eSchristos #endif
3347d62b00eSchristos #if defined (SIGLIBRT)
3357d62b00eSchristos   if (hostsig == SIGLIBRT)
3367d62b00eSchristos     return GDB_SIGNAL_LIBRT;
3377d62b00eSchristos #endif
3387d62b00eSchristos 
3397d62b00eSchristos #if defined (REALTIME_LO)
3407d62b00eSchristos   if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
3417d62b00eSchristos     {
3427d62b00eSchristos       /* This block of GDB_SIGNAL_REALTIME value is in order.  */
3437d62b00eSchristos       if (33 <= hostsig && hostsig <= 63)
3447d62b00eSchristos 	return (enum gdb_signal)
3457d62b00eSchristos 	  (hostsig - 33 + (int) GDB_SIGNAL_REALTIME_33);
3467d62b00eSchristos       else if (hostsig == 32)
3477d62b00eSchristos 	return GDB_SIGNAL_REALTIME_32;
3487d62b00eSchristos       else if (64 <= hostsig && hostsig <= 127)
3497d62b00eSchristos 	return (enum gdb_signal)
3507d62b00eSchristos 	  (hostsig - 64 + (int) GDB_SIGNAL_REALTIME_64);
3517d62b00eSchristos       else
3527d62b00eSchristos 	error (_("GDB bug: target.c (gdb_signal_from_host): "
3537d62b00eSchristos 	       "unrecognized real-time signal"));
3547d62b00eSchristos     }
3557d62b00eSchristos #endif
3567d62b00eSchristos 
3577d62b00eSchristos   return GDB_SIGNAL_UNKNOWN;
3587d62b00eSchristos }
3597d62b00eSchristos 
3607d62b00eSchristos /* Convert a OURSIG (an enum gdb_signal) to the form used by the
3617d62b00eSchristos    target operating system (refered to as the ``host'') or zero if the
3627d62b00eSchristos    equivalent host signal is not available.  Set/clear OURSIG_OK
3637d62b00eSchristos    accordingly. */
3647d62b00eSchristos 
3657d62b00eSchristos static int
3667d62b00eSchristos do_gdb_signal_to_host (enum gdb_signal oursig,
3677d62b00eSchristos 			  int *oursig_ok)
3687d62b00eSchristos {
3697d62b00eSchristos   int retsig;
3707d62b00eSchristos   /* Silence the 'not used' warning, for targets that
3717d62b00eSchristos      do not support signals.  */
3727d62b00eSchristos   (void) retsig;
3737d62b00eSchristos 
3747d62b00eSchristos   /* Signals are ordered ANSI-standard signals first, other signals
3757d62b00eSchristos      second, with signals in each block ordered by their numerical
3767d62b00eSchristos      values on a typical POSIX platform.  */
3777d62b00eSchristos 
3787d62b00eSchristos   *oursig_ok = 1;
3797d62b00eSchristos   switch (oursig)
3807d62b00eSchristos     {
3817d62b00eSchristos     case GDB_SIGNAL_0:
3827d62b00eSchristos       return 0;
3837d62b00eSchristos 
3847d62b00eSchristos       /* SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV and SIGTERM
3857d62b00eSchristos 	 are ANSI-standard signals and are always available.  */
3867d62b00eSchristos     case GDB_SIGNAL_INT:
3877d62b00eSchristos       return SIGINT;
3887d62b00eSchristos     case GDB_SIGNAL_ILL:
3897d62b00eSchristos       return SIGILL;
3907d62b00eSchristos     case GDB_SIGNAL_ABRT:
3917d62b00eSchristos       return SIGABRT;
3927d62b00eSchristos     case GDB_SIGNAL_FPE:
3937d62b00eSchristos       return SIGFPE;
3947d62b00eSchristos     case GDB_SIGNAL_SEGV:
3957d62b00eSchristos       return SIGSEGV;
3967d62b00eSchristos     case GDB_SIGNAL_TERM:
3977d62b00eSchristos       return SIGTERM;
3987d62b00eSchristos 
3997d62b00eSchristos       /* All other signals need preprocessor conditionals.  */
4007d62b00eSchristos #if defined (SIGHUP)
4017d62b00eSchristos     case GDB_SIGNAL_HUP:
4027d62b00eSchristos       return SIGHUP;
4037d62b00eSchristos #endif
4047d62b00eSchristos #if defined (SIGQUIT)
4057d62b00eSchristos     case GDB_SIGNAL_QUIT:
4067d62b00eSchristos       return SIGQUIT;
4077d62b00eSchristos #endif
4087d62b00eSchristos #if defined (SIGTRAP)
4097d62b00eSchristos     case GDB_SIGNAL_TRAP:
4107d62b00eSchristos       return SIGTRAP;
4117d62b00eSchristos #endif
4127d62b00eSchristos #if defined (SIGEMT)
4137d62b00eSchristos     case GDB_SIGNAL_EMT:
4147d62b00eSchristos       return SIGEMT;
4157d62b00eSchristos #endif
4167d62b00eSchristos #if defined (SIGKILL)
4177d62b00eSchristos     case GDB_SIGNAL_KILL:
4187d62b00eSchristos       return SIGKILL;
4197d62b00eSchristos #endif
4207d62b00eSchristos #if defined (SIGBUS)
4217d62b00eSchristos     case GDB_SIGNAL_BUS:
4227d62b00eSchristos       return SIGBUS;
4237d62b00eSchristos #endif
4247d62b00eSchristos #if defined (SIGSYS)
4257d62b00eSchristos     case GDB_SIGNAL_SYS:
4267d62b00eSchristos       return SIGSYS;
4277d62b00eSchristos #endif
4287d62b00eSchristos #if defined (SIGPIPE)
4297d62b00eSchristos     case GDB_SIGNAL_PIPE:
4307d62b00eSchristos       return SIGPIPE;
4317d62b00eSchristos #endif
4327d62b00eSchristos #if defined (SIGALRM)
4337d62b00eSchristos     case GDB_SIGNAL_ALRM:
4347d62b00eSchristos       return SIGALRM;
4357d62b00eSchristos #endif
4367d62b00eSchristos #if defined (SIGUSR1)
4377d62b00eSchristos     case GDB_SIGNAL_USR1:
4387d62b00eSchristos       return SIGUSR1;
4397d62b00eSchristos #endif
4407d62b00eSchristos #if defined (SIGUSR2)
4417d62b00eSchristos     case GDB_SIGNAL_USR2:
4427d62b00eSchristos       return SIGUSR2;
4437d62b00eSchristos #endif
4447d62b00eSchristos #if defined (SIGCHLD) || defined (SIGCLD)
4457d62b00eSchristos     case GDB_SIGNAL_CHLD:
4467d62b00eSchristos #if defined (SIGCHLD)
4477d62b00eSchristos       return SIGCHLD;
4487d62b00eSchristos #else
4497d62b00eSchristos       return SIGCLD;
4507d62b00eSchristos #endif
4517d62b00eSchristos #endif /* SIGCLD or SIGCHLD */
4527d62b00eSchristos #if defined (SIGPWR)
4537d62b00eSchristos     case GDB_SIGNAL_PWR:
4547d62b00eSchristos       return SIGPWR;
4557d62b00eSchristos #endif
4567d62b00eSchristos #if defined (SIGWINCH)
4577d62b00eSchristos     case GDB_SIGNAL_WINCH:
4587d62b00eSchristos       return SIGWINCH;
4597d62b00eSchristos #endif
4607d62b00eSchristos #if defined (SIGURG)
4617d62b00eSchristos     case GDB_SIGNAL_URG:
4627d62b00eSchristos       return SIGURG;
4637d62b00eSchristos #endif
4647d62b00eSchristos #if defined (SIGIO)
4657d62b00eSchristos     case GDB_SIGNAL_IO:
4667d62b00eSchristos       return SIGIO;
4677d62b00eSchristos #endif
4687d62b00eSchristos #if defined (SIGPOLL)
4697d62b00eSchristos     case GDB_SIGNAL_POLL:
4707d62b00eSchristos       return SIGPOLL;
4717d62b00eSchristos #endif
4727d62b00eSchristos #if defined (SIGSTOP)
4737d62b00eSchristos     case GDB_SIGNAL_STOP:
4747d62b00eSchristos       return SIGSTOP;
4757d62b00eSchristos #endif
4767d62b00eSchristos #if defined (SIGTSTP)
4777d62b00eSchristos     case GDB_SIGNAL_TSTP:
4787d62b00eSchristos       return SIGTSTP;
4797d62b00eSchristos #endif
4807d62b00eSchristos #if defined (SIGCONT)
4817d62b00eSchristos     case GDB_SIGNAL_CONT:
4827d62b00eSchristos       return SIGCONT;
4837d62b00eSchristos #endif
4847d62b00eSchristos #if defined (SIGTTIN)
4857d62b00eSchristos     case GDB_SIGNAL_TTIN:
4867d62b00eSchristos       return SIGTTIN;
4877d62b00eSchristos #endif
4887d62b00eSchristos #if defined (SIGTTOU)
4897d62b00eSchristos     case GDB_SIGNAL_TTOU:
4907d62b00eSchristos       return SIGTTOU;
4917d62b00eSchristos #endif
4927d62b00eSchristos #if defined (SIGVTALRM)
4937d62b00eSchristos     case GDB_SIGNAL_VTALRM:
4947d62b00eSchristos       return SIGVTALRM;
4957d62b00eSchristos #endif
4967d62b00eSchristos #if defined (SIGPROF)
4977d62b00eSchristos     case GDB_SIGNAL_PROF:
4987d62b00eSchristos       return SIGPROF;
4997d62b00eSchristos #endif
5007d62b00eSchristos #if defined (SIGXCPU)
5017d62b00eSchristos     case GDB_SIGNAL_XCPU:
5027d62b00eSchristos       return SIGXCPU;
5037d62b00eSchristos #endif
5047d62b00eSchristos #if defined (SIGXFSZ)
5057d62b00eSchristos     case GDB_SIGNAL_XFSZ:
5067d62b00eSchristos       return SIGXFSZ;
5077d62b00eSchristos #endif
5087d62b00eSchristos #if defined (SIGWIND)
5097d62b00eSchristos     case GDB_SIGNAL_WIND:
5107d62b00eSchristos       return SIGWIND;
5117d62b00eSchristos #endif
5127d62b00eSchristos #if defined (SIGPHONE)
5137d62b00eSchristos     case GDB_SIGNAL_PHONE:
5147d62b00eSchristos       return SIGPHONE;
5157d62b00eSchristos #endif
5167d62b00eSchristos #if defined (SIGLOST)
5177d62b00eSchristos     case GDB_SIGNAL_LOST:
5187d62b00eSchristos       return SIGLOST;
5197d62b00eSchristos #endif
5207d62b00eSchristos #if defined (SIGWAITING)
5217d62b00eSchristos     case GDB_SIGNAL_WAITING:
5227d62b00eSchristos       return SIGWAITING;
5237d62b00eSchristos #endif
5247d62b00eSchristos #if defined (SIGCANCEL)
5257d62b00eSchristos     case GDB_SIGNAL_CANCEL:
5267d62b00eSchristos       return SIGCANCEL;
5277d62b00eSchristos #endif
5287d62b00eSchristos #if defined (SIGLWP)
5297d62b00eSchristos     case GDB_SIGNAL_LWP:
5307d62b00eSchristos       return SIGLWP;
5317d62b00eSchristos #endif
5327d62b00eSchristos #if defined (SIGDANGER)
5337d62b00eSchristos     case GDB_SIGNAL_DANGER:
5347d62b00eSchristos       return SIGDANGER;
5357d62b00eSchristos #endif
5367d62b00eSchristos #if defined (SIGGRANT)
5377d62b00eSchristos     case GDB_SIGNAL_GRANT:
5387d62b00eSchristos       return SIGGRANT;
5397d62b00eSchristos #endif
5407d62b00eSchristos #if defined (SIGRETRACT)
5417d62b00eSchristos     case GDB_SIGNAL_RETRACT:
5427d62b00eSchristos       return SIGRETRACT;
5437d62b00eSchristos #endif
5447d62b00eSchristos #if defined (SIGMSG)
5457d62b00eSchristos     case GDB_SIGNAL_MSG:
5467d62b00eSchristos       return SIGMSG;
5477d62b00eSchristos #endif
5487d62b00eSchristos #if defined (SIGSOUND)
5497d62b00eSchristos     case GDB_SIGNAL_SOUND:
5507d62b00eSchristos       return SIGSOUND;
5517d62b00eSchristos #endif
5527d62b00eSchristos #if defined (SIGSAK)
5537d62b00eSchristos     case GDB_SIGNAL_SAK:
5547d62b00eSchristos       return SIGSAK;
5557d62b00eSchristos #endif
5567d62b00eSchristos #if defined (SIGPRIO)
5577d62b00eSchristos     case GDB_SIGNAL_PRIO:
5587d62b00eSchristos       return SIGPRIO;
5597d62b00eSchristos #endif
5607d62b00eSchristos 
5617d62b00eSchristos       /* Mach exceptions.  Assumes that the values for EXC_ are positive! */
5627d62b00eSchristos #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
5637d62b00eSchristos     case GDB_EXC_BAD_ACCESS:
5647d62b00eSchristos       return _NSIG + EXC_BAD_ACCESS;
5657d62b00eSchristos #endif
5667d62b00eSchristos #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
5677d62b00eSchristos     case GDB_EXC_BAD_INSTRUCTION:
5687d62b00eSchristos       return _NSIG + EXC_BAD_INSTRUCTION;
5697d62b00eSchristos #endif
5707d62b00eSchristos #if defined (EXC_ARITHMETIC) && defined (_NSIG)
5717d62b00eSchristos     case GDB_EXC_ARITHMETIC:
5727d62b00eSchristos       return _NSIG + EXC_ARITHMETIC;
5737d62b00eSchristos #endif
5747d62b00eSchristos #if defined (EXC_EMULATION) && defined (_NSIG)
5757d62b00eSchristos     case GDB_EXC_EMULATION:
5767d62b00eSchristos       return _NSIG + EXC_EMULATION;
5777d62b00eSchristos #endif
5787d62b00eSchristos #if defined (EXC_SOFTWARE) && defined (_NSIG)
5797d62b00eSchristos     case GDB_EXC_SOFTWARE:
5807d62b00eSchristos       return _NSIG + EXC_SOFTWARE;
5817d62b00eSchristos #endif
5827d62b00eSchristos #if defined (EXC_BREAKPOINT) && defined (_NSIG)
5837d62b00eSchristos     case GDB_EXC_BREAKPOINT:
5847d62b00eSchristos       return _NSIG + EXC_BREAKPOINT;
5857d62b00eSchristos #endif
5867d62b00eSchristos 
5877d62b00eSchristos #if defined (SIGINFO)
5887d62b00eSchristos     case GDB_SIGNAL_INFO:
5897d62b00eSchristos       return SIGINFO;
5907d62b00eSchristos #endif
5917d62b00eSchristos #if defined (SIGLIBRT)
5927d62b00eSchristos     case GDB_SIGNAL_LIBRT:
5937d62b00eSchristos       return SIGLIBRT;
5947d62b00eSchristos #endif
5957d62b00eSchristos 
5967d62b00eSchristos     default:
5977d62b00eSchristos #if defined (REALTIME_LO)
5987d62b00eSchristos       retsig = 0;
5997d62b00eSchristos 
6007d62b00eSchristos       if (oursig >= GDB_SIGNAL_REALTIME_33
6017d62b00eSchristos 	  && oursig <= GDB_SIGNAL_REALTIME_63)
6027d62b00eSchristos 	{
6037d62b00eSchristos 	  /* This block of signals is continuous, and
6047d62b00eSchristos 	     GDB_SIGNAL_REALTIME_33 is 33 by definition.  */
6057d62b00eSchristos 	  retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_33 + 33;
6067d62b00eSchristos 	}
6077d62b00eSchristos       else if (oursig == GDB_SIGNAL_REALTIME_32)
6087d62b00eSchristos 	{
6097d62b00eSchristos 	  /* GDB_SIGNAL_REALTIME_32 isn't contiguous with
6107d62b00eSchristos 	     GDB_SIGNAL_REALTIME_33.  It is 32 by definition.  */
6117d62b00eSchristos 	  retsig = 32;
6127d62b00eSchristos 	}
6137d62b00eSchristos       else if (oursig >= GDB_SIGNAL_REALTIME_64
6147d62b00eSchristos 	  && oursig <= GDB_SIGNAL_REALTIME_127)
6157d62b00eSchristos 	{
6167d62b00eSchristos 	  /* This block of signals is continuous, and
6177d62b00eSchristos 	     GDB_SIGNAL_REALTIME_64 is 64 by definition.  */
6187d62b00eSchristos 	  retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_64 + 64;
6197d62b00eSchristos 	}
6207d62b00eSchristos 
6217d62b00eSchristos       if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
6227d62b00eSchristos 	return retsig;
6237d62b00eSchristos #endif
6247d62b00eSchristos 
6257d62b00eSchristos       *oursig_ok = 0;
6267d62b00eSchristos       return 0;
6277d62b00eSchristos     }
6287d62b00eSchristos }
6297d62b00eSchristos 
6307d62b00eSchristos int
6317d62b00eSchristos gdb_signal_to_host_p (enum gdb_signal oursig)
6327d62b00eSchristos {
6337d62b00eSchristos   int oursig_ok;
6347d62b00eSchristos   do_gdb_signal_to_host (oursig, &oursig_ok);
6357d62b00eSchristos   return oursig_ok;
6367d62b00eSchristos }
6377d62b00eSchristos 
6387d62b00eSchristos int
6397d62b00eSchristos gdb_signal_to_host (enum gdb_signal oursig)
6407d62b00eSchristos {
6417d62b00eSchristos   int oursig_ok;
6427d62b00eSchristos   int targ_signo = do_gdb_signal_to_host (oursig, &oursig_ok);
6437d62b00eSchristos   if (!oursig_ok)
6447d62b00eSchristos     {
6457d62b00eSchristos       /* The user might be trying to do "signal SIGSAK" where this system
6467d62b00eSchristos 	 doesn't have SIGSAK.  */
6477d62b00eSchristos       warning (_("Signal %s does not exist on this system."),
6487d62b00eSchristos 	       gdb_signal_to_name (oursig));
6497d62b00eSchristos       return 0;
6507d62b00eSchristos     }
6517d62b00eSchristos   else
6527d62b00eSchristos     return targ_signo;
6537d62b00eSchristos }
654