From patchwork Tue Feb 11 09:02:04 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: 37939 Received: (qmail 124638 invoked by alias); 11 Feb 2020 09:04:10 -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 120786 invoked by uid 89); 11 Feb 2020 09:03:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.5 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: mga09.intel.com Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 09:03:33 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2020 01:03:28 -0800 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 11 Feb 2020 01:03:27 -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 01B93Q2d002313; Tue, 11 Feb 2020 09:03:26 GMT Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id 01B93QIX010709; Tue, 11 Feb 2020 10:03:26 +0100 Received: (from taktemur@localhost) by ulvlx001.iul.intel.com with LOCAL id 01B93QNd010705; Tue, 11 Feb 2020 10:03:26 +0100 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH 52/58] gdbserver: turn breakpoint kind-related target ops into methods Date: Tue, 11 Feb 2020 10:02:04 +0100 Message-Id: <5f07daabec3126a60bf48b20fd60594bc68c83f0.1581410935.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 breakpoint_kind_from_pc, sw_breakpoint_from_kind, and breakpoint_kind_from_current_state ops methods ofprocess_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.c (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 structs and callers below. * mem-break.c (bp_size): Update. (bp_opcode): Update. * linux-low.c (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.c (lynx_target_ops): Update. (lynx_process_target::sw_breakpoint_from_kind): Define. * lynx-low.h (class lynx_process_target): Update. * nto-low.c (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.c (win32_target_ops): Update. (win32_sw_breakpoint_from_kind): Turn iwin32 ... (win32_process_target::sw_breakpoint_from_kind): ... this. * win32-low.h (class win32_process_target): Update. --- gdbserver/linux-low.c | 23 ++++++++++------------- gdbserver/linux-low.h | 6 ++++++ gdbserver/lynx-low.c | 10 +++++++--- gdbserver/lynx-low.h | 2 ++ gdbserver/mem-break.c | 4 ++-- gdbserver/nto-low.c | 7 ++----- gdbserver/nto-low.h | 2 ++ gdbserver/target.c | 32 ++++++++++++++++---------------- gdbserver/target.h | 42 ++++++++++++++++++------------------------ gdbserver/win32-low.c | 7 ++----- gdbserver/win32-low.h | 2 ++ 11 files changed, 69 insertions(+), 68 deletions(-) diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c index b19c3458bc5..de011c126c0 100644 --- a/gdbserver/linux-low.c +++ b/gdbserver/linux-low.c @@ -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) { @@ -7355,19 +7355,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); @@ -7377,13 +7377,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 @@ -7498,10 +7498,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 7ee9c0c03d0..6a531ed3aab 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -465,6 +465,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.c b/gdbserver/lynx-low.c index 11a7ab9e6a6..aa4c5b24b0e 100644 --- a/gdbserver/lynx-low.c +++ b/gdbserver/lynx-low.c @@ -728,6 +728,13 @@ 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")); + return nullptr; +} + /* The LynxOS target ops object. */ static lynx_process_target the_lynx_target; @@ -735,10 +742,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 4f542118704..d4d265ca2f3 100644 --- a/gdbserver/lynx-low.h +++ b/gdbserver/lynx-low.h @@ -90,6 +90,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.c b/gdbserver/mem-break.c index 682b3bc1832..3802d72a573 100644 --- a/gdbserver/mem-break.c +++ b/gdbserver/mem-break.c @@ -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.c b/gdbserver/nto-low.c index f5919baa5cb..3e2e8eaa521 100644 --- a/gdbserver/nto-low.c +++ b/gdbserver/nto-low.c @@ -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 ad60bf913bf..be4634079ad 100644 --- a/gdbserver/nto-low.h +++ b/gdbserver/nto-low.h @@ -97,6 +97,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.c b/gdbserver/target.c index 39e763dffc8..a29c9fda4eb 100644 --- a/gdbserver/target.c +++ b/gdbserver/target.c @@ -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 f7f0e6b779c..8da04a58150 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.c b/gdbserver/win32-low.c index ecece2d579c..017cfd3c245 100644 --- a/gdbserver/win32-low.c +++ b/gdbserver/win32-low.c @@ -1836,8 +1836,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; @@ -1848,10 +1848,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 fcd50e2a45b..dc0bdcc714a 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -165,6 +165,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. */