From: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>
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 [thread overview]
Message-ID: <20231114133532.3877-4-mohamed.bouhaouel@intel.com> (raw)
In-Reply-To: <20231114133532.3877-1-mohamed.bouhaouel@intel.com>
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 <blarsen@redhat.com>
---
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)
--
2.25.1
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2023-11-14 13:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 13:35 [PATCH v3 0/3] Check for zpoint support when handling watchpoints Mohamed Bouhaouel
2023-11-14 13:35 ` [PATCH v3 1/3] gdb, gdbserver, zpoint: report z_point support Mohamed Bouhaouel
2023-11-14 13:45 ` Eli Zaretskii
2023-11-14 14:36 ` Tom Tromey
2023-11-15 17:31 ` Bouhaouel, Mohamed
2023-11-14 13:35 ` [PATCH v3 2/3] gdb, breakpoint: add a breakpoint type converter Mohamed Bouhaouel
2023-11-14 14:37 ` Tom Tromey
2023-11-15 17:44 ` Bouhaouel, Mohamed
2023-11-14 13:35 ` Mohamed Bouhaouel [this message]
2023-11-14 14:45 ` [PATCH v3 3/3] gdb, zpoint: check for target hardware breakpoint support Tom Tromey
2023-11-15 18:18 ` Bouhaouel, Mohamed
2023-11-17 13:42 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231114133532.3877-4-mohamed.bouhaouel@intel.com \
--to=mohamed.bouhaouel@intel.com \
--cc=blarsen@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).