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)