From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53218 invoked by alias); 28 Apr 2017 13:42:48 -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 53199 invoked by uid 89); 28 Apr 2017 13:42:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 13:42:45 +0000 Received: by mail-wm0-f67.google.com with SMTP id y10so11036477wmh.0 for ; Fri, 28 Apr 2017 06:42:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=Qui550Y5LSgqcq3iCI5NeZCUFLl0It+54Lwh1/MAVfQ=; b=hGRIx7vGv887oeA9syFShgN9ZwPbK2RAKoAjYnZVaTT8EgyILgQgSrf/ejKzty+zYY 2pS6rUUe4ALR5bcYBomzXe7ztjU1aBPvfl66ah9pmybOrSrQ63eNceiTw6D7oD152mWJ oCJ5dS0fwJBHn8OxX9og+G3uayjY3P6amCOzNUjvzmjVOnXP6YRSWyuXDs2jd5/bk8th GwAlMD01KKFanC6J2PY9Bps1Cxo6WhrP1pAJtEDspbMkF33R0XNrmSlozoIvBlTkBMQo rKAcWyezuU6dJHWeKcHaYiqRv+pr97VsEQIZP3JZjdZDAvxRbLR6cviFPYPfvWxv0lWJ LkqQ== X-Gm-Message-State: AN3rC/6lth3godZhpB0D3adySJdR74DbGRhAha8POzO4ymHiW5pijkAQ glAm6fiWcjb7c+e6 X-Received: by 10.28.20.9 with SMTP id 9mr5704542wmu.52.1493386965881; Fri, 28 Apr 2017 06:42:45 -0700 (PDT) Received: from E107787-LIN ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id w186sm6909681wme.26.2017.04.28.06.42.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 28 Apr 2017 06:42:45 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/6] Add constructor and destructor to regcache References: <1493152106-3246-1-git-send-email-yao.qi@linaro.org> <1493152106-3246-3-git-send-email-yao.qi@linaro.org> <24c71239-5b8f-5ca1-a140-146acef9c543@redhat.com> Date: Fri, 28 Apr 2017 13:42:00 -0000 In-Reply-To: <24c71239-5b8f-5ca1-a140-146acef9c543@redhat.com> (Pedro Alves's message of "Thu, 27 Apr 2017 18:34:03 +0100") Message-ID: <86h918bqcs.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00770.txt.bz2 Pedro Alves writes: >> + explicit regcache (struct gdbarch *gdbarch, struct address_space *asp= ace_) >> + : regcache (gdbarch, aspace_, true) > > There's no real good reason to use "explicit" when you have more than > one parameter. > Removed. >> + >> +private: >> + explicit regcache (struct gdbarch *gdbarch, struct address_space *asp= ace_, >> + bool readonly_p_) > > Ditto. > Removed. >> + : aspace (aspace_), readonly_p (readonly_p_) >> + { >> + gdb_assert (gdbarch !=3D NULL); >> + descr =3D regcache_descr (gdbarch); >> + >> + if (readonly_p) >> + { >> + registers =3D XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers); >> + register_status =3D XCNEWVEC (signed char, >> + descr->sizeof_cooked_register_status); >> + } >> + else >> + { >> + registers =3D XCNEWVEC (gdb_byte, descr->sizeof_raw_registers); >> + register_status =3D XCNEWVEC (signed char, >> + descr->sizeof_raw_register_status); >> + } >> + ptid =3D minus_one_ptid; >> + } >> + >> + friend struct regcache * >> + get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch, >> + struct address_space *aspace); >> }; > > (I'd drop the "struct" in the aspace parameters.) Removed. Patch below is pushed in. --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom c35356d17072b89ae7d6b34c20f4b2cd69ed8468 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Thu, 20 Apr 2017 14:54:26 +0100 Subject: [PATCH] Add constructor and destructor to regcache This patch adds ctor and dtor to regcache. gdb: 2017-04-28 Yao Qi * regcache.c (regcache::regcache): New function. (regcache::~regcache): New function. (regcache_xmalloc_1): Remove. (regcache_xmalloc): Call new regcache. (regcache_xfree): Call delete regcache. (get_thread_arch_aspace_regcache): Call new regcache. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d99c5a2..efaf8bb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2017-04-28 Yao Qi =20 + * regcache.c (regcache::regcache): New function. + (regcache::~regcache): New function. + (regcache_xmalloc_1): Remove. + (regcache_xmalloc): Call new regcache. + (regcache_xfree): Call delete regcache. + (get_thread_arch_aspace_regcache): Call new regcache. + +2017-04-28 Yao Qi + * mips-linux-nat.c (mips_linux_new_thread): Use ptid method lwp instead of ptid_get_lwp. =20 diff --git a/gdb/regcache.c b/gdb/regcache.c index 966f0c7..798812e 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -191,6 +191,17 @@ regcache_register_size (const struct regcache *regcach= e, int n) =20 struct regcache { +public: + regcache (gdbarch *gdbarch, address_space *aspace_) + : regcache (gdbarch, aspace_, true) + {} + + ~regcache () + { + xfree (registers); + xfree (register_status); + } + struct regcache_descr *descr; =20 /* The address space of this register cache (for registers where it @@ -213,6 +224,32 @@ struct regcache /* If this is a read-write cache, which thread's registers is it connected to? */ ptid_t ptid; + +private: + regcache (gdbarch *gdbarch, address_space *aspace_, bool readonly_p_) + : aspace (aspace_), readonly_p (readonly_p_) + { + gdb_assert (gdbarch !=3D NULL); + descr =3D regcache_descr (gdbarch); + + if (readonly_p) + { + registers =3D XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers); + register_status =3D XCNEWVEC (signed char, + descr->sizeof_cooked_register_status); + } + else + { + registers =3D XCNEWVEC (gdb_byte, descr->sizeof_raw_registers); + register_status =3D XCNEWVEC (signed char, + descr->sizeof_raw_register_status); + } + ptid =3D minus_one_ptid; + } + + friend regcache * + get_thread_arch_aspace_regcache (ptid_t ptid, gdbarch *gdbarch, + address_space *aspace); }; =20 /* See regcache.h. */ @@ -225,41 +262,10 @@ regcache_get_ptid (const struct regcache *regcache) return regcache->ptid; } =20 -static struct regcache * -regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace, - bool readonly_p) -{ - struct regcache_descr *descr; - struct regcache *regcache; - - gdb_assert (gdbarch !=3D NULL); - descr =3D regcache_descr (gdbarch); - regcache =3D XNEW (struct regcache); - regcache->descr =3D descr; - regcache->readonly_p =3D readonly_p; - if (readonly_p) - { - regcache->registers - =3D XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers); - regcache->register_status - =3D XCNEWVEC (signed char, descr->sizeof_cooked_register_status); - } - else - { - regcache->registers - =3D XCNEWVEC (gdb_byte, descr->sizeof_raw_registers); - regcache->register_status - =3D XCNEWVEC (signed char, descr->sizeof_raw_register_status); - } - regcache->aspace =3D aspace; - regcache->ptid =3D minus_one_ptid; - return regcache; -} - struct regcache * regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace) { - return regcache_xmalloc_1 (gdbarch, aspace, true); + return new regcache (gdbarch, aspace); } =20 void @@ -267,9 +273,8 @@ regcache_xfree (struct regcache *regcache) { if (regcache =3D=3D NULL) return; - xfree (regcache->registers); - xfree (regcache->register_status); - xfree (regcache); + + delete regcache; } =20 static void @@ -507,7 +512,7 @@ get_thread_arch_aspace_regcache (ptid_t ptid, struct gd= barch *gdbarch, && get_regcache_arch (list->regcache) =3D=3D gdbarch) return list->regcache; =20 - new_regcache =3D regcache_xmalloc_1 (gdbarch, aspace, false); + new_regcache =3D new regcache (gdbarch, aspace, false); new_regcache->ptid =3D ptid; =20 list =3D XNEW (struct regcache_list);