From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23559 invoked by alias); 27 Dec 2017 00:28:17 -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 23541 invoked by uid 89); 27 Dec 2017 00:28:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham 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; Wed, 27 Dec 2017 00:28:15 +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 vBR0S6if031198 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Dec 2017 19:28:11 -0500 Received: from [10.0.0.11] (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id B540E1E02D; Tue, 26 Dec 2017 19:28:06 -0500 (EST) Subject: Re: [PATCH v4 3/4] reggroups: Add reggroup_gdbarch_new, reggroup_find for dynamic reggroups To: Stafford Horne , GDB patches Cc: Eli Zaretskii References: <20171226134832.23497-1-shorne@gmail.com> <20171226134832.23497-4-shorne@gmail.com> From: Simon Marchi Message-ID: <6f994e73-8ef4-59ff-c56a-b805ef2aa6d7@polymtl.ca> Date: Wed, 27 Dec 2017 00:28:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171226134832.23497-4-shorne@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 27 Dec 2017 00:28:06 +0000 X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00503.txt.bz2 On 2017-12-26 08:48 AM, Stafford Horne wrote: > Traditionally reggroups have been created via reggroup_new() during > initialization code and never freed. Now, if we want to initialize > reggroups dynamically (i.e. in target description) we should be able to > free them. Create this function reggroup_gdbarch_new() which will > allocate the reggroup memory onto the passed gdbarch obstack. > > Also creating reggroup_find() as a utility to find a gdbarch registered > reggroup object by name. > > gdb/ChangeLog: > > yyyy-mm-dd Stafford Horne > > * reggroups.c (reggroup_gdbarch_new): New function. > (reggroup_find): New function. > * reggroups.h (reggroup_gdbarch_new): New function. > (reggroup_find): New function. > --- > Changes since v3 > * Added the reggroup_find function. > > gdb/reggroups.c | 29 +++++++++++++++++++++++++++++ > gdb/reggroups.h | 5 +++++ > 2 files changed, 34 insertions(+) > > diff --git a/gdb/reggroups.c b/gdb/reggroups.c > index 5d5e33f2a3..4e6b452f88 100644 > --- a/gdb/reggroups.c > +++ b/gdb/reggroups.c > @@ -46,6 +46,18 @@ reggroup_new (const char *name, enum reggroup_type type) > return group; > } > > +struct reggroup * > +reggroup_gdbarch_new (struct gdbarch *gdbarch, const char *name, > + enum reggroup_type type) > +{ > + struct reggroup *group = GDBARCH_OBSTACK_ZALLOC (gdbarch, > + struct reggroup); > + > + group->name = gdbarch_obstack_strdup (gdbarch, name); > + group->type = type; > + return group; > +} > + > /* Register group attributes. */ > > const char * > @@ -201,6 +213,23 @@ default_register_reggroup_p (struct gdbarch *gdbarch, int regnum, > return 0; > } > > +/* Find a reggroup by name. */ > + > +reggroup * > +reggroup_find (struct gdbarch *gdbarch, const char *name) > +{ > + struct reggroup *group; > + > + for (group = reggroup_next (gdbarch, NULL); > + group != NULL; > + group = reggroup_next (gdbarch, group)) > + { > + if (strcmp (name, reggroup_name (group)) == 0) > + return group; > + } > + return NULL; > +} > + > /* Dump out a table of register groups for the current architecture. */ > > static void > diff --git a/gdb/reggroups.h b/gdb/reggroups.h > index 18fc1bf294..5cfa51abff 100644 > --- a/gdb/reggroups.h > +++ b/gdb/reggroups.h > @@ -41,6 +41,10 @@ extern struct reggroup *const restore_reggroup; > /* Create a new local register group. */ > extern struct reggroup *reggroup_new (const char *name, > enum reggroup_type type); > +/* Create a new register group allocated onto the gdbarch obstack. */ > +extern struct reggroup *reggroup_gdbarch_new (struct gdbarch *gdbarch, > + const char *name, > + enum reggroup_type type); > > /* Add a register group (with attribute values) to the pre-defined list. */ > extern void reggroup_add (struct gdbarch *gdbarch, struct reggroup *group); > @@ -57,6 +61,7 @@ extern struct reggroup *reggroup_next (struct gdbarch *gdbarch, > struct reggroup *last); > extern struct reggroup *reggroup_prev (struct gdbarch *gdbarch, > struct reggroup *curr); > +extern reggroup *reggroup_find (struct gdbarch *gdbarch, const char *name); Please add a doc comment for this declaration. In the .c, write /* See reggroups.h. */ for both functions. It's ok to push with that fixed. Simon