From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19781 invoked by alias); 2 Nov 2015 16:00:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 19617 invoked by uid 89); 2 Nov 2015 16:00:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 02 Nov 2015 16:00:07 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 87CA3AB4; Mon, 2 Nov 2015 16:00:06 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA2G04jB022044; Mon, 2 Nov 2015 11:00:05 -0500 Message-ID: <56378884.70001@redhat.com> Date: Mon, 02 Nov 2015 16:00:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Simon Marchi , gdb-patches@sourceware.org CC: qiyaoltc@gmail.com Subject: Re: [PATCH] Fix length calculation in aarch64_linux_set_debug_regs References: <1446475684-31936-1-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1446475684-31936-1-git-send-email-simon.marchi@ericsson.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2015-11/txt/msg00011.txt.bz2 On 11/02/2015 02:48 PM, Simon Marchi wrote: > 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? IIUYC, you're pointing out two issues: #1 - the offsetof that doesn't work in C++. #2 - an off-by-one. I don't know enough about Aarch64 to judge #1, but it does sound right to me. On #2, I saw the same on x86. See my fix here: https://sourceware.org/ml/gdb-patches/2015-02/msg00213.html I think it's a little nicer to hide away the offsetof+sizeof. Thanks, Pedro Alves