public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@arm.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] [gdb/aarch64] Handle unknown debug architecture versions more gracefully
Date: Tue, 18 Apr 2023 14:53:13 +0100	[thread overview]
Message-ID: <20230418135313.36300-1-luis.machado@arm.com> (raw)

In PR 30340 it was reported that a KVM-based AArch64 system's kernel was
returning a debug architecture version of 0 when fetching both the
NT_ARM_HW_WATCH and NT_ARM_HW_BREAK register sets.

Even though the debug architecture version being reported is invalid, gdb can
still make things work by ignoring that information and relying on the counts
of hardware watchpoints and hardware breakpoints.

This patch makes gdb handle this situation a bit more gracefully by causing gdb
to warn when it sees an invalid/unknown debug architecture version, but still
allowing gdb to detect the number of hardware watchpoints and hardware
breakpoints available.

PR tdep/30340
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30340
---
 gdb/nat/aarch64-linux-hw-point.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c
index ccb47cd5aa2..b014d387e1e 100644
--- a/gdb/nat/aarch64-linux-hw-point.c
+++ b/gdb/nat/aarch64-linux-hw-point.c
@@ -250,10 +250,21 @@ aarch64_linux_get_debug_reg_capacity (int tid)
   iov.iov_base = &dreg_state;
   iov.iov_len = sizeof (dreg_state);
 
+  /* It has been reported that under KVM the debug architecture version can
+     be reported as 0, which is invalid.  But this doesn't mean gdb can't use
+     hardware debugging resources.  Instead of bailing out, carry on fetching
+     the hardware breakpoints/watchpoints count so we can potentially get back
+     on track.  */
+
   /* Get hardware watchpoint register info.  */
-  if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_HW_WATCH, &iov) == 0
-      && compatible_debug_arch (AARCH64_DEBUG_ARCH (dreg_state.dbg_info)))
+  if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_HW_WATCH, &iov) == 0)
     {
+      if (!compatible_debug_arch (AARCH64_DEBUG_ARCH (dreg_state.dbg_info)))
+	warning (_("Unknown/Invalid debug architecture version %d.\n"
+		   "Attempting to fetch the number of hardware watchpoints "
+		   "available."),
+		   AARCH64_DEBUG_ARCH (dreg_state.dbg_info));
+
       aarch64_num_wp_regs = AARCH64_DEBUG_NUM_SLOTS (dreg_state.dbg_info);
       if (aarch64_num_wp_regs > AARCH64_HWP_MAX_NUM)
 	{
@@ -271,9 +282,14 @@ aarch64_linux_get_debug_reg_capacity (int tid)
     }
 
   /* Get hardware breakpoint register info.  */
-  if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_HW_BREAK, &iov) == 0
-      && compatible_debug_arch (AARCH64_DEBUG_ARCH (dreg_state.dbg_info)))
+  if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_HW_BREAK, &iov) == 0)
     {
+      if (!compatible_debug_arch (AARCH64_DEBUG_ARCH (dreg_state.dbg_info)))
+	warning (_("Unknown/Invalid debug architecture version %d.\n"
+		   "Attempting to fetch the number of hardware breakpoints "
+		   "available."),
+		   AARCH64_DEBUG_ARCH (dreg_state.dbg_info));
+
       aarch64_num_bp_regs = AARCH64_DEBUG_NUM_SLOTS (dreg_state.dbg_info);
       if (aarch64_num_bp_regs > AARCH64_HBP_MAX_NUM)
 	{
-- 
2.25.1


             reply	other threads:[~2023-04-18 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 13:53 Luis Machado [this message]
2023-05-15 10:07 ` Andrew Burgess

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=20230418135313.36300-1-luis.machado@arm.com \
    --to=luis.machado@arm.com \
    --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).