Refactor the NetBSD amd64 gdbserver support
authorKamil Rytarowski <n54@gmx.com>
Wed, 23 Sep 2020 02:26:37 +0000 (04:26 +0200)
committerKamil Rytarowski <n54@gmx.com>
Thu, 1 Oct 2020 22:39:20 +0000 (00:39 +0200)
Replace the pre-C++ construct of netbsd_target_ops, netbsd_regset_info
and netbsd_tdesc with C++ inheritance approach found in the Linux
gdbserver code. Add netbsd_amd64_target, that inherits from the
netbsd_process_target class and add proper singleton object for
the_netbsd_target, initialized from netbsd_amd64_target.

Call low_arch_setup () on post process creation, which sets machine
specific properties of the traced process.

Remove global singleton the_netbsd_target object from the generic
gdbserver code.

This refactoring introduces no functional change from the end-user
point of view.

gdbserver/ChangeLog:

* netbsd-amd64-low.cc (netbsd_x86_64_arch_setup): Remove.
(netbsd_target_regsets): Now const.
(the_low_target): Remove.
(class netbsd_amd64_target, the_netbsd_amd64_target)
(the_netbsd_target): Add.
* netbsd-low.cc (netbsd_process_target::post_create_inferior): Call
low_arch_setup ().
(netbsd_process_target::fetch_registers)
(netbsd_process_target::store_registers, initialize_low): Update.
(the_netbsd_target): Remove.
* netbsd-low.h (netbsd_target_regsets, netbsd_target_ops)
(the_low_target, netbsd_tdesc): Remove.
(netbsd_process_target::get_regs_info)
(netbsd_process_target::low_arch_setup): Add.

gdbserver/ChangeLog
gdbserver/netbsd-amd64-low.cc
gdbserver/netbsd-low.cc
gdbserver/netbsd-low.h

index c97d4b1d28440e53d7449e2cb8e00c798acac8c9..383e3d3d484b6facf4eb1b54ec9ce72363e167d1 100644 (file)
@@ -1,3 +1,20 @@
+2020-10-01  Kamil Rytarowski  <n54@gmx.com>
+
+       * netbsd-amd64-low.cc (netbsd_x86_64_arch_setup): Remove.
+       (netbsd_target_regsets): Now const.
+       (the_low_target): Remove.
+       (class netbsd_amd64_target, the_netbsd_amd64_target)
+       (the_netbsd_target): Add.
+       * netbsd-low.cc (netbsd_process_target::post_create_inferior): Call
+       low_arch_setup ().
+       (netbsd_process_target::fetch_registers)
+       (netbsd_process_target::store_registers, initialize_low): Update.
+       (the_netbsd_target): Remove.
+       * netbsd-low.h (netbsd_target_regsets, netbsd_target_ops)
+       (the_low_target, netbsd_tdesc): Remove.
+       (netbsd_process_target::get_regs_info)
+       (netbsd_process_target::low_arch_setup): Add.
+
 2020-09-23  Hannes Domani  <ssbssa@yahoo.de>
 
        * win32-low.cc: Remove local wow64_process variable.
index 9b8ea9b8aa666632115a8138e5daa38ef236a46c..c59ebc8f2cf41d85701fabbe4b9aa08a449a785c 100644 (file)
@@ -155,22 +155,9 @@ netbsd_x86_64_store_gregset (struct regcache *regcache, const char *buf)
   netbsd_x86_64_supply_gp (AMD64_GS_REGNUM, GS);
 }
 
-/* Implements the netbsd_target_ops.arch_setup routine.  */
-
-static void
-netbsd_x86_64_arch_setup (void)
-{
-  struct target_desc *tdesc
-    = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, false, false);
-
-  init_target_desc (tdesc, amd64_expedite_regs);
-
-  netbsd_tdesc = tdesc;
-}
-
 /* Description of all the x86-netbsd register sets.  */
 
