gdbserver: turn breakpoint kind-related target ops into methods
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 17 Feb 2020 15:12:02 +0000 (16:12 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 20 Feb 2020 16:35:18 +0000 (17:35 +0100)
gdbserver/ChangeLog:
2020-02-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

Turn process_stratum_target's breakpoint_kind_from_pc,
sw_breakpoint_from_kind, and breakpoint_kind_from_current_state
ops into methods of process_target.

* target.h (struct process_stratum_target): Remove the target op.
(class process_target): Add the target op.
(target_breakpoint_kind_from_pc): Update the macro.
(target_breakpoint_kind_from_current_state): Update the macro.
(default_breakpoint_kind_from_pc): Remove declaration.
* target.cc (default_breakpoint_kind_from_pc): Turn into ...
(process_target::breakpoint_kind_from_pc): ... this.
(process_target::breakpoint_kind_from_current_state): Define.

Update the derived classes and callers below.

* mem-break.cc (bp_size): Update.
(bp_opcode): Update.
* linux-low.cc (linux_target_ops): Update.
(linux_wait_1): Update.
(linux_breakpoint_kind_from_pc): Turn into ...
(linux_process_target::breakpoint_kind_from_pc): ... this.
(linux_sw_breakpoint_from_kind): Turn into ...
(linux_process_target::sw_breakpoint_from_kind): ... this.
(linux_breakpoint_kind_from_current_state): Turn into ...
(linux_process_target::breakpoint_kind_from_current_state): ... this.
* linux-low.h (class linux_process_target): Update.
* lynx-low.cc (lynx_target_ops): Update.
(lynx_process_target::sw_breakpoint_from_kind): Define.
* lynx-low.h (class lynx_process_target): Update.
* nto-low.cc (nto_target_ops): Update.
(nto_sw_breakpoint_from_kind): Turn into ...
(nto_process_target::sw_breakpoint_from_kind): ... this.
* nto-low.h (class nto_process_target): Update.
* win32-low.cc (win32_target_ops): Update.
(win32_sw_breakpoint_from_kind): Turn into ...
(win32_process_target::sw_breakpoint_from_kind): ... this.
* win32-low.h (class win32_process_target): Update.

12 files changed:
gdbserver/ChangeLog
gdbserver/linux-low.cc
gdbserver/linux-low.h
gdbserver/lynx-low.cc
gdbserver/lynx-low.h
gdbserver/mem-break.cc
gdbserver/nto-low.cc
gdbserver/nto-low.h
gdbserver/target.cc
gdbserver/target.h
gdbserver/win32-low.cc
gdbserver/win32-low.h

index dee5728f0aa6452da630a3fc2c790c1692c9cdbf..694792265db7bb8439c60bf1d1c3b035d68e63c0 100644 (file)
@@ -1,3 +1,43 @@
+2020-02-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       Turn process_stratum_target's breakpoint_kind_from_pc,
+       sw_breakpoint_from_kind, and breakpoint_kind_from_current_state
+       ops into methods of process_target.
+
+       * target.h (struct process_stratum_target): Remove the target op.
+       (class process_target): Add the target op.
+       (target_breakpoint_kind_from_pc): Update the macro.
+       (target_breakpoint_kind_from_current_state): Update the macro.
+       (default_breakpoint_kind_from_pc): Remove declaration.
+       * target.cc (default_breakpoint_kind_from_pc): Turn into ...
+       (process_target::breakpoint_kind_from_pc): ... this.
+       (process_target::breakpoint_kind_from_current_state): Define.
+
+       Update the derived classes and callers below.
+
+       * mem-break.cc (bp_size): Update.
+       (bp_opcode): Update.
+       * linux-low.cc (linux_target_ops): Update.
+       (linux_wait_1): Update.
+       (linux_breakpoint_kind_from_pc): Turn into ...
+       (linux_process_target::breakpoint_kind_from_pc): ... this.
+       (linux_sw_breakpoint_from_kind): Turn into ...
+       (linux_process_target::sw_breakpoint_from_kind): ... this.
+       (linux_breakpoint_kind_from_current_state): Turn into ...
+       (linux_process_target::breakpoint_kind_from_current_state): ... this.
+       * linux-low.h (class linux_process_target): Update.
+       * lynx-low.cc (lynx_target_ops): Update.
+       (lynx_process_target::sw_breakpoint_from_kind): Define.
+       * lynx-low.h (class lynx_process_target): Update.
+       * nto-low.cc (nto_target_ops): Update.
+       (nto_sw_breakpoint_from_kind): Turn into ...
+       (nto_process_target::sw_breakpoint_from_kind): ... this.
+       * nto-low.h (class nto_process_target): Update.
+       * win32-low.cc (win32_target_ops): Update.
+       (win32_sw_breakpoint_from_kind): Turn into ...
+       (win32_process_target::sw_breakpoint_from_kind): ... this.
+       * win32-low.h (class win32_process_target): Update.
+
 2020-02-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        Turn process_stratum_target's multifs_open, multifs_readlink,
index c49ba8924682b13724e5110f2a75968f67c9772a..20a936bb8700d12953af4c2bfa84a3d83b6cc6f2 100644 (file)
@@ -3226,8 +3226,8 @@ linux_wait_1 (ptid_t ptid,
       CORE_ADDR stop_pc = event_child->stop_pc;
 
       breakpoint_kind =
-       the_target->breakpoint_kind_from_current_state (&stop_pc);
-      the_target->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
+       the_target->pt->breakpoint_kind_from_current_state (&stop_pc);
+      the_target->pt->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
 
       if (debug_threads)
        {
@@ -7366,19 +7366,19 @@ current_lwp_ptid (void)
 
 /* Implementation of the target_ops method "breakpoint_kind_from_pc".  */
 
-static int
-linux_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
+int
+linux_process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
 {
   if (the_low_target.breakpoint_kind_from_pc != NULL)
     return (*the_low_target.breakpoint_kind_from_pc) (pcptr);
   else
-    return default_breakpoint_kind_from_pc (pcptr);
+    return process_target::breakpoint_kind_from_pc (pcptr);
 }
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-linux_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+linux_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   gdb_assert (the_low_target.sw_breakpoint_from_kind != NULL);
 
@@ -7388,13 +7388,13 @@ linux_sw_breakpoint_from_kind (int kind, int *size)
 /* Implementation of the target_ops method
    "breakpoint_kind_from_current_state".  */
 
-static int
-linux_breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
+int
+linux_process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
 {
   if (the_low_target.breakpoint_kind_from_current_state != NULL)
     return (*the_low_target.breakpoint_kind_from_current_state) (pcptr);
   else
-    return linux_breakpoint_kind_from_pc (pcptr);
+    return breakpoint_kind_from_pc (pcptr);
 }
 
 /* Default implementation of linux_target_ops method "set_pc" for
@@ -7509,10 +7509,7 @@ linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_breakpoint_kind_from_pc,
-  linux_sw_breakpoint_from_kind,
   linux_proc_tid_get_name,
-  linux_breakpoint_kind_from_current_state,
   linux_supports_software_single_step,
   linux_supports_catch_syscall,
   linux_get_ipa_tdesc_idx,
index 9fd2bc0ea35a42b29be19692c318d0fef1ced154..ae422b8387969ad07b3acb3fdad035999be83650 100644 (file)
@@ -462,6 +462,12 @@ public:
 
   ssize_t multifs_readlink (int pid, const char *filename, char *buf,
                            size_t bufsiz) override;
+
+  int breakpoint_kind_from_pc (CORE_ADDR *pcptr) override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
+
+  int breakpoint_kind_from_current_state (CORE_ADDR *pcptr) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
index ad669c8e9d7ffe6a682fc7ee02979c0a34b69dbd..b07412f0dcd645aa0a2581c283f3008786fa71c5 100644 (file)
@@ -728,6 +728,12 @@ lynx_process_target::supports_hardware_single_step ()
   return true;
 }
 
+const gdb_byte *
+lynx_process_target::sw_breakpoint_from_kind (int kind, int *size)
+{
+  error (_("Target does not implement the sw_breakpoint_from_kind op"));
+}
+
 /* The LynxOS target ops object.  */
 
 static lynx_process_target the_lynx_target;
@@ -735,10 +741,7 @@ static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  NULL,  /* breakpoint_kind_from_pc */
-  NULL,  /* sw_breakpoint_from_kind */
   NULL,  /* thread_name */
-  NULL,  /* breakpoint_kind_from_current_state */
   NULL,  /* supports_software_single_step */
   NULL,  /* supports_catch_syscall */
   NULL,  /* get_ipa_tdesc_idx */
index 4253f1259c29e6650a10e6ce89c3377c59aba368..7da97b3b073c509a1b43134cefed9a0a7f727018 100644 (file)
@@ -91,6 +91,8 @@ public:
   void request_interrupt () override;
 
   bool supports_hardware_single_step () override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 };
 
 /* The inferior's target description.  This is a global because the
index 682b3bc1832e066a2de12ff263d236a0265a5126..3802d72a57361d7317d49ad8354b3908ddf881c5 100644 (file)
@@ -223,7 +223,7 @@ bp_size (struct raw_breakpoint *bp)
 {
   int size = 0;
 
-  the_target->sw_breakpoint_from_kind (bp->kind, &size);
+  the_target->pt->sw_breakpoint_from_kind (bp->kind, &size);
   return size;
 }
 
@@ -234,7 +234,7 @@ bp_opcode (struct raw_breakpoint *bp)
 {
   int size = 0;
 
-  return the_target->sw_breakpoint_from_kind (bp->kind, &size);
+  return the_target->pt->sw_breakpoint_from_kind (bp->kind, &size);
 }
 
 /* See mem-break.h.  */
index 1140b5b6d498eca653568f907e88568f0473a659..b0ac86f8790b47e701b0520feccb2beb43035c1d 100644 (file)
@@ -935,8 +935,8 @@ nto_process_target::stopped_data_address ()
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-nto_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+nto_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   *size = the_low_target.breakpoint_len;
   return the_low_target.breakpoint;
@@ -947,10 +947,7 @@ nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  NULL, /* breakpoint_kind_from_pc */
-  nto_sw_breakpoint_from_kind,
   NULL, /* thread_name */
-  NULL, /* breakpoint_kind_from_current_state */
   NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
index c3e7099e702c9f11a76e12489f89cd4070cca0f8..ff2003b60b0433d37ad56419c2b365973b45015d 100644 (file)
@@ -98,6 +98,8 @@ public:
   bool stopped_by_watchpoint () override;
 
   CORE_ADDR stopped_data_address () override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 };
 
 /* The inferior's target description.  This is a global because the
index 4c92fa6f89dae3915aa36329dd1b3354a6a6fe6a..76eef626ce88a42d7c94695156e2448b309dcf53 100644 (file)
@@ -306,22 +306,6 @@ kill_inferior (process_info *proc)
   return the_target->pt->kill (proc);
 }
 
-/* Default implementation for breakpoint_kind_for_pc.
-
-   The default behavior for targets that don't implement breakpoint_kind_for_pc
-   is to use the size of a breakpoint as the kind.  */
-
-int
-default_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
-{
-  int size = 0;
-
-  gdb_assert (the_target->sw_breakpoint_from_kind != NULL);
-
-  (*the_target->sw_breakpoint_from_kind) (0, &size);
-  return size;
-}
-
 /* Define it.  */
 
 target_terminal_state target_terminal::m_terminal_state
@@ -801,3 +785,19 @@ process_target::multifs_readlink (int pid, const char *filename,
 {
   return readlink (filename, buf, bufsiz);
 }
+
+int
+process_target::breakpoint_kind_from_pc (CORE_ADDR *pcptr)
+{
+  /* The default behavior is to use the size of a breakpoint as the
+     kind.  */
+  int size = 0;
+  sw_breakpoint_from_kind (0, &size);
+  return size;
+}
+
+int
+process_target::breakpoint_kind_from_current_state (CORE_ADDR *pcptr)
+{
+  return breakpoint_kind_from_pc (pcptr);
+}
index bf653a4d08a4547b8f8886996a015a393d61d1a4..4651e449a805d65238b6581845097962f932288f 100644 (file)
@@ -70,26 +70,10 @@ class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Return the breakpoint kind for this target based on PC.  The PCPTR is
-     adjusted to the real memory location in case a flag (e.g., the Thumb bit on
-     ARM) was present in the PC.  */
-  int (*breakpoint_kind_from_pc) (CORE_ADDR *pcptr);
-
-  /* Return the software breakpoint from KIND.  KIND can have target
-     specific meaning like the Z0 kind parameter.
-     SIZE is set to the software breakpoint's length in memory.  */
-  const gdb_byte *(*sw_breakpoint_from_kind) (int kind, int *size);
-
   /* Return the thread's name, or NULL if the target is unable to determine it.
      The returned value must not be freed by the caller.  */
   const char *(*thread_name) (ptid_t thread);
 
-  /* Return the breakpoint kind for this target based on the current
-     processor state (e.g. the current instruction mode on ARM) and the
-     PC.  The PCPTR is adjusted to the real memory location in case a flag
-     (e.g., the Thumb bit on ARM) is present in the PC.  */
-  int (*breakpoint_kind_from_current_state) (CORE_ADDR *pcptr);
-
   /* Returns true if the target can software single step.  */
   int (*supports_software_single_step) (void);
 
@@ -503,6 +487,22 @@ public:
      not override this.  The default behavior is to use readlink(2).  */
   virtual ssize_t multifs_readlink (int pid, const char *filename,
                                    char *buf, size_t bufsiz);
+
+  /* Return the breakpoint kind for this target based on PC.  The
+     PCPTR is adjusted to the real memory location in case a flag
+     (e.g., the Thumb bit on ARM) was present in the PC.  */
+  virtual int breakpoint_kind_from_pc (CORE_ADDR *pcptr);
+
+  /* Return the software breakpoint from KIND.  KIND can have target
+     specific meaning like the Z0 kind parameter.
+     SIZE is set to the software breakpoint's length in memory.  */
+  virtual const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) = 0;
+
+  /* Return the breakpoint kind for this target based on the current
+     processor state (e.g. the current instruction mode on ARM) and the
+     PC.  The PCPTR is adjusted to the real memory location in case a
+     flag (e.g., the Thumb bit on ARM) is present in the  PC.  */
+  virtual int breakpoint_kind_from_current_state (CORE_ADDR *pcptr);
 };
 
 extern process_stratum_target *the_target;
@@ -661,14 +661,10 @@ target_read_btrace_conf (struct btrace_target_info *tinfo,
   the_target->pt->stopped_by_hw_breakpoint ()
 
 #define target_breakpoint_kind_from_pc(pcptr) \
-  (the_target->breakpoint_kind_from_pc \
-   ? (*the_target->breakpoint_kind_from_pc) (pcptr) \
-   : default_breakpoint_kind_from_pc (pcptr))
+  the_target->pt->breakpoint_kind_from_pc (pcptr)
 
 #define target_breakpoint_kind_from_current_state(pcptr) \
-  (the_target->breakpoint_kind_from_current_state \
-   ? (*the_target->breakpoint_kind_from_current_state) (pcptr) \
-   : target_breakpoint_kind_from_pc (pcptr))
+  the_target->pt->breakpoint_kind_from_current_state (pcptr)
 
 #define target_supports_software_single_step() \
   (the_target->supports_software_single_step ? \
@@ -701,6 +697,4 @@ int set_desired_thread ();
 
 const char *target_pid_to_str (ptid_t);
 
-int default_breakpoint_kind_from_pc (CORE_ADDR *pcptr);
-
 #endif /* GDBSERVER_TARGET_H */
index eb51a857b25d2b18f05d2d3974608aa537d81d50..71adf18ebb5edbb3c978a9df7ea7516552ad0f20 100644 (file)
@@ -1846,8 +1846,8 @@ win32_process_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 
 /* Implementation of the target_ops method "sw_breakpoint_from_kind".  */
 
-static const gdb_byte *
-win32_sw_breakpoint_from_kind (int kind, int *size)
+const gdb_byte *
+win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
 {
   *size = the_low_target.breakpoint_len;
   return the_low_target.breakpoint;
@@ -1858,10 +1858,7 @@ win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  NULL, /* breakpoint_kind_from_pc */
-  win32_sw_breakpoint_from_kind,
   NULL, /* thread_name */
-  NULL, /* breakpoint_kind_from_current_state */
   NULL, /* supports_software_single_step */
   NULL, /* supports_catch_syscall */
   NULL, /* get_ipa_tdesc_idx */
index 1618501838ecf8ef68e54a626cb418f96623512f..d4c7cae30137433b9e0ddf615a5a2fa74fe664f1 100644 (file)
@@ -166,6 +166,8 @@ public:
   bool supports_get_tib_address () override;
 
   int get_tib_address (ptid_t ptid, CORE_ADDR *addr) override;
+
+  const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */
This page took 0.039521 seconds and 4 git commands to generate.