From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FW7CC67ViGCfGAAAWB0awg (envelope-from ) for ; Tue, 27 Apr 2021 23:25:34 -0400 Received: by simark.ca (Postfix, from userid 112) id 228DA1F11C; Tue, 27 Apr 2021 23:25:34 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 302381E940 for ; Tue, 27 Apr 2021 23:25:33 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E8C139DC4E7; Wed, 28 Apr 2021 03:25:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E8C139DC4E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1619580332; bh=e7DUCuTYSZiQlLRSAKOYTZhwd42yeeCZ4UMEdGXS6p0=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xdAAUKa8sbqGWEv4eXs0GreajpWWStYT8MkRrZ7+hko0/DSOygHAcgfQLF8EusoMz tTrVhV8HYHku7lGxm3pUC4UBSPd+lPTqGOMr4xKbEipXOU0mtcwvFRnMlKOtGrIIbH R/GMfL2Stc5ye50eywSrrh3oy4EhedJKuRsuZEmM= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 03B3339C0003 for ; Wed, 28 Apr 2021 03:25:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 03B3339C0003 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 13S3PN5R015693 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Apr 2021 23:25:27 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 13S3PN5R015693 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 1818F1E940; Tue, 27 Apr 2021 23:25:23 -0400 (EDT) Subject: Re: [PATCH 18/43] Add new register access interface to expr.c To: Zoran Zaric , gdb-patches@sourceware.org References: <20210301144620.103016-1-Zoran.Zaric@amd.com> <20210301144620.103016-19-Zoran.Zaric@amd.com> Message-ID: Date: Tue, 27 Apr 2021 23:25:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210301144620.103016-19-Zoran.Zaric@amd.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 28 Apr 2021 03:25:23 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2021-03-01 9:45 a.m., Zoran Zaric via Gdb-patches wrote: > DWARF expression evaluator is currently using get_frame_register_bytes > and put_frame_register_bytes interface for register access. > > The problem with evaluator using this interface is that it allows a > bleed out register access. This means that if the caller specifies a > larger amount of data then the size of a specified register, the > operation will continue accessing the neighboring registers until a > full amount of data has been reached. > > DWARF specification does not define this behavior, so a new simplified > register access interface is needed instead. > > * dwarf2/expr.c (read_from_register): New function. > (write_to_register): New function. > (rw_pieced_value): Now calls the read_from_register and > write_to_register functions. > --- > gdb/dwarf2/expr.c | 128 ++++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 106 insertions(+), 22 deletions(-) > > diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c > index c50bb3c8d90..5a1fd5b941f 100644 > --- a/gdb/dwarf2/expr.c > +++ b/gdb/dwarf2/expr.c > @@ -106,6 +106,96 @@ read_addr_from_reg (struct frame_info *frame, int reg) > return address_from_register (regnum, frame); > } > > +/* Read register REGNUM's contents in a given FRAME context. > + > + The data read is offsetted by OFFSET, and the number of bytes read > + is defined by LENGTH. The data is then copied into the > + caller-managed buffer BUF. > + > + If the register is optimized out or unavailable for the given > + FRAME, the OPTIMIZED and UNAVAILABLE outputs are set > + accordingly */ > + > +static void > +read_from_register (struct frame_info *frame, int regnum, > + CORE_ADDR offset, gdb::array_view buf, > + int *optimized, int *unavailable) > +{ > + struct gdbarch *gdbarch = get_frame_arch (frame); > + int regsize = register_size (gdbarch, regnum); > + int numregs = gdbarch_num_cooked_regs (gdbarch); > + int length = buf.size (); > + > + /* If a register is wholly inside the OFFSET, skip it. */ > + if (frame == NULL || !regsize > + || offset + length > regsize || numregs < regnum) The last line is missing one column of indent. Can `frame` really be NULL here? Given that where write_to_register is used, we have: struct frame_info *frame = frame_find_by_id (c->frame_id); struct gdbarch *arch = get_frame_arch (frame); If frame was NULL, it would segfault in get_frame_arch. Can regsize really be 0? I don't understand the code and how it relates to the comment. What does it mean for a register to be inside an offset? The expression `offset + length > regsize` checks that the end of the portion we want to read is beyond the end of the register. But there could be a part of the portion we want to read that is within the register. The code might be correct, but the comment needs to express the intention more clearly. Is `numregs < regnum` really useful? When would you encounter that? Simon