From 6eeb5c5531f0238d367a2f3f1520ae3e2401f7ea Mon Sep 17 00:00:00 2001 From: Tankut Baris Aktemur Date: Mon, 17 Feb 2020 16:11:55 +0100 Subject: [PATCH] gdbserver: turn target ops 'stopped_by_watchpoint' and 'stopped_data_address' into methods gdbserver/ChangeLog: 2020-02-20 Tankut Baris Aktemur Turn process_stratum_target's stopped_by_watchpoint and stopped_data_address ops into methods of process_target. * target.h (struct process_stratum_target): Remove the target ops. (class process_target): Add the target ops. * target.cc (process_target::stopped_by_watchpoint): Define. (process_target::stopped_data_address): Define. Update the derived classes and callers below. * remote-utils.cc (prepare_resume_reply): Update. * linux-low.cc (linux_target_ops): Update. (linux_stopped_by_watchpoint): Turn into ... (linux_process_target::stopped_by_watchpoint): ... this. (linux_stopped_data_address): Turn into ... (linux_process_target::stopped_data_address): ... this. * linux-low.h (class linux_process_target): Update. * lynx-low.cc (lynx_target_ops): Update. * nto-low.cc (nto_target_ops): Update. (nto_stopped_by_watchpoint): Turn into ... (nto_process_target::stopped_by_watchpoint): ... this. (nto_stopped_data_address): Turn into ... (nto_process_target::stopped_data_address): ... this. * nto-low.h (class nto_process_target): Update. * win32-low.cc (win32_target_ops): Update. (win32_stopped_by_watchpoint): Turn into ... (win32_process_target::stopped_by_watchpoint): ... this. (win32_stopped_data_address): Turn into ... (win32_process_target::stopped_data_address): ... this. * win32-low.h (class win32_process_target): Update. --- gdbserver/ChangeLog | 33 +++++++++++++++++++++++++++++++++ gdbserver/linux-low.cc | 11 ++++------- gdbserver/linux-low.h | 4 ++++ gdbserver/lynx-low.cc | 2 -- gdbserver/nto-low.cc | 16 +++++++--------- gdbserver/nto-low.h | 4 ++++ gdbserver/remote-utils.cc | 5 ++--- gdbserver/target.cc | 12 ++++++++++++ gdbserver/target.h | 17 ++++++++--------- gdbserver/win32-low.cc | 12 +++++------- gdbserver/win32-low.h | 4 ++++ 11 files changed, 83 insertions(+), 37 deletions(-) diff --git a/gdbserver/ChangeLog b/gdbserver/ChangeLog index 9757bc0fa3..f7ac9a877c 100644 --- a/gdbserver/ChangeLog +++ b/gdbserver/ChangeLog @@ -1,3 +1,36 @@ +2020-02-20 Tankut Baris Aktemur + + Turn process_stratum_target's stopped_by_watchpoint and + stopped_data_address ops into methods of process_target. + + * target.h (struct process_stratum_target): Remove the target ops. + (class process_target): Add the target ops. + * target.cc (process_target::stopped_by_watchpoint): Define. + (process_target::stopped_data_address): Define. + + Update the derived classes and callers below. + + * remote-utils.cc (prepare_resume_reply): Update. + * linux-low.cc (linux_target_ops): Update. + (linux_stopped_by_watchpoint): Turn into ... + (linux_process_target::stopped_by_watchpoint): ... this. + (linux_stopped_data_address): Turn into ... + (linux_process_target::stopped_data_address): ... this. + * linux-low.h (class linux_process_target): Update. + * lynx-low.cc (lynx_target_ops): Update. + * nto-low.cc (nto_target_ops): Update. + (nto_stopped_by_watchpoint): Turn into ... + (nto_process_target::stopped_by_watchpoint): ... this. + (nto_stopped_data_address): Turn into ... + (nto_process_target::stopped_data_address): ... this. + * nto-low.h (class nto_process_target): Update. + * win32-low.cc (win32_target_ops): Update. + (win32_stopped_by_watchpoint): Turn into ... + (win32_process_target::stopped_by_watchpoint): ... this. + (win32_stopped_data_address): Turn into ... + (win32_process_target::stopped_data_address): ... this. + * win32-low.h (class win32_process_target): Update. + 2020-02-20 Tankut Baris Aktemur Turn process_stratum_target's supports_hardware_single_step op into diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index fec2c3c567..5a5c637282 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -269,7 +269,6 @@ static int linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid, int *wstat, int options); static int linux_wait_for_event (ptid_t ptid, int *wstat, int options); static struct lwp_info *add_lwp (ptid_t ptid); -static int linux_stopped_by_watchpoint (void); static void mark_lwp_dead (struct lwp_info *lwp, int wstat); static int lwp_is_marked_dead (struct lwp_info *lwp); static void proceed_all_lwps (void); @@ -6044,16 +6043,16 @@ linux_supports_software_single_step (void) return can_software_single_step (); } -static int -linux_stopped_by_watchpoint (void) +bool +linux_process_target::stopped_by_watchpoint () { struct lwp_info *lwp = get_thread_lwp (current_thread); return lwp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT; } -static CORE_ADDR -linux_stopped_data_address (void) +CORE_ADDR +linux_process_target::stopped_data_address () { struct lwp_info *lwp = get_thread_lwp (current_thread); @@ -7376,8 +7375,6 @@ linux_get_hwcap2 (int wordsize) static linux_process_target the_linux_target; static process_stratum_target linux_target_ops = { - linux_stopped_by_watchpoint, - linux_stopped_data_address, #if defined(__UCLIBC__) && defined(HAS_NOMMU) \ && defined(PT_TEXT_ADDR) && defined(PT_DATA_ADDR) \ && defined(PT_TEXT_END_ADDR) diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index 57fc9a5941..af2a0c6671 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -332,6 +332,10 @@ public: bool supports_stopped_by_hw_breakpoint () override; bool supports_hardware_single_step () override; + + bool stopped_by_watchpoint () override; + + CORE_ADDR stopped_data_address () 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 ea328b7efe..e9dfccede0 100644 --- a/gdbserver/lynx-low.cc +++ b/gdbserver/lynx-low.cc @@ -735,8 +735,6 @@ static lynx_process_target the_lynx_target; /* The LynxOS target_ops vector. */ static process_stratum_target lynx_target_ops = { - NULL, /* stopped_by_watchpoint */ - NULL, /* stopped_data_address */ NULL, /* read_offsets */ NULL, /* get_tls_address */ NULL, /* hostio_last_error */ diff --git a/gdbserver/nto-low.cc b/gdbserver/nto-low.cc index 3e10436df3..53020a25e7 100644 --- a/gdbserver/nto-low.cc +++ b/gdbserver/nto-low.cc @@ -878,12 +878,12 @@ nto_process_target::supports_hardware_single_step () /* Check if the reason of stop for current thread (CURRENT_INFERIOR) is a watchpoint. - Return 1 if stopped by watchpoint, 0 otherwise. */ + Return true if stopped by watchpoint, false otherwise. */ -static int -nto_stopped_by_watchpoint (void) +bool +nto_process_target::stopped_by_watchpoint () { - int ret = 0; + bool ret = false; TRACE ("%s\n", __func__); if (nto_inferior.ctl_fd != -1 && current_thread != NULL) @@ -899,7 +899,7 @@ nto_stopped_by_watchpoint (void) err = devctl (nto_inferior.ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0); if (err == EOK && (status.flags & watchmask)) - ret = 1; + ret = true; } } TRACE ("%s: %s\n", __func__, ret ? "yes" : "no"); @@ -910,8 +910,8 @@ nto_stopped_by_watchpoint (void) Return inferior's instruction pointer value, or 0 on error. */ -static CORE_ADDR -nto_stopped_data_address (void) +CORE_ADDR +nto_process_target::stopped_data_address () { CORE_ADDR ret = (CORE_ADDR)0; @@ -956,8 +956,6 @@ nto_sw_breakpoint_from_kind (int kind, int *size) static nto_process_target the_nto_target; static process_stratum_target nto_target_ops = { - nto_stopped_by_watchpoint, - nto_stopped_data_address, NULL, /* nto_read_offsets */ NULL, /* thread_db_set_tls_address */ hostio_last_error_from_errno, diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h index 001ccb6687..c3e7099e70 100644 --- a/gdbserver/nto-low.h +++ b/gdbserver/nto-low.h @@ -94,6 +94,10 @@ public: int size, raw_breakpoint *bp) override; bool supports_hardware_single_step () override; + + bool stopped_by_watchpoint () override; + + CORE_ADDR stopped_data_address () override; }; /* The inferior's target description. This is a global because the diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index b5248ab368..316f04e32e 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -1214,8 +1214,7 @@ prepare_resume_reply (char *buf, ptid_t ptid, regcache = get_thread_regcache (current_thread, 1); - if (the_target->stopped_by_watchpoint != NULL - && (*the_target->stopped_by_watchpoint) ()) + if (the_target->pt->stopped_by_watchpoint ()) { CORE_ADDR addr; int i; @@ -1223,7 +1222,7 @@ prepare_resume_reply (char *buf, ptid_t ptid, memcpy (buf, "watch:", 6); buf += 6; - addr = (*the_target->stopped_data_address) (); + addr = the_target->pt->stopped_data_address (); /* Convert each byte of the address into two hexadecimal chars. Note that we take sizeof (void *) instead of diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 09b3a633fc..00f5f794b8 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -469,3 +469,15 @@ process_target::supports_hardware_single_step () { return false; } + +bool +process_target::stopped_by_watchpoint () +{ + return false; +} + +CORE_ADDR +process_target::stopped_data_address () +{ + return 0; +} diff --git a/gdbserver/target.h b/gdbserver/target.h index 92b85cb061..83595fad52 100644 --- a/gdbserver/target.h +++ b/gdbserver/target.h @@ -70,15 +70,6 @@ class process_target; shared code. */ struct process_stratum_target { - /* Returns 1 if target was stopped due to a watchpoint hit, 0 otherwise. */ - - int (*stopped_by_watchpoint) (void); - - /* Returns the address associated with the watchpoint that hit, if any; - returns 0 otherwise. */ - - CORE_ADDR (*stopped_data_address) (void); - /* Reports the text, data offsets of the executable. This is needed for uclinux where the executable is relocated during load time. */ @@ -476,6 +467,14 @@ public: /* Returns true if the target can do hardware single step. */ virtual bool supports_hardware_single_step (); + + /* Returns true if target was stopped due to a watchpoint hit, false + otherwise. */ + virtual bool stopped_by_watchpoint (); + + /* Returns the address associated with the watchpoint that hit, if any; + returns 0 otherwise. */ + virtual CORE_ADDR stopped_data_address (); }; extern process_stratum_target *the_target; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 2862a9c241..ff62bcefb0 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -283,17 +283,17 @@ win32_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr, return 1; } -static int -win32_stopped_by_watchpoint (void) +bool +win32_process_target::stopped_by_watchpoint () { if (the_low_target.stopped_by_watchpoint != NULL) return the_low_target.stopped_by_watchpoint (); else - return 0; + return false; } -static CORE_ADDR -win32_stopped_data_address (void) +CORE_ADDR +win32_process_target::stopped_data_address () { if (the_low_target.stopped_data_address != NULL) return the_low_target.stopped_data_address (); @@ -1844,8 +1844,6 @@ win32_sw_breakpoint_from_kind (int kind, int *size) static win32_process_target the_win32_target; static process_stratum_target win32_target_ops = { - win32_stopped_by_watchpoint, - win32_stopped_data_address, NULL, /* read_offsets */ NULL, /* get_tls_address */ #ifdef _WIN32_WCE diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h index c5f9a13e02..b2b8a6dedc 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -148,6 +148,10 @@ public: int size, raw_breakpoint *bp) override; bool supports_hardware_single_step () override; + + bool stopped_by_watchpoint () override; + + CORE_ADDR stopped_data_address () override; }; /* Retrieve the context for this thread, if not already retrieved. */ -- 2.34.1