public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix length calculation in aarch64_linux_set_debug_regs
Date: Thu, 19 Nov 2015 15:20:00 -0000	[thread overview]
Message-ID: <564DE8BB.1060200@ericsson.com> (raw)
In-Reply-To: <564DD3BE.2080305@gmail.com>

On 15-11-19 08:50 AM, Yao Qi wrote:
> You can push it in, with some commit log adjustments, because the old
> code is correct.

Ok I pushed it.  Again, sorry for saying the code was not correct :).


From bb82e93484cdd56c67efd52b869a6123b2623f6c Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Thu, 19 Nov 2015 10:17:36 -0500
Subject: [PATCH] Fix iov_len calculation in aarch64_linux_set_debug_regs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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.
---
 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++)
     {
-- 
2.5.1





      reply	other threads:[~2015-11-19 15:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02 14:48 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 message]

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=564DE8BB.1060200@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    /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).