From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 43AFA3858C2A for ; Thu, 21 Dec 2023 20:19:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43AFA3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 43AFA3858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703189954; cv=none; b=adl6s4ilgQus8r/mpD0VwrU2V8oqd+dhEi0enxVGcMgLluKMLA2FjqrkPXviEL4JTWDUryw+nT8hHB2v4zkbesADXsbIkQ2Ie6Wnv8uaH1w04I1iaamIBuhkQI2KyLbmqfOvkqdk+M/MuO3D7fHZDsDp3kmKlNbmfD+Rc28l2i8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703189954; c=relaxed/simple; bh=VZnSWKZEFg+9PMTRTcqrxy8UoYzsDSajr9y8Y3AyI04=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=xJlkSSN0/JOj+wgR7SjENSY/ctHxmj/p9Imm7lG8nJ+5ZnoKrhcRaRCNEtqAUfCzqiDk1pk26kGfzGAx3ftKYei0RFyeJnWICaikGkrB1wWHcm8gcqmYgRLIh76gHi0ZklyZ+Iqlxf2SfPmO30kMVak9j+hW6rfkDm9OIk6e3Ac= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1703189951; bh=VZnSWKZEFg+9PMTRTcqrxy8UoYzsDSajr9y8Y3AyI04=; h=Date:Subject:To:References:From:In-Reply-To:From; b=fOqGSAGNQSf8ho7rpSkQUA2R4ymoIv5IK/AQC3yGigzUXiU+TEP8AG7/RBoi90RZy 3Jrab7bKe5QP3cNeVLf7oBeaHweg3gHIiw9X8RlOnIIVoaorIzaTAq9lMupQAnGWwm X1DQEDbGvXikA3lP2coGFUJpf924HFYdGd6JZSpg= Received: from [172.16.0.192] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D62DC1E0AC; Thu, 21 Dec 2023 15:19:11 -0500 (EST) Message-ID: <4688c6c9-d8d7-4298-a79b-6e561ff740f1@simark.ca> Date: Thu, 21 Dec 2023 15:19:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 02/26] gdbserver: convert new_register_cache into a regcache constructor Content-Language: fr To: Tankut Baris Aktemur , gdb-patches@sourceware.org References: From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/28/23 06:28, Tankut Baris Aktemur via Gdb-patches wrote: > Convert the `new_register_cache` function into a constructor of the > regcache struct. Also define a default ctor because it is used in > other places, in particular, tracepoint.cc. > --- > gdbserver/regcache.cc | 11 +++-------- > gdbserver/regcache.h | 8 ++++---- > gdbserver/server.cc | 2 +- > 3 files changed, 8 insertions(+), 13 deletions(-) > > diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc > index 7987c406ab4..1410dd96551 100644 > --- a/gdbserver/regcache.cc > +++ b/gdbserver/regcache.cc > @@ -43,7 +43,7 @@ get_thread_regcache (struct thread_info *thread, int fetch) > > gdb_assert (proc->tdesc != NULL); > > - regcache = new_register_cache (proc->tdesc); > + regcache = new struct regcache (proc->tdesc); > set_thread_regcache_data (thread, regcache); > } > > @@ -151,15 +151,10 @@ regcache::initialize (const target_desc *tdesc, > > #ifndef IN_PROCESS_AGENT > > -struct regcache * > -new_register_cache (const struct target_desc *tdesc) > +regcache::regcache (const target_desc *tdesc) > { > - struct regcache *regcache = new struct regcache; > - > gdb_assert (tdesc->registers_size != 0); > - regcache->initialize (tdesc, nullptr); > - > - return regcache; > + initialize (tdesc, nullptr); > } > > void > diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h > index 15b7e2b4dff..0002726ed00 100644 > --- a/gdbserver/regcache.h > +++ b/gdbserver/regcache.h > @@ -44,6 +44,10 @@ struct regcache : public reg_buffer_common > #ifndef IN_PROCESS_AGENT > /* One of REG_UNAVAILABLE or REG_VALID. */ > unsigned char *register_status = nullptr; > + > + /* Constructors. */ > + regcache () = default; > + regcache (const target_desc *tdesc); Ok, so with this patch I understood better the two modes regcache can operate, it can allocate its own memory or use a buffer passed to the initialize method. I think my previous suggestion still stands. You could have: regcache (const target_desc *tdesc, unsigned char *regbuf); regcache (const target_desc *tdesc); ... former using the passed-in buffer and the latter allocating its own buffer. I don't think we would need a default constructor then (and we should use DISALLOW_COPY_AND_ASSIGN). Simon