This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix iov_len calculation in aarch64_linux_set_debug_regs


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bb82e93484cdd56c67efd52b869a6123b2623f6c

commit bb82e93484cdd56c67efd52b869a6123b2623f6c
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Thu Nov 19 10:17:36 2015 -0500

    Fix iov_len calculation in aarch64_linux_set_debug_regs
    
    There is this build failure when building in C++:
    
    /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])
                                                                    ^
    We can simplify the computation and make g++ happy at the same time by
    formulating as:
    
      size of fixed part + size of variable part
    
    thus...
    
      size of fixed part + count * size of one variable part element
    
    thus...
    
      offsetof (struct user_hwdebug_state, dbg_regs) + count * sizeof (regs.dbg_reg[0]);
    
    gdb/ChangeLog:
    
    	* nat/aarch64-linux-hw-point.c (aarch64_linux_set_debug_regs): Change
    	form of iov_len computation.

Diff:
---
 gdb/ChangeLog                    | 5 +++++
 gdb/nat/aarch64-linux-hw-point.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0539d96..94721a0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-11-19  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* nat/aarch64-linux-hw-point.c (aarch64_linux_set_debug_regs): Change
+	form of iov_len computation.
+
 2015-11-19  Pedro Alves  <palves@redhat.com>
 
 	* configure.ac (ERROR_ON_WARNING): Don't check whether in C++
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++)
     {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]