Add signal number conversions for NetBSD

Message ID 20200406102755.9148-1-n54@gmx.com
State New
Headers show
Series
  • Add signal number conversions for NetBSD
Related show

Commit Message

Kamil Rytarowski April 6, 2020, 10:27 a.m.
gdb/ChangeLog:

	* nbsd-tdep.c: Include "gdbarch.h".
	Define enum with NetBSD signal numbers.
	(nbsd_gdb_signal_from_target, nbsd_gdb_signal_to_target): New.
	* alpha-nbsd-tdep.c (alphanbsd_init_abi): Call nbsd_init_abi().
	* amd64-nbsd-tdep.c (amd64nbsd_init_abi): Likewise.
	* arm-nbsd-tdep.c (arm_netbsd_elf_init_abi): Likewise.
	* hppa-nbsd-tdep.c (hppanbsd_init_abi): Likewise.
	* i386-nbsd-tdep.c (i386nbsd_init_abi): Likewise.
	* mips-nbsd-tdep.c (nbsd_init_abi): Likewise.
	* ppc-nbsd-tdep.c (ppcnbsd_init_abi): Likewise.
	* sh-nbsd-tdep.c (shnbsd_init_abi): Likewise.
	* sparc-nbsd-tdep.c (sparc32nbsd_init_abi): Likewise.
	* sparc64-nbsd-tdep.c (sparc64nbsd_init_abi): Likewise.
	* vax-nbsd-tdep.c (vaxnbsd_elf_init_abi): Likewise.
---
 gdb/ChangeLog           |  17 +++
 gdb/alpha-nbsd-tdep.c   |   2 +
 gdb/amd64-nbsd-tdep.c   |   1 +
 gdb/arm-nbsd-tdep.c     |   3 +
 gdb/hppa-nbsd-tdep.c    |   2 +
 gdb/i386-nbsd-tdep.c    |   2 +
 gdb/mips-nbsd-tdep.c    |   2 +
 gdb/nbsd-tdep.c         | 300 ++++++++++++++++++++++++++++++++++++++++
 gdb/nbsd-tdep.h         |   4 +
 gdb/ppc-nbsd-tdep.c     |   2 +
 gdb/sh-nbsd-tdep.c      |   1 +
 gdb/sparc-nbsd-tdep.c   |   2 +
 gdb/sparc64-nbsd-tdep.c |   2 +
 gdb/vax-nbsd-tdep.c     |   2 +
 14 files changed, 342 insertions(+)

--
2.25.0

Comments

Tom Tromey April 6, 2020, 2:15 p.m. | #1
>>>>> "Kamil" == Kamil Rytarowski <n54@gmx.com> writes:


Kamil> gdb/ChangeLog:
Kamil> 	* nbsd-tdep.c: Include "gdbarch.h".
Kamil> 	Define enum with NetBSD signal numbers.
Kamil> 	(nbsd_gdb_signal_from_target, nbsd_gdb_signal_to_target): New.
Kamil> 	* alpha-nbsd-tdep.c (alphanbsd_init_abi): Call nbsd_init_abi().
Kamil> 	* amd64-nbsd-tdep.c (amd64nbsd_init_abi): Likewise.
Kamil> 	* arm-nbsd-tdep.c (arm_netbsd_elf_init_abi): Likewise.
Kamil> 	* hppa-nbsd-tdep.c (hppanbsd_init_abi): Likewise.
Kamil> 	* i386-nbsd-tdep.c (i386nbsd_init_abi): Likewise.
Kamil> 	* mips-nbsd-tdep.c (nbsd_init_abi): Likewise.
Kamil> 	* ppc-nbsd-tdep.c (ppcnbsd_init_abi): Likewise.
Kamil> 	* sh-nbsd-tdep.c (shnbsd_init_abi): Likewise.
Kamil> 	* sparc-nbsd-tdep.c (sparc32nbsd_init_abi): Likewise.
Kamil> 	* sparc64-nbsd-tdep.c (sparc64nbsd_init_abi): Likewise.
Kamil> 	* vax-nbsd-tdep.c (vaxnbsd_elf_init_abi): Likewise.

