public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, AArch64] Fix bug in hardware watchpoint/breakpoint handling
@ 2013-12-18 16:07 Yufeng Zhang
  2013-12-18 16:24 ` Pedro Alves
  2013-12-19  7:00 ` pinskia
  0 siblings, 2 replies; 6+ messages in thread
From: Yufeng Zhang @ 2013-12-18 16:07 UTC (permalink / raw)
  To: gdb-patches; +Cc: Marcus Shawcroft

[-- 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++)
     {

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-12-19 10:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-18 16:07 [PATCH, AArch64] Fix bug in hardware watchpoint/breakpoint handling Yufeng Zhang
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

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).