From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81338 invoked by alias); 9 Feb 2019 05:24:58 -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 81171 invoked by uid 89); 9 Feb 2019 05:24:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS,TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Feb 2019 05:24:22 +0000 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 x195OBZZ029132 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 9 Feb 2019 00:24:16 -0500 Received: by simark.ca (Postfix, from userid 112) id 681861E64C; Sat, 9 Feb 2019 00:24:11 -0500 (EST) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 727391E077; Sat, 9 Feb 2019 00:24:06 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Sat, 09 Feb 2019 05:24:00 -0000 From: Simon Marchi To: John Baldwin Cc: gdb-patches@sourceware.org, Ulrich Weigand , Tom Tromey , Simon Marchi Subject: Re: [PATCH v2 1/3] Extract register_reader and register_readwriter interfaces from regcache In-Reply-To: References: <20181024014333.14143-1-simon.marchi@polymtl.ca> <20181024014333.14143-2-simon.marchi@polymtl.ca> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2019-02/txt/msg00103.txt.bz2 On 2019-02-08 11:46, John Baldwin wrote: > On 10/23/18 6:43 PM, Simon Marchi wrote: >> From: Simon Marchi >> >> In the following patch, we make gdbarch pseudo-registers hooks read >> and >> write required registers from a frame instead of from the current >> regcache. To avoid having to change the implementation of all >> architectures to use a different interface, we can re-use the regcache >> interface. >> >> This patch extracts two interfaces, register_reader and >> register_readwriter, and make respectively readable_regcache and >> regcache inherit from them. register_reader is "something from which >> you can read register values from". It can of course be a regcache, >> but >> it will also be (in the following patch) something that unwinds >> registers for a particular frame. As you would expect, >> register_readwriter is "something you can read and write registers >> from/to". >> >> Some notes about the implementation. This results in diamond >> inheritance: regcache inherits from both readable_regcache and >> register_readwriter, which both inherit from register_reader. It is >> therefore necessary to use virtual inheritance (use "public virtual"), >> otherwises we end up with errors like: >> >> /home/emaisin/src/binutils-gdb/gdb/regcache.c:210:20: error: request >> for member ‘cooked_read’ is ambiguous >> >> Also, the raw_read method in readable_regcache hides the raw_read >> template method in register_reader. So it's necessary to use "using >> register_reader::raw_read" so that clients of readable_regcache are >> able >> to call register_reader's raw_read. Same thing for some cooked_read, >> raw_write and cooked_write. >> >> All corresponding gdbarch hooks are updated to use register_reader or >> register_readwriter instead of readable_regcache and regcache, but >> otherwise they are not changed. >> >> With this patch, no behavior change is expected. >> >> @@ -539,20 +541,19 @@ regcache_raw_read_signed (struct regcache >> *regcache, int regnum, LONGEST *val) >> >> template >> enum register_status >> -readable_regcache::raw_read (int regnum, T *val) >> +register_reader::raw_read (int regnum, T *val) >> { >> - gdb_byte *buf; >> - enum register_status status; >> + gdbarch *arch = this->arch (); >> + int reg_size = register_size (arch, regnum); >> + gdb_byte buf[reg_size]; >> + >> + register_status status = raw_read (regnum, buf); >> >> - assert_regnum (regnum); >> - buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]); >> - status = raw_read (regnum, buf); > > This "loses" the assert_regnum(). Is that replaced for regcache's by > the > gdb_assert() you added in readable_regcache::raw_read()? Did you > consider > moving that assertion to here instead so it would also be enforced in > the > frame version of register_reader? (Or does the frame version also add > its > own assertion in the following patches?) Good point. I don't recall exactly, but the idea was probably to have the assert in a single place on the code path, to avoid asserting the same thing multiple times in a row, if possible. I don't think that the frame version adds a similar assert, I'll look into adding it there. > Similar question about register_readwriter::raw_write, > register_reader::cooked_read, and register_readerwriter::cooked_write. > > The only other general comment is that while I appreciate that this > doesn't > require changing the tdep files very much (which is a good thing), it > does > have the odd result that the variable names in the gdbarch methods are > still > named 'regcache' even though they aren't regcache's anymore. It's > perhaps > not worth it, but it might be nice to do a followup pass eventually to > rename 'register_reader *regcache' to 'reader' and something similar > for > the writer case? It seems tedious though, and I don't think it should > be a > requirement/blocker, just a suggestion for the future perhaps. I agree. I'll look into doing this as a follow-up pass (it would just add noise to this patch). Thanks, Simon