Looks good to me.  Thank you.

Tom

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 014752e4ddc..b1a965304a4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,20 @@ 
+2020-04-06  Kamil Rytarowski  <n54@gmx.com>
+
+	* nbsd-tdep.c: Include "gdbarch.h".
+	Define enum with NetBSD signal numbers.
+	(nbsd_gdb_signal_from_target, nbsd_gdb_signal_to_target): New.
+	* alpha-nbsd-tdep.c (alphanbsd_init_abi): Call nbsd_init_abi().
+	* amd64-nbsd-tdep.c (amd64nbsd_init_abi): Likewise.
+	* arm-nbsd-tdep.c (arm_netbsd_elf_init_abi): Likewise.
+	* hppa-nbsd-tdep.c (hppanbsd_init_abi): Likewise.
+	* i386-nbsd-tdep.c (i386nbsd_init_abi): Likewise.
+	* mips-nbsd-tdep.c (nbsd_init_abi): Likewise.
+	* ppc-nbsd-tdep.c (ppcnbsd_init_abi): Likewise.
+	* sh-nbsd-tdep.c (shnbsd_init_abi): Likewise.
+	* sparc-nbsd-tdep.c (sparc32nbsd_init_abi): Likewise.
+	* sparc64-nbsd-tdep.c (sparc64nbsd_init_abi): Likewise.
+	* vax-nbsd-tdep.c (vaxnbsd_elf_init_abi): Likewise.
+
 2020-04-03  Hannes Domani  <ssbssa@yahoo.de>

 	PR gdb/25325
diff --git a/gdb/alpha-nbsd-tdep.c b/gdb/alpha-nbsd-tdep.c
index ab9240e35da..58294edb3f6 100644
--- a/gdb/alpha-nbsd-tdep.c
+++ b/gdb/alpha-nbsd-tdep.c
@@ -258,6 +258,8 @@  alphanbsd_init_abi (struct gdbarch_info info,
   /* Hook into the MDEBUG frame unwinder.  */
   alpha_mdebug_init_abi (info, gdbarch);

+  nbsd_init_abi (info, gdbarch);
+
   /* NetBSD/alpha does not provide single step support via ptrace(2); we
      must use software single-stepping.  */
   set_gdbarch_software_single_step (gdbarch, alpha_software_single_step);
diff --git a/gdb/amd64-nbsd-tdep.c b/gdb/amd64-nbsd-tdep.c
index 89d07236b85..59071488ed7 100644
--- a/gdb/amd64-nbsd-tdep.c
+++ b/gdb/amd64-nbsd-tdep.c
@@ -106,6 +106,7 @@  amd64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)

   amd64_init_abi (info, gdbarch,
 		  amd64_target_description (X86_XSTATE_SSE_MASK, true));
+  nbsd_init_abi (info, gdbarch);

   tdep->jb_pc_offset = 7 * 8;

