From patchwork Tue Nov 14 13:35:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bouhaouel, Mohamed" X-Patchwork-Id: 79832 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 05F363858020 for ; Tue, 14 Nov 2023 13:36:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by sourceware.org (Postfix) with ESMTPS id AC7923857B98 for ; Tue, 14 Nov 2023 13:36:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC7923857B98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC7923857B98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699968996; cv=none; b=aV5z4xJIs3Uey5rlO0jSHRjKZnA4fQbxjuSDWS2LBfe0KFN/bvzPqAYGkVIqnpuGi0lit8E1jxgJAqnXlZyjYL4d0/Ya0onBVqZAJsPm2J35sncCYQEoZQ6fvnykrhigD4Hv3rhfvtgoE4g5Sys1U25ytmkZgOCFFN2B7QF3hqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699968996; c=relaxed/simple; bh=cvoeDiYwVwkyARZ64tafor0uLgLDSP5e6L/7ssE5aiI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=fFx/uMGPs0iftfqllsseUXnBMOsvZ9kj5M8PFb+QwhAWsmY5JlGQf+Q1Lv3GPlaP/aCPJGYDY8UroGCN/ikBxskqdjbVVhjWP2Lvjch/Inq4+9ZxRSijXY6CTJGjMzCVj/wL7dKPNjM0A0MzvgThXu5Hlz2J3KjEJG2ZcrcdCGE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699968995; x=1731504995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cvoeDiYwVwkyARZ64tafor0uLgLDSP5e6L/7ssE5aiI=; b=n0mY6KiHZyJ4QaOAgo3mCF5HtigJ3kE2JHw2DDmfXlIs9Zh+qvYS1XyV QlcG/c3dfxZDkrBXb3cwBz5EECJUUdPJoitsYJUr3swjHyhMVNvhAFhbZ nFuRw9og2FudBwyAsaSiLEbUfpU32lz9cITseEPLr6qkNGsrg00Hwi0tX k6NmDKc+sSy2NCNVox6aAVpSHmE2uOgz4pVFxKA7GdxZK42tEmzGy/FSt VYuNqakMvKS7Hz3vvdP4k1wlY12REWefo2EFc8Lm+A8BpWL/b98sYQMCw g8Cqh97zl1oeo2eO+zsPOCHREjYEp2vYRXjrzRySFXXEP3GhHEW/DwkeH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="12199837" X-IronPort-AV: E=Sophos;i="6.03,302,1694761200"; d="scan'208";a="12199837" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 05:36:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,302,1694761200"; d="scan'208";a="5808087" Received: from mbouhaou-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.56.16]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 05:36:32 -0800 From: Mohamed Bouhaouel To: gdb-patches@sourceware.org Cc: blarsen@redhat.com, mohamed.bouhaouel@intel.com, eliz@gnu.org Subject: [PATCH v3 3/3] gdb, zpoint: check for target hardware breakpoint support Date: Tue, 14 Nov 2023 14:35:32 +0100 Message-Id: <20231114133532.3877-4-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231114133532.3877-1-mohamed.bouhaouel@intel.com> References: <20231114133532.3877-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 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, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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. Reviewed-By: Guinevere Larsen --- gdb/remote.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 7aa380a5989..10504696a57 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -10982,7 +10982,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) { @@ -10995,6 +10995,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); } @@ -11003,7 +11006,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); } @@ -11014,7 +11017,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 ((to_underlying (PACKET_Z0) + to_underlying (packet))) == PACKET_DISABLE) @@ -11064,7 +11067,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 ((to_underlying (PACKET_Z0) + to_underlying (packet))) == PACKET_DISABLE) @@ -11118,6 +11121,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) @@ -11127,6 +11135,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)