From patchwork Tue Mar 28 11:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bouhaouel, Mohamed" X-Patchwork-Id: 67007 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 314263854830 for ; Tue, 28 Mar 2023 11:55:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 314263854830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680004538; bh=txjyr5c2seAb7SavtkItZf/fA6C5vxzU72G+4mBH82I=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KMIksdCAOvim1dRdtvuxhi+13xCY2pOhDvhSWxUEM9gH9tKfRW/w6Dr70ePOQiFnx v+Jikpb07yBS2pwRkDzrzhdtpMwb9bhuOaF/RXvV2qfDHsogX3bNRYQ4dYp+jAALh/ ec3Cflf7PJvAv3tSbLOt8nO07d4aOQh/+sVyVLfs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id D98F83858430 for ; Tue, 28 Mar 2023 11:55:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D98F83858430 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320944346" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="320944346" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 04:55:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="753116171" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="753116171" Received: from mbouhaou-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.40.224]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 04:55:09 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 1/3] gdb, gdbserver, zpoint: report z_point support Date: Tue, 28 Mar 2023 13:54:47 +0200 Message-Id: <20230328115449.6526-2-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328115449.6526-1-mohamed.bouhaouel@intel.com> References: <20230328115449.6526-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mohamed Bouhaouel via Gdb-patches From: "Bouhaouel, Mohamed" Reply-To: Mohamed Bouhaouel Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Report if the target supports Z-points when exchanging features between GDB and gdbserver. Signed-off-by: Mohamed Bouhaouel --- gdb/remote.c | 15 +++++++++++++++ gdbserver/mem-break.cc | 2 +- gdbserver/mem-break.h | 4 ++++ gdbserver/server.cc | 7 +++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gdb/remote.c b/gdb/remote.c index 526df313ea7..1139ce3ddf7 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -755,6 +755,9 @@ class remote_target : public process_stratum_target int insert_watchpoint (CORE_ADDR, int, enum target_hw_bp_type, struct expression *) override; + /* Returns TRUE if GDB Z breakpoint type is supported, FALSE otherwise. */ + bool supports_z_point_type (int); + int remove_watchpoint (CORE_ADDR, int, enum target_hw_bp_type, struct expression *) override; @@ -5604,6 +5607,11 @@ static const struct protocol_feature remote_protocol_features[] = { { "no-resumed", PACKET_DISABLE, remote_supported_packet, PACKET_no_resumed }, { "memory-tagging", PACKET_DISABLE, remote_supported_packet, PACKET_memory_tagging_feature }, + { "Z0", PACKET_SUPPORT_UNKNOWN, remote_supported_packet, PACKET_Z0 }, + { "Z1", PACKET_SUPPORT_UNKNOWN, remote_supported_packet, PACKET_Z1 }, + { "Z2", PACKET_SUPPORT_UNKNOWN, remote_supported_packet, PACKET_Z2 }, + { "Z3", PACKET_SUPPORT_UNKNOWN, remote_supported_packet, PACKET_Z3 }, + { "Z4", PACKET_SUPPORT_UNKNOWN, remote_supported_packet, PACKET_Z4 }, }; static char *remote_support_xml; @@ -10843,6 +10851,13 @@ watchpoint_to_Z_packet (int type) } } +bool +remote_target::supports_z_point_type (int type) +{ + Z_packet_type packet = watchpoint_to_Z_packet (type); + return (m_features.packet_support (PACKET_Z0 + packet) != PACKET_DISABLE); +} + int remote_target::insert_watchpoint (CORE_ADDR addr, int len, enum target_hw_bp_type type, struct expression *cond) diff --git a/gdbserver/mem-break.cc b/gdbserver/mem-break.cc index c669842228d..20434f7c9b4 100644 --- a/gdbserver/mem-break.cc +++ b/gdbserver/mem-break.cc @@ -987,7 +987,7 @@ find_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind) return NULL; } -static int +int z_type_supported (char z_type) { return (z_type >= '0' && z_type <= '4' diff --git a/gdbserver/mem-break.h b/gdbserver/mem-break.h index 9bf7aa84932..458ba0e6be2 100644 --- a/gdbserver/mem-break.h +++ b/gdbserver/mem-break.h @@ -276,4 +276,8 @@ int remove_memory_breakpoint (struct raw_breakpoint *bp); void clone_all_breakpoints (struct thread_info *child_thread, const struct thread_info *parent_thread); + +/* Returns TRUE if Z_TYPE is supported by the target. */ + +int z_type_supported (char z_type); #endif /* GDBSERVER_MEM_BREAK_H */ diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 949849b63a2..e758cd0d509 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -2480,6 +2480,13 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p) if (target_supports_memory_tagging ()) strcat (own_buf, ";memory-tagging+"); + /* Z points support. */ + strcat (own_buf, z_type_supported ('0') ? ";Z0+" : ";Z0-"); + strcat (own_buf, z_type_supported ('1') ? ";Z1+" : ";Z1-"); + strcat (own_buf, z_type_supported ('2') ? ";Z2+" : ";Z2-"); + strcat (own_buf, z_type_supported ('3') ? ";Z3+" : ";Z3-"); + strcat (own_buf, z_type_supported ('4') ? ";Z4+" : ";Z4-"); + /* Reinitialize components as needed for the new connection. */ hostio_handle_new_gdb_connection (); target_handle_new_gdb_connection (); From patchwork Tue Mar 28 11:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bouhaouel, Mohamed" X-Patchwork-Id: 67008 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF51838582BD for ; Tue, 28 Mar 2023 11:55:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF51838582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680004541; bh=53TmgT10EiQjqW6fz74a32PR1lVWhOeYS4wMzwkBPXA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uQxe6LJi8RN0W08BYsV/Bn+3a1cOUyOEejnAlMj/C+na2iGmPPpgLv5swE0HsVp5w op0yJ0vTa/eys09Uf3IBud3fw0doDsIsaa9sOEYQyob0BTMc4IkAzTbmbsfqujivfL z26BJYGBeRpJsYIT/9uHSY1mfO7dr7T5DQlaH4Yo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id D322E3858C53 for ; Tue, 28 Mar 2023 11:55:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D322E3858C53 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320944369" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="320944369" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 04:55:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="753116301" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="753116301" Received: from mbouhaou-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.40.224]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 04:55:16 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 2/3] gdb, breakpoint: add a breakpoint type converter Date: Tue, 28 Mar 2023 13:54:48 +0200 Message-Id: <20230328115449.6526-3-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328115449.6526-1-mohamed.bouhaouel@intel.com> References: <20230328115449.6526-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mohamed Bouhaouel via Gdb-patches From: "Bouhaouel, Mohamed" Reply-To: Mohamed Bouhaouel Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Add a new function 'bptype_to_target_hw_bp_type' to perform the translation from 'bptype' to 'target_hw_bp_type'. Signed-off-by: Mohamed Bouhaouel --- gdb/breakpoint.c | 20 ++++++++++++++++++++ gdb/breakpoint.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 7228acfd8fe..e71cf7639d9 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9581,6 +9581,26 @@ break_range_command (const char *arg, int from_tty) install_breakpoint (false, std::move (br), true); } +/* See breakpoint.h. */ + +target_hw_bp_type +bptype_to_target_hw_bp_type (bptype type) +{ + switch (type) + { + case bp_hardware_watchpoint: + return hw_write; + case bp_read_watchpoint: + return hw_read; + case bp_access_watchpoint: + return hw_access; + case bp_hardware_breakpoint: + return hw_execute; + default: + error (_ ("Bad breakpoint type: bptype %d."), type); + } +} + /* Return non-zero if EXP is verified as constant. Returned zero means EXP is variable. Also the constant detection may fail for some constant expressions and in such case still falsely return diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 7c5cf3f2bef..12fa5c96e08 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1946,4 +1946,7 @@ extern void describe_other_breakpoints (struct gdbarch *, extern void enable_disable_bp_location (bp_location *loc, bool enable); +/* Translate BPTYPE to TARGET_HW_BP_TYPE. */ + +extern target_hw_bp_type bptype_to_target_hw_bp_type (bptype type); #endif /* !defined (BREAKPOINT_H) */ From patchwork Tue Mar 28 11:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bouhaouel, Mohamed" X-Patchwork-Id: 67009 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C35B385AC39 for ; Tue, 28 Mar 2023 11:55:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C35B385AC39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680004549; bh=4aJRwV6/BvrN/RzHIWUXgR3p9yEibIRSzrxmXpkKoHM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jeDvJUd97ZtaI5/ld9JgBwAe0B1TxwFk53vmmAS5aDj2JSCLy5D35mf44qoAg1Vc2 iCiU/RDuLUg/Vhi1xR3/8YX3TrSsfmIl5cwlDdTYvhQg6x9iWYn1Wex19Xsd4INx9s jBPytmg79Rv2RYL9pblKpuYWUPSuS/i87KgsfLrg= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id 7DD06385842E for ; Tue, 28 Mar 2023 11:55:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DD06385842E X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320944383" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="320944383" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 04:55:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="753116354" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="753116354" Received: from mbouhaou-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.40.224]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 04:55:23 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 3/3] gdb, zpoint: check for target hardware breakpoint support Date: Tue, 28 Mar 2023 13:54:49 +0200 Message-Id: <20230328115449.6526-4-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328115449.6526-1-mohamed.bouhaouel@intel.com> References: <20230328115449.6526-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mohamed Bouhaouel via Gdb-patches From: "Bouhaouel, Mohamed" Reply-To: Mohamed Bouhaouel Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" In 'can_use_hw_breakpoint', check if the target supports hardware-assisted breakpoints. This will prevent GDB from trying to insert the hardware breakpoint in case it is not supported. Signed-off-by: Mohamed Bouhaouel --- gdb/remote.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 1139ce3ddf7..1b9883f263c 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -10833,7 +10833,7 @@ remote_target::remove_breakpoint (struct gdbarch *gdbarch, } static enum Z_packet_type -watchpoint_to_Z_packet (int type) +hw_bp_to_Z_packet (int type) { switch (type) { @@ -10846,6 +10846,9 @@ watchpoint_to_Z_packet (int type) case hw_access: return Z_PACKET_ACCESS_WP; break; + case hw_execute: + return Z_PACKET_HARDWARE_BP; + break; default: internal_error (_("hw_bp_to_z: bad watchpoint type %d"), type); } @@ -10854,7 +10857,7 @@ watchpoint_to_Z_packet (int type) bool remote_target::supports_z_point_type (int type) { - Z_packet_type packet = watchpoint_to_Z_packet (type); + Z_packet_type packet = hw_bp_to_Z_packet (type); return (m_features.packet_support (PACKET_Z0 + packet) != PACKET_DISABLE); } @@ -10865,7 +10868,7 @@ remote_target::insert_watchpoint (CORE_ADDR addr, int len, struct remote_state *rs = get_remote_state (); char *endbuf = rs->buf.data () + get_remote_packet_size (); char *p; - enum Z_packet_type packet = watchpoint_to_Z_packet (type); + enum Z_packet_type packet = hw_bp_to_Z_packet (type); if (m_features.packet_support (PACKET_Z0 + packet) == PACKET_DISABLE) return 1; @@ -10913,7 +10916,7 @@ remote_target::remove_watchpoint (CORE_ADDR addr, int len, struct remote_state *rs = get_remote_state (); char *endbuf = rs->buf.data () + get_remote_packet_size (); char *p; - enum Z_packet_type packet = watchpoint_to_Z_packet (type); + enum Z_packet_type packet = hw_bp_to_Z_packet (type); if (m_features.packet_support (PACKET_Z0 + packet) == PACKET_DISABLE) return -1; @@ -10965,6 +10968,11 @@ remote_target::can_use_hw_breakpoint (enum bptype type, int cnt, int ot) { if (type == bp_hardware_breakpoint) { + /* Check if the target supports hardware-assisted breakpoints. + Return 0 if not. */ + if (!supports_z_point_type (bptype_to_target_hw_bp_type (type))) + return 0; + if (remote_hw_breakpoint_limit == 0) return 0; else if (remote_hw_breakpoint_limit < 0) @@ -10974,6 +10982,18 @@ remote_target::can_use_hw_breakpoint (enum bptype type, int cnt, int ot) } else { + /* Check if the target supports the hardware watchpoint type. + Return 0 if not. */ + if (!supports_z_point_type (bptype_to_target_hw_bp_type (type))) + { + /* If hw read watchpoints are not supported while hw access are, + GDB will try to insert the watchpoint as hw access. */ + bool access_support = supports_z_point_type ( + bptype_to_target_hw_bp_type (bp_access_watchpoint)); + if (!(type == bp_read_watchpoint && access_support)) + return 0; + } + if (remote_hw_watchpoint_limit == 0) return 0; else if (remote_hw_watchpoint_limit < 0)