diff --git a/gdb/arm-nbsd-tdep.c b/gdb/arm-nbsd-tdep.c
index e01df50bc25..a6104f760b3 100644
--- a/gdb/arm-nbsd-tdep.c
+++ b/gdb/arm-nbsd-tdep.c
@@ -150,6 +150,9 @@  arm_netbsd_elf_init_abi (struct gdbarch_info info,
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

   arm_netbsd_init_abi_common (info, gdbarch);
+
+  nbsd_init_abi (info, gdbarch);
+
   if (tdep->fp_model == ARM_FLOAT_AUTO)
     tdep->fp_model = ARM_FLOAT_SOFT_VFP;

diff --git a/gdb/hppa-nbsd-tdep.c b/gdb/hppa-nbsd-tdep.c
index b532ab1d5cc..d601aa96f3f 100644
--- a/gdb/hppa-nbsd-tdep.c
+++ b/gdb/hppa-nbsd-tdep.c
@@ -201,6 +201,8 @@  hppanbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Obviously NetBSD is BSD-based.  */
   hppabsd_init_abi (info, gdbarch);

+  nbsd_init_abi (info, gdbarch);
+
   /* Core file support.  */
   set_gdbarch_iterate_over_regset_sections
     (gdbarch, hppanbsd_iterate_over_regset_sections);
diff --git a/gdb/i386-nbsd-tdep.c b/gdb/i386-nbsd-tdep.c
index 3157451e08f..f350412d9bd 100644
--- a/gdb/i386-nbsd-tdep.c
+++ b/gdb/i386-nbsd-tdep.c
@@ -377,6 +377,8 @@  i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   /* Obviously NetBSD is BSD-based.  */
   i386bsd_init_abi (info, gdbarch);

+  nbsd_init_abi (info, gdbarch);
+
   /* NetBSD has a different `struct reg'.  */
   tdep->gregset_reg_offset = i386nbsd_r_reg_offset;
   tdep->gregset_num_regs = ARRAY_SIZE (i386nbsd_r_reg_offset);
diff --git a/gdb/mips-nbsd-tdep.c b/gdb/mips-nbsd-tdep.c
index 38bc7ce636b..6f4d22b24fb 100644
--- a/gdb/mips-nbsd-tdep.c
+++ b/gdb/mips-nbsd-tdep.c
@@ -354,6 +354,8 @@  static void
 mipsnbsd_init_abi (struct gdbarch_info info,
                    struct gdbarch *gdbarch)
 {
+  nbsd_init_abi (info, gdbarch)
+
   set_gdbarch_iterate_over_regset_sections
     (gdbarch, mipsnbsd_iterate_over_regset_sections);

diff --git a/gdb/nbsd-tdep.c b/gdb/nbsd-tdep.c
index 49bb2b706bd..6680d3c6fde 100644
--- a/gdb/nbsd-tdep.c
+++ b/gdb/nbsd-tdep.c
@@ -22,6 +22,7 @@ 
 #include "defs.h"
 #include "solib-svr4.h"
 #include "nbsd-tdep.h"
+#include "gdbarch.h"

 /* FIXME: kettenis/20060115: We should really eliminate the next two
    functions completely.  */
@@ -47,3 +48,302 @@  nbsd_pc_in_sigtramp (CORE_ADDR pc, const char *func_name)
   return (func_name != NULL
 	  && startswith (func_name, "__sigtramp"));
 }
+
+/* This enum is derived from NETBSD's <sys/signal.h>.  */
+
+enum
+  {
+   NBSD_SIGHUP = 1,
+   NBSD_SIGINT = 2,
+   NBSD_SIGQUIT = 3,
+   NBSD_SIGILL = 4,
+   NBSD_SIGTRAP = 5,
+   NBSD_SIGABRT = 6,
+   NBSD_SIGEMT = 7,
+   NBSD_SIGFPE = 8,
+   NBSD_SIGKILL = 9,
+   NBSD_SIGBUS = 10,
+   NBSD_SIGSEGV = 11,
+   NBSD_SIGSYS = 12,
+   NBSD_SIGPIPE = 13,
+   NBSD_SIGALRM = 14,
+   NBSD_SIGTERM = 15,
+   NBSD_SIGURG = 16,
+   NBSD_SIGSTOP = 17,
+   NBSD_SIGTSTP = 18,
+   NBSD_SIGCONT = 19,
+   NBSD_SIGCHLD = 20,
+   NBSD_SIGTTIN = 21,
+   NBSD_SIGTTOU = 22,
+   NBSD_SIGIO = 23,
+   NBSD_SIGXCPU = 24,
+   NBSD_SIGXFSZ = 25,
+   NBSD_SIGVTALRM = 26,
+   NBSD_SIGPROF = 27,
+   NBSD_SIGWINCH = 28,
+   NBSD_SIGINFO = 29,
+   NBSD_SIGUSR1 = 30,
+   NBSD_SIGUSR2 = 31,
+   NBSD_SIGPWR = 32,
+   NBSD_SIGRTMIN = 33,
+   NBSD_SIGRTMAX = 63,
+  };
+
+/* Implement the "gdb_signal_from_target" gdbarch method.  */
+
+static enum gdb_signal
+nbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
+{
+  switch (signal)
+    {
+    case 0:
+      return GDB_SIGNAL_0;
+
+    case NBSD_SIGHUP:
+      return GDB_SIGNAL_HUP;
+
+    case NBSD_SIGINT:
+      return GDB_SIGNAL_INT;
+
+    case NBSD_SIGQUIT:
+      return GDB_SIGNAL_QUIT;
+
+    case NBSD_SIGILL:
+      return GDB_SIGNAL_ILL;
+
+    case NBSD_SIGTRAP:
+      return GDB_SIGNAL_TRAP;
+
+    case NBSD_SIGABRT:
+      return GDB_SIGNAL_ABRT;
+
+    case NBSD_SIGEMT:
+      return GDB_SIGNAL_EMT;
+
+    case NBSD_SIGFPE:
+      return GDB_SIGNAL_FPE;
+
+    case NBSD_SIGKILL:
+      return GDB_SIGNAL_KILL;
+
+    case NBSD_SIGBUS:
+      return GDB_SIGNAL_BUS;
+
+    case NBSD_SIGSEGV:
+      return GDB_SIGNAL_SEGV;
+
+    case NBSD_SIGSYS:
+      return GDB_SIGNAL_SYS;
+
+    case NBSD_SIGPIPE:
+      return GDB_SIGNAL_PIPE;
+
+    case NBSD_SIGALRM:
+      return GDB_SIGNAL_ALRM;
+
+    case NBSD_SIGTERM:
+      return GDB_SIGNAL_TERM;
+
+    case NBSD_SIGURG:
+      return GDB_SIGNAL_URG;
+
+    case NBSD_SIGSTOP:
+      return GDB_SIGNAL_STOP;
+
+    case NBSD_SIGTSTP:
+      return GDB_SIGNAL_TSTP;
+
+    case NBSD_SIGCONT:
+      return GDB_SIGNAL_CONT;
+
+    case NBSD_SIGCHLD:
+      return GDB_SIGNAL_CHLD;
+
+    case NBSD_SIGTTIN:
+      return GDB_SIGNAL_TTIN;
+
+    case NBSD_SIGTTOU:
+      return GDB_SIGNAL_TTOU;
+
+    case NBSD_SIGIO:
+      return GDB_SIGNAL_IO;
+
+    case NBSD_SIGXCPU:
+      return GDB_SIGNAL_XCPU;
+
+    case NBSD_SIGXFSZ:
+      return GDB_SIGNAL_XFSZ;
+
+    case NBSD_SIGVTALRM:
+      return GDB_SIGNAL_VTALRM;
+
+    case NBSD_SIGPROF:
+      return GDB_SIGNAL_PROF;
+
+    case NBSD_SIGWINCH:
+      return GDB_SIGNAL_WINCH;
+
+    case NBSD_SIGINFO:
+      return GDB_SIGNAL_INFO;
+
+    case NBSD_SIGUSR1:
+      return GDB_SIGNAL_USR1;
+
+    case NBSD_SIGUSR2:
+      return GDB_SIGNAL_USR2;
+
+    case NBSD_SIGPWR:
+      return GDB_SIGNAL_PWR;
+
+    /* SIGRTMIN and SIGRTMAX are not continuous in <gdb/signals.def>,
+       therefore we have to handle them here.  */
+    case NBSD_SIGRTMIN:
+      return GDB_SIGNAL_REALTIME_33;
+
+    case NBSD_SIGRTMAX:
+      return GDB_SIGNAL_REALTIME_63;
+    }
+
+  if (signal >= NBSD_SIGRTMIN + 1 && signal <= NBSD_SIGRTMAX - 1)
+    {
+      int offset = signal - NBSD_SIGRTMIN + 1;
+
+      return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_34 + offset);
+    }
+
+  return GDB_SIGNAL_UNKNOWN;
+}
+
+/* Implement the "gdb_signal_to_target" gdbarch method.  */
+
+static int
+nbsd_gdb_signal_to_target (struct gdbarch *gdbarch,
+                enum gdb_signal signal)
+{
+  switch (signal)
+    {
+    case GDB_SIGNAL_0:
+      return 0;
+
+    case GDB_SIGNAL_HUP:
+      return NBSD_SIGHUP;
+
+    case GDB_SIGNAL_INT:
+      return NBSD_SIGINT;
+
+    case GDB_SIGNAL_QUIT:
+      return NBSD_SIGQUIT;
+
+    case GDB_SIGNAL_ILL:
+      return NBSD_SIGILL;
+
+    case GDB_SIGNAL_TRAP:
+      return NBSD_SIGTRAP;
+
+    case GDB_SIGNAL_ABRT:
+      return NBSD_SIGABRT;
+
+    case GDB_SIGNAL_EMT:
+      return NBSD_SIGEMT;
+
+    case GDB_SIGNAL_FPE:
+      return NBSD_SIGFPE;
+
+    case GDB_SIGNAL_KILL:
+      return NBSD_SIGKILL;
+
+    case GDB_SIGNAL_BUS:
+      return NBSD_SIGBUS;
+
+    case GDB_SIGNAL_SEGV:
+      return NBSD_SIGSEGV;
+
+    case GDB_SIGNAL_SYS:
+      return NBSD_SIGSYS;
+
+    case GDB_SIGNAL_PIPE:
+      return NBSD_SIGPIPE;
+
+    case GDB_SIGNAL_ALRM:
+      return NBSD_SIGALRM;
+
+    case GDB_SIGNAL_TERM:
+      return NBSD_SIGTERM;
+
+    case GDB_SIGNAL_URG:
+      return NBSD_SIGSTOP;
+
+    case GDB_SIGNAL_TSTP:
+      return NBSD_SIGTSTP;
+
+    case GDB_SIGNAL_CONT:
+      return NBSD_SIGCONT;
+
+    case GDB_SIGNAL_CHLD:
+      return NBSD_SIGCHLD;
+
+    case GDB_SIGNAL_TTIN:
+      return NBSD_SIGTTIN;
+
+    case GDB_SIGNAL_TTOU:
+      return NBSD_SIGTTOU;
+
+    case GDB_SIGNAL_IO:
+      return NBSD_SIGIO;
+
+    case GDB_SIGNAL_XCPU:
+      return NBSD_SIGXCPU;
+
+    case GDB_SIGNAL_XFSZ:
+      return NBSD_SIGXFSZ;
+
+    case GDB_SIGNAL_VTALRM:
+      return NBSD_SIGVTALRM;
+
+    case GDB_SIGNAL_PROF:
+      return NBSD_SIGPROF;
+
+    case GDB_SIGNAL_WINCH:
+      return NBSD_SIGWINCH;
+
+    case GDB_SIGNAL_INFO:
+      return NBSD_SIGINFO;
+
+    case GDB_SIGNAL_USR1:
+      return NBSD_SIGUSR1;
+
+    case GDB_SIGNAL_USR2:
+      return NBSD_SIGUSR2;
+
+    case GDB_SIGNAL_PWR:
+      return NBSD_SIGPWR;
+
+    /* GDB_SIGNAL_REALTIME_33 is not continuous in <gdb/signals.def>,
+       therefore we have to handle it here.  */
+    case GDB_SIGNAL_REALTIME_33:
+      return NBSD_SIGRTMIN;
+
+    /* Same comment applies to _64.  */
+    case GDB_SIGNAL_REALTIME_63:
+      return NBSD_SIGRTMAX;
+    }
+
+  if (signal >= GDB_SIGNAL_REALTIME_34
+      && signal <= GDB_SIGNAL_REALTIME_62)
+    {
+      int offset = signal - GDB_SIGNAL_REALTIME_32;
+
+      return NBSD_SIGRTMIN + 1 + offset;
+    }
+
+  return -1;
+}
+
+/* See nbsd-tdep.h.  */
+
+void
+nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+  set_gdbarch_gdb_signal_from_target (gdbarch, nbsd_gdb_signal_from_target);
+  set_gdbarch_gdb_signal_to_target (gdbarch, nbsd_gdb_signal_to_target);
+}
diff --git a/gdb/nbsd-tdep.h b/gdb/nbsd-tdep.h
index c99a8b537b6..4b06c13f87b 100644
--- a/gdb/nbsd-tdep.h
+++ b/gdb/nbsd-tdep.h
@@ -25,4 +25,8 @@  struct link_map_offsets *nbsd_lp64_solib_svr4_fetch_link_map_offsets (void);

 int nbsd_pc_in_sigtramp (CORE_ADDR, const char *);

