public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix length calculation in aarch64_linux_set_debug_regs
@ 2015-11-02 14:48 Simon Marchi
  2015-11-02 16:00 ` Pedro Alves
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Simon Marchi @ 2015-11-02 14:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: qiyaoltc, Simon Marchi

There is this build failure when building in C++:

In file included from build-gnulib/import/stddef.h:45:0,
                 from /usr/include/time.h:37,
                 from build-gnulib/import/time.h:41,
                 from build-gnulib/import/sys/stat.h:44,
                 from ../bfd/bfd.h:44,
                 from /home/simark/src/binutils-gdb/gdb/common/common-types.h:35,
                 from /home/simark/src/binutils-gdb/gdb/common/common-defs.h:44,
                 from /home/simark/src/binutils-gdb/gdb/nat/aarch64-linux-hw-point.c:19:
/home/simark/src/binutils-gdb/gdb/nat/aarch64-linux-hw-point.c: In function ‘void aarch64_linux_set_debug_regs(const aarch64_debug_reg_state*, int, int)’:
/home/simark/src/binutils-gdb/gdb/nat/aarch64-linux-hw-point.c:564:64: error: ‘count’ cannot appear in a constant-expression
   iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs[count - 1])
                                                                ^

I don't really understand the length computation done here.

From what I understand, the dbg_regs array in the user_hwdebug_state structure
is 16 elements long, but we don't use all of them.  We want iov_len to reflect
only the used bytes.  If that's true, I don't think that the current code is
correct.  Instead, it can be computed simply with:

  offsetof (struct user_hwdebug_state, dbg_regs) + count * sizeof (regs.dbg_reg[0]);

Does it make sense?

gdb/ChangeLog:

	* nat/aarch64-linux-hw-point.c (aarch64_linux_set_debug_regs): Fix
	iov_len computation.
---
 gdb/nat/aarch64-linux-hw-point.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c
index 1a5fa6a..dcbfa98 100644
--- a/gdb/nat/aarch64-linux-hw-point.c
+++ b/gdb/nat/aarch64-linux-hw-point.c
@@ -561,8 +561,8 @@ aarch64_linux_set_debug_regs (const struct aarch64_debug_reg_state *state,
   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]));
+  iov.iov_len = (offsetof (struct user_hwdebug_state, dbg_regs)
+		 + count * sizeof (regs.dbg_regs[0]));
 
   for (i = 0; i < count; i++)
     {
-- 
2.5.1

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

end of thread, other threads:[~2015-11-19 15:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-02 14:48 [PATCH] Fix length calculation in aarch64_linux_set_debug_regs Simon Marchi
2015-11-02 16:00 ` Pedro Alves
2015-11-02 17:09   ` Simon Marchi
2015-11-02 17:57     ` Pedro Alves
2015-11-02 18:17       ` Simon Marchi
2015-11-02 18:19         ` Pedro Alves
2015-11-02 18:25         ` Andreas Schwab
2015-11-02 16:51 ` Yao Qi
2015-11-19 11:52 ` Yao Qi
2015-11-19 13:32   ` Simon Marchi
2015-11-19 13:51     ` Yao Qi
2015-11-19 15:20       ` Simon Marchi

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