Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yufeng Zhang <Yufeng.Zhang@arm.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: Marcus Shawcroft <Marcus.Shawcroft@arm.com>
Subject: [PATCH, AArch64] Fix bug in hardware watchpoint/breakpoint handling
Date: Wed, 18 Dec 2013 16:07:00 -0000	[thread overview]
Message-ID: <52B1C84F.4000102@arm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1003 bytes --]

Hi,

This patch fixes an AArch64 GDB bug in handling the hardware debug 
registers.  GDB calls ptrace to set hardware debug registers and it 
passes a full-length "struct user_hwdebug_state" variable regardless of 
the number of hardware debug registers available on a target.  When 
there are fewer than 16 (the maximum number) hardware 
breakpoint/watchpoint registers on a target, the kernel will complain 
about the gdb's request to set non-existing hardware debug registers. 
There will be an warning of "Unexpected error setting hardware debug 
registers" when the inferior starts to run.

This patch fixes the issue by setting iov.iov_len with a value 
reflecting the exact size in use.

OK for the mainline?

Thanks.
Yufeng


gdb/

         * aarch64-linux-nat.c (aarch64_linux_set_debug_regs): Set
	iov.iov_len with the real length in use.

gdb/gdbserver/

         * linux-aarch64-low.c (aarch64_linux_set_debug_regs): Set
	iov.iov_len with the real length in use.

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 1532 bytes --]

diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index 256725b..7d76833 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -314,10 +314,13 @@ aarch64_linux_set_debug_regs (const struct aarch64_debug_reg_state *state,
 
   memset (&regs, 0, sizeof (regs));
   iov.iov_base = &regs;
-  iov.iov_len = sizeof (regs);
   count = watchpoint ? aarch64_num_wp_regs : aarch64_num_bp_regs;
   addr = watchpoint ? state->dr_addr_wp : state->dr_addr_bp;
   ctrl = watchpoint ? state->dr_ctrl_wp : state->dr_ctrl_bp;
+  if (count == 0)
+    return;
+  iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs[count - 1])
+		 + sizeof (regs.dbg_regs [count - 1]));
 
   for (i = 0; i < count; i++)
     {
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 93246b3..c2d271a 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -602,10 +602,13 @@ aarch64_linux_set_debug_regs (const struct aarch64_debug_reg_state *state,
 
   memset (&regs, 0, sizeof (regs));
   iov.iov_base = &regs;
-  iov.iov_len = sizeof (regs);
   count = watchpoint ? aarch64_num_wp_regs : aarch64_num_bp_regs;
   addr = watchpoint ? state->dr_addr_wp : state->dr_addr_bp;
   ctrl = watchpoint ? state->dr_ctrl_wp : state->dr_ctrl_bp;
+  if (count == 0)
+    return;
+  iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs[count - 1])
+		 + sizeof (regs.dbg_regs [count - 1]));
 
   for (i = 0; i < count; i++)
     {

             reply	other threads:[~2013-12-18 16:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18 16:07 Yufeng Zhang [this message]
2013-12-18 16:24 ` Pedro Alves
2013-12-19  7:00 ` pinskia
2013-12-19 10:16   ` Marcus Shawcroft
2013-12-19 10:23     ` pinskia
2013-12-19 10:26       ` Marcus Shawcroft

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=52B1C84F.4000102@arm.com \
    --to=yufeng.zhang@arm.com \
    --cc=Marcus.Shawcroft@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