+/* NetBSD specific set of ABI-related routines.  */
+
+void nbsd_init_abi (struct gdbarch_info, struct gdbarch *);
+
 #endif /* NBSD_TDEP_H */
diff --git a/gdb/ppc-nbsd-tdep.c b/gdb/ppc-nbsd-tdep.c
index d75930c9f8d..81492deaccd 100644
--- a/gdb/ppc-nbsd-tdep.c
+++ b/gdb/ppc-nbsd-tdep.c
@@ -173,6 +173,8 @@  static void
 ppcnbsd_init_abi (struct gdbarch_info info,
                   struct gdbarch *gdbarch)
 {
+  nbsd_init_abi (info, gdbarch);
+
   /* For NetBSD, this is an on again, off again thing.  Some systems
      do use the broken struct convention, and some don't.  */
   set_gdbarch_return_value (gdbarch, ppcnbsd_return_value);
diff --git a/gdb/sh-nbsd-tdep.c b/gdb/sh-nbsd-tdep.c
index aa319261684..2b2a7e3fd4a 100644
--- a/gdb/sh-nbsd-tdep.c
+++ b/gdb/sh-nbsd-tdep.c
@@ -63,6 +63,7 @@  shnbsd_init_abi (struct gdbarch_info info,
                   struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+  nbsd_init_abi (info, gdbarch);

   tdep->core_gregmap = (struct sh_corefile_regmap *)regmap;
   tdep->sizeof_gregset = 84;
diff --git a/gdb/sparc-nbsd-tdep.c b/gdb/sparc-nbsd-tdep.c
index 7aba6020d27..ab1b557c57c 100644
--- a/gdb/sparc-nbsd-tdep.c
+++ b/gdb/sparc-nbsd-tdep.c
@@ -296,6 +296,8 @@  sparc32nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

+  nbsd_init_abi (info, gdbarch);
+
   /* NetBSD doesn't support the 128-bit `long double' from the psABI.  */
   set_gdbarch_long_double_bit (gdbarch, 64);
   set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
diff --git a/gdb/sparc64-nbsd-tdep.c b/gdb/sparc64-nbsd-tdep.c
index cd5bfe89410..dac7fa78b9b 100644
--- a/gdb/sparc64-nbsd-tdep.c
+++ b/gdb/sparc64-nbsd-tdep.c
@@ -249,6 +249,8 @@  sparc64nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

+  nbsd_init_abi (info, gdbarch);
+
   tdep->gregset = &sparc64nbsd_gregset;
   tdep->sizeof_gregset = 160;

diff --git a/gdb/vax-nbsd-tdep.c b/gdb/vax-nbsd-tdep.c
index c2c08cc1603..7630ac5ab94 100644
--- a/gdb/vax-nbsd-tdep.c
+++ b/gdb/vax-nbsd-tdep.c
@@ -29,6 +29,8 @@ 
 static void
 vaxnbsd_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
+  nbsd_init_abi (info, gdbarch);
+
   /* NetBSD ELF uses SVR4-style shared libraries.  */
   set_solib_svr4_fetch_link_map_offsets
     (gdbarch, svr4_ilp32_fetch_link_map_offsets);