From patchwork Mon Nov 2 14:48:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 9495 Received: (qmail 30737 invoked by alias); 2 Nov 2015 14:48:29 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 30706 invoked by uid 89); 2 Nov 2015 14:48:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 02 Nov 2015 14:48:22 +0000 Received: from EUSAAHC004.ericsson.se (Unknown_Domain [147.117.188.84]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id E2.6C.32596.C7617365; Mon, 2 Nov 2015 08:53:32 +0100 (CET) Received: from elxcz23q12-y4.dyn.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.84) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 2 Nov 2015 09:48:19 -0500 From: Simon Marchi To: CC: , Simon Marchi Subject: [PATCH] Fix length calculation in aarch64_linux_set_debug_regs Date: Mon, 2 Nov 2015 09:48:04 -0500 Message-ID: <1446475684-31936-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes 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++) {