-struct netbsd_regset_info netbsd_target_regsets[] =
+static const struct netbsd_regset_info netbsd_target_regsets[] =
 {
  /* General Purpose Registers.  */
  {PT_GETREGS, PT_SETREGS, sizeof (struct reg),
@@ -179,9 +166,41 @@ struct netbsd_regset_info netbsd_target_regsets[] =
  {0, 0, -1, NULL, NULL }
 };
 
-/* The netbsd_target_ops vector for x86-netbsd.  */
+/* NetBSD target op definitions for the amd64 architecture.  */
 
-struct netbsd_target_ops the_low_target =
+class netbsd_amd64_target : public netbsd_process_target
 {
- netbsd_x86_64_arch_setup,
+protected:
+  const netbsd_regset_info *get_regs_info () override;
+
+  void low_arch_setup () override;
 };
+
+/* Return the information to access registers.  */
+
+const netbsd_regset_info *
+netbsd_amd64_target::get_regs_info ()
+{
+  return netbsd_target_regsets;
+}
+
+/* Architecture-specific setup for the current process.  */
+
+void
+netbsd_amd64_target::low_arch_setup ()
+{
+  target_desc *tdesc
+    = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, false, false);
+
+  init_target_desc (tdesc, amd64_expedite_regs);
+
+  current_process ()->tdesc = tdesc;
+}
+
+/* The singleton target ops object.  */
+
+static netbsd_amd64_target the_netbsd_amd64_target;
+
+/* The NetBSD target ops object.  */
+
+netbsd_process_target *the_netbsd_target = &the_netbsd_amd64_target;
index 3eb2c0f25f6e27a5eedc1f76d2320c78ca0f29fe..7bec55a56acb2526b3f307269b2fffbea76da702 100644 (file)
@@ -114,6 +114,8 @@ netbsd_process_target::post_create_inferior ()
 {
   pid_t pid = current_process ()->pid;
   netbsd_nat::enable_proc_events (pid);
+
+  low_arch_setup ();
 }
 
 /* Implement the attach target_ops method.  */
@@ -504,7 +506,7 @@ netbsd_process_target::thread_alive (ptid_t ptid)
 void
 netbsd_process_target::fetch_registers (struct regcache *regcache, int regno)
 {
-  struct netbsd_regset_info *regset = netbsd_target_regsets;
+  const netbsd_regset_info *regset = get_regs_info ();
   ptid_t inferior_ptid = ptid_of (current_thread);
 
   while (regset->size >= 0)
@@ -525,7 +527,7 @@ netbsd_process_target::fetch_registers (struct regcache *regcache, int regno)
 void
 netbsd_process_target::store_registers (struct regcache *regcache, int regno)
 {
-  struct netbsd_regset_info *regset = netbsd_target_regsets;
+  const netbsd_regset_info *regset = get_regs_info ();
   ptid_t inferior_ptid = ptid_of (current_thread);
 
   while (regset->size >= 0)
@@ -1317,13 +1319,8 @@ netbsd_process_target::supports_read_auxv ()
   return true;
 }
 
-/* The NetBSD target ops object.  */
-
-static netbsd_process_target the_netbsd_target;
-
 void
 initialize_low ()
 {
-  set_target_ops (&the_netbsd_target);
-  the_low_target.arch_setup ();
+  set_target_ops (the_netbsd_target);
 }
index 96ad6d92474781cf3246580542cca8f0d4d074dd..c229a0f9f617a41565849f0c63758a592b378d12 100644 (file)
@@ -35,21 +35,6 @@ struct netbsd_regset_info
   void (*store_function) (struct regcache *regcache, const char *buf);
 };
 
-/* A list of regsets for the target being debugged, terminated by an entry
-   where the size is negative.
-
-   This list should be created by the target-specific code.  */
-
-extern struct netbsd_regset_info netbsd_target_regsets[];
-
-/* The target-specific operations for NetBSD support.  */
-
-struct netbsd_target_ops
-{
-  /* Architecture-specific setup.  */
-  void (*arch_setup) ();
-};
-
 /* Target ops definitions for a NetBSD target.  */
 
 class netbsd_process_target : public process_stratum_target
@@ -141,14 +126,17 @@ public:
   const char *thread_name (ptid_t thread) override;
 
   bool supports_catch_syscall () override;
-};
 
-/* The inferior's target description.  This is a global because the
-   NetBSD ports support neither bi-arch nor multi-process.  */
+protected:
+  /* The architecture-specific "low" methods are listed below.  */
 
-extern struct netbsd_target_ops the_low_target;
+  /* Return the information to access registers.  */
+  virtual const netbsd_regset_info *get_regs_info () = 0;
+
+  /* Architecture-specific setup for the current process.  */
+  virtual void low_arch_setup () = 0;
+};
 
-/* XXX: multilib */
-extern const struct target_desc *netbsd_tdesc;
+extern netbsd_process_target *the_netbsd_target;
 
 #endif /* GDBSERVER_NETBSD_LOW_H */