This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v2 52/58] gdbserver: turn breakpoint kind-related target ops into methods
gdbserver/ChangeLog:
2020-02-10 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.
---
gdbserver/linux-low.cc | 23 ++++++++++-------------
gdbserver/linux-low.h | 6 ++++++
gdbserver/lynx-low.cc | 9 ++++++---
gdbserver/lynx-low.h | 2 ++
gdbserver/mem-break.cc | 4 ++--
gdbserver/nto-low.cc | 7 ++-----
gdbserver/nto-low.h | 2 ++
gdbserver/target.cc | 32 ++++++++++++++++----------------
gdbserver/target.h | 42 ++++++++++++++++++------------------------
gdbserver/win32-low.cc | 7 ++-----
gdbserver/win32-low.h | 2 ++
11 files changed, 68 insertions(+), 68 deletions(-)
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 398c5fc6a82..9dce2a7c35e 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -3218,8 +3218,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)
{
@@ -7362,19 +7362,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);
@@ -7384,13 +7384,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
@@ -7505,10 +7505,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,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 9fd2bc0ea35..ae422b83879 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -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)))
diff --git a/gdbserver/lynx-low.cc b/gdbserver/lynx-low.cc
index ad669c8e9d7..b07412f0dcd 100644
--- a/gdbserver/lynx-low.cc
+++ b/gdbserver/lynx-low.cc
@@ -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 */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 4253f1259c2..7da97b3b073 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -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
diff --git a/gdbserver/mem-break.cc b/gdbserver/mem-break.cc
index 682b3bc1832..3802d72a573 100644
--- a/gdbserver/mem-break.cc
+++ b/gdbserver/mem-break.cc
@@ -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. */
diff --git a/gdbserver/nto-low.cc b/gdbserver/nto-low.cc
index 1140b5b6d49..b0ac86f8790 100644
--- a/gdbserver/nto-low.cc
+++ b/gdbserver/nto-low.cc
@@ -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 */
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index c3e7099e702..ff2003b60b0 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -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
diff --git a/gdbserver/target.cc b/gdbserver/target.cc
index 4c92fa6f89d..76eef626ce8 100644
--- a/gdbserver/target.cc
+++ b/gdbserver/target.cc
@@ -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);
+}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index bf653a4d08a..4651e449a80 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -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 */
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index eb51a857b25..71adf18ebb5 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -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 */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 1618501838e..d4c7cae3013 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -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. */
--
2.17.1