From patchwork Tue Feb 11 09:01:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tankut Baris Aktemur X-Patchwork-Id: 37912 Received: (qmail 119971 invoked by alias); 11 Feb 2020 09:03:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 118177 invoked by uid 89); 11 Feb 2020 09:03:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mga07.intel.com Received: from mga07.intel.com (HELO mga07.intel.com) (134.134.136.100) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 09:03:22 +0000 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2020 01:03:21 -0800 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga008.jf.intel.com with ESMTP; 11 Feb 2020 01:03:20 -0800 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 01B93JUk002195; Tue, 11 Feb 2020 09:03:19 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id 01B93JIs010506; Tue, 11 Feb 2020 10:03:19 +0100 Received: (from taktemur@localhost) by ulvlx001.iul.intel.com with LOCAL id 01B93JsR010500; Tue, 11 Feb 2020 10:03:19 +0100 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 23/58] gdbserver: turn target ops 'stopped_by_watchpoint' and 'stopped_data_address' into methods Date: Tue, 11 Feb 2020 10:01:35 +0100 Message-Id: <8fc6fbdb8c8c4eff5d4304ea153adc1a3263372a.1581410934.git.tankut.baris.aktemur@intel.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes gdbserver/ChangeLog: 2020-02-10 Tankut Baris Aktemur Make process_stratum_target's stopped_by_watchpoint and stopped_data_address ops methods of process_target. * target.h (struct process_stratum_target): Remove the target ops. (class process_target): Add the target ops. * target.c (process_target::stopped_by_watchpoint): Define. (process_target::stopped_data_address): Define. Update the derived structs and callers below. * remote-utils.c (prepare_resume_reply): Update. * linux-low.c (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.c (lynx_target_ops): Update. * nto-low.c (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.c (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/linux-low.c | 11 ++++------- gdbserver/linux-low.h | 4 ++++ gdbserver/lynx-low.c | 2 -- gdbserver/nto-low.c | 16 +++++++--------- gdbserver/nto-low.h | 4 ++++ gdbserver/remote-utils.c | 5 ++--- gdbserver/target.c | 12 ++++++++++++ gdbserver/target.h | 17 ++++++++--------- gdbserver/win32-low.c | 12 +++++------- gdbserver/win32-low.h | 4 ++++ 10 files changed, 50 insertions(+), 37 deletions(-) diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c index d43483c5e0b..a01ecd0c562 100644 --- a/gdbserver/linux-low.c +++ b/gdbserver/linux-low.c @@ -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 00e563eddbe..59a1d9321d9 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -331,6 +331,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.c b/gdbserver/lynx-low.c index 23dc32c31f8..0d4934fb313 100644 --- a/gdbserver/lynx-low.c +++ b/gdbserver/lynx-low.c @@ -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.c b/gdbserver/nto-low.c index 20db2dba3f4..fc7a6032fd6 100644 --- a/gdbserver/nto-low.c +++ b/gdbserver/nto-low.c @@ -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 7b321077607..ad60bf913bf 100644 --- a/gdbserver/nto-low.h +++ b/gdbserver/nto-low.h @@ -93,6 +93,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.c b/gdbserver/remote-utils.c index b5248ab368e..316f04e32ee 100644 --- a/gdbserver/remote-utils.c +++ b/gdbserver/remote-utils.c @@ -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.c b/gdbserver/target.c index 09b3a633fc8..00f5f794b85 100644 --- a/gdbserver/target.c +++ b/gdbserver/target.c @@ -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 263efaf104f..f9c749fdfcb 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.c b/gdbserver/win32-low.c index 0c4a948a37a..970c532c149 100644 --- a/gdbserver/win32-low.c +++ b/gdbserver/win32-low.c @@ -284,17 +284,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 (); @@ -1834,8 +1834,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 b13c53c4ed3..36926801f1e 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -147,6 +147,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. */