From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64620 invoked by alias); 20 Jun 2017 10:31:37 -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 64601 invoked by uid 89); 20 Jun 2017 10:31:35 -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,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f196.google.com Received: from mail-io0-f196.google.com (HELO mail-io0-f196.google.com) (209.85.223.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Jun 2017 10:31:33 +0000 Received: by mail-io0-f196.google.com with SMTP id a96so14257082ioj.1 for ; Tue, 20 Jun 2017 03:31:33 -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=3E890K7no878RMaKA7naYF9qDqr9D2im8lEoz6J9qzI=; b=syhyS2pIjVWtNokbA2csQTyW0vT18xqAoyz5yoXuXZZXFVJlbnoHiWNMfdqYFiZn5i iSjNp7CabT3knnRq2fCOuXh6c0eNTtdC6NpWBFPFoP+w3j09OTcbvSmRWAHXoYLNFxrH I9CiRr3HQ4xxrm0xeNosvp0Xr6gLeaS5uUstYyLqAFhnX5rRY/4YIxupCHcivfY33y0g EUsFSWjAOTLwnmciquUo+HDkfWr38QhNokBKQBuSAS1Rtr8tXZvCqdC8mkVBPv/UfjOb N/gNha5YOaxxGmg4n45ONijN7Lv72vCVB4XylceMaLfrH/LYVAoFIYvCr6QWY8VHc6+C 8EiA== X-Gm-Message-State: AKS2vOw82BIHmXKMhAJyR6Hrs/YQRcytwZbrH3/Ffb4vJPP39jLaWf4n JCOjClVWoeJu2VBt X-Received: by 10.107.4.19 with SMTP id 19mr25235830ioe.95.1497954691401; Tue, 20 Jun 2017 03:31:31 -0700 (PDT) Received: from E107787-LIN (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id y188sm8354683ity.9.2017.06.20.03.31.29 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 20 Jun 2017 03:31:30 -0700 (PDT) From: Yao Qi To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature References: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> <1497256916-4958-4-git-send-email-yao.qi@linaro.org> <9f54f8e4d6eec605f0620ceeae7d6842@polymtl.ca> Date: Tue, 20 Jun 2017 10:31:00 -0000 In-Reply-To: <9f54f8e4d6eec605f0620ceeae7d6842@polymtl.ca> (Simon Marchi's message of "Mon, 19 Jun 2017 23:30:28 +0200") Message-ID: <8660fr54sf.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-06/txt/msg00559.txt.bz2 Simon Marchi writes: > Oh, I forgot to mention: you could take this opportunity to make these > expression respect our coding style (use !=3D NULL to check for NULL > pointer). Thanks for the review. They are fixed. Patch below is pushed in. --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom 72ddacb77e3301a0481003a23b2d8dced7116de5 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Tue, 20 Jun 2017 11:29:17 +0100 Subject: [PATCH] Class-fy tdesc_reg tdesc_type and tdesc_feature This patch class-fies them, adding ctor, dtor, and deleting copy ctor and assignment operator. gdb: 2017-06-20 Yao Qi * target-descriptions.c (tdesc_reg): Add ctor, dtor. Delete copy ctor and assignment operator. (tdesc_type): Likewise. (tdesc_feature): Likewise. (tdesc_free_reg): Remove. (tdesc_create_reg): Use new. (tdesc_free_type): Remove. (tdesc_create_vector): Use new. (tdesc_create_union): Likewise. (tdesc_create_flags): Likewise. (tdesc_create_enum): Likewise. (tdesc_free_feature): Delete. (free_target_description): Use delete. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4e091d7..c1998bb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,19 @@ +2017-06-20 Yao Qi + + * target-descriptions.c (tdesc_reg): Add ctor, dtor. + Delete copy ctor and assignment operator. + (tdesc_type): Likewise. + (tdesc_feature): Likewise. + (tdesc_free_reg): Remove. + (tdesc_create_reg): Use new. + (tdesc_free_type): Remove. + (tdesc_create_vector): Use new. + (tdesc_create_union): Likewise. + (tdesc_create_flags): Likewise. + (tdesc_create_enum): Likewise. + (tdesc_free_feature): Delete. + (free_target_description): Use delete. + 2017-06-19 John Baldwin =20 * mips-tdep.c (print_gp_register_row): Don't error for unavailable diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 9a7e2dd..0b5b46f 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -48,6 +48,31 @@ DEF_VEC_O(property_s); =20 typedef struct tdesc_reg { + tdesc_reg (struct tdesc_feature *feature, const char *name_, + int regnum, int save_restore_, const char *group_, + int bitsize_, const char *type_) + : name (xstrdup (name_)), target_regnum (regnum), + save_restore (save_restore_), + group (group_ !=3D NULL ? xstrdup (group_) : NULL), + bitsize (bitsize_), + type (type_ !=3D NULL ? xstrdup (type_) : xstrdup ("")) + { + /* If the register's type is target-defined, look it up now. We may n= ot + have easy access to the containing feature when we want it later. = */ + tdesc_type =3D tdesc_named_type (feature, type); + } + + ~tdesc_reg () + { + xfree (name); + xfree (type); + xfree (group); + } + + /* Disable copying. */ + tdesc_reg (const tdesc_reg &) =3D delete; + tdesc_reg &operator=3D (const tdesc_reg &) =3D delete; + /* The name of this register. In standard features, it may be recognized by the architecture support code, or it may be purely for the user. */ @@ -128,6 +153,42 @@ enum tdesc_type_kind =20 typedef struct tdesc_type { + tdesc_type (const char *name_, enum tdesc_type_kind kind_) + : name (xstrdup (name_)), kind (kind_) + { + memset (&u, 0, sizeof (u)); + } + + ~tdesc_type () + { + switch (kind) + { + case TDESC_TYPE_STRUCT: + case TDESC_TYPE_UNION: + case TDESC_TYPE_FLAGS: + case TDESC_TYPE_ENUM: + { + struct tdesc_type_field *f; + int ix; + + for (ix =3D 0; + VEC_iterate (tdesc_type_field, u.u.fields, ix, f); + ix++) + xfree (f->name); + + VEC_free (tdesc_type_field, u.u.fields); + } + break; + + default: + break; + } + xfree ((char *) name); + } + /* Disable copying. */ + tdesc_type (const tdesc_type &) =3D delete; + tdesc_type &operator=3D (const tdesc_type &) =3D delete; + /* The name of this type. If this type is a built-in type, this is a pointer to a constant string. Otherwise, it's a malloc-allocated string (and thus must be freed). */ @@ -161,15 +222,40 @@ DEF_VEC_P(tdesc_type_p); =20 typedef struct tdesc_feature { + tdesc_feature (const char *name_) + : name (xstrdup (name_)) + {} + + ~tdesc_feature () + { + struct tdesc_reg *reg; + struct tdesc_type *type; + int ix; + + for (ix =3D 0; VEC_iterate (tdesc_reg_p, registers, ix, reg); ix++) + delete reg; + VEC_free (tdesc_reg_p, registers); + + for (ix =3D 0; VEC_iterate (tdesc_type_p, types, ix, type); ix++) + delete type; + VEC_free (tdesc_type_p, types); + + xfree (name); + } + + /* Disable copying. */ + tdesc_feature (const tdesc_feature &) =3D delete; + tdesc_feature &operator=3D (const tdesc_feature &) =3D delete; + /* The name of this feature. It may be recognized by the architecture support code. */ char *name; =20 /* The registers associated with this feature. */ - VEC(tdesc_reg_p) *registers; + VEC(tdesc_reg_p) *registers =3D NULL; =20 /* The types associated with this feature. */ - VEC(tdesc_type_p) *types; + VEC(tdesc_type_p) *types =3D NULL; } *tdesc_feature_p; DEF_VEC_P(tdesc_feature_p); =20 @@ -1274,81 +1360,23 @@ tdesc_use_registers (struct gdbarch *gdbarch, } =0C =20 -/* Methods for constructing a target description. */ - -static void -tdesc_free_reg (struct tdesc_reg *reg) -{ - xfree (reg->name); - xfree (reg->type); - xfree (reg->group); - xfree (reg); -} - void tdesc_create_reg (struct tdesc_feature *feature, const char *name, int regnum, int save_restore, const char *group, int bitsize, const char *type) { - struct tdesc_reg *reg =3D XCNEW (struct tdesc_reg); - - reg->name =3D xstrdup (name); - reg->target_regnum =3D regnum; - reg->save_restore =3D save_restore; - reg->group =3D group ? xstrdup (group) : NULL; - reg->bitsize =3D bitsize; - reg->type =3D type ? xstrdup (type) : xstrdup (""); - - /* If the register's type is target-defined, look it up now. We may not - have easy access to the containing feature when we want it later. */ - reg->tdesc_type =3D tdesc_named_type (feature, reg->type); + tdesc_reg *reg =3D new tdesc_reg (feature, name, regnum, save_restore, + group, bitsize, type); =20 VEC_safe_push (tdesc_reg_p, feature->registers, reg); } =20 -/* Subroutine of tdesc_free_feature to simplify it. - Note: We do not want to free any referenced types here (e.g., types of - fields of a struct). All types of a feature are recorded in - feature->types and are freed that way. */ - -static void -tdesc_free_type (struct tdesc_type *type) -{ - switch (type->kind) - { - case TDESC_TYPE_STRUCT: - case TDESC_TYPE_UNION: - case TDESC_TYPE_FLAGS: - case TDESC_TYPE_ENUM: - { - struct tdesc_type_field *f; - int ix; - - for (ix =3D 0; - VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f); - ix++) - xfree (f->name); - - VEC_free (tdesc_type_field, type->u.u.fields); - } - break; - - default: - break; - } - - xfree ((char *) type->name); - xfree (type); -} - struct tdesc_type * tdesc_create_vector (struct tdesc_feature *feature, const char *name, struct tdesc_type *field_type, int count) { - struct tdesc_type *type =3D XCNEW (struct tdesc_type); + struct tdesc_type *type =3D new tdesc_type (name, TDESC_TYPE_VECTOR); =20 - type->name =3D xstrdup (name); - type->kind =3D TDESC_TYPE_VECTOR; type->u.v.type =3D field_type; type->u.v.count =3D count; =20 @@ -1359,10 +1387,7 @@ tdesc_create_vector (struct tdesc_feature *feature, = const char *name, struct tdesc_type * tdesc_create_struct (struct tdesc_feature *feature, const char *name) { - struct tdesc_type *type =3D XCNEW (struct tdesc_type); - - type->name =3D xstrdup (name); - type->kind =3D TDESC_TYPE_STRUCT; + struct tdesc_type *type =3D new tdesc_type (name, TDESC_TYPE_STRUCT); =20 VEC_safe_push (tdesc_type_p, feature->types, type); return type; @@ -1383,10 +1408,7 @@ tdesc_set_struct_size (struct tdesc_type *type, int = size) struct tdesc_type * tdesc_create_union (struct tdesc_feature *feature, const char *name) { - struct tdesc_type *type =3D XCNEW (struct tdesc_type); - - type->name =3D xstrdup (name); - type->kind =3D TDESC_TYPE_UNION; + struct tdesc_type *type =3D new tdesc_type (name, TDESC_TYPE_UNION); =20 VEC_safe_push (tdesc_type_p, feature->types, type); return type; @@ -1396,12 +1418,10 @@ struct tdesc_type * tdesc_create_flags (struct tdesc_feature *feature, const char *name, int size) { - struct tdesc_type *type =3D XCNEW (struct tdesc_type); + struct tdesc_type *type =3D new tdesc_type (name, TDESC_TYPE_FLAGS); =20 gdb_assert (size > 0); =20 - type->name =3D xstrdup (name); - type->kind =3D TDESC_TYPE_FLAGS; type->u.u.size =3D size; =20 VEC_safe_push (tdesc_type_p, feature->types, type); @@ -1412,12 +1432,10 @@ struct tdesc_type * tdesc_create_enum (struct tdesc_feature *feature, const char *name, int size) { - struct tdesc_type *type =3D XCNEW (struct tdesc_type); + struct tdesc_type *type =3D new tdesc_type (name, TDESC_TYPE_ENUM); =20 gdb_assert (size > 0); =20 - type->name =3D xstrdup (name); - type->kind =3D TDESC_TYPE_ENUM; type->u.u.size =3D size; =20 VEC_safe_push (tdesc_type_p, feature->types, type); @@ -1521,31 +1539,10 @@ tdesc_add_enum_value (struct tdesc_type *type, int = value, VEC_safe_push (tdesc_type_field, type->u.u.fields, &f); } =20 -static void -tdesc_free_feature (struct tdesc_feature *feature) -{ - struct tdesc_reg *reg; - struct tdesc_type *type; - int ix; - - for (ix =3D 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); i= x++) - tdesc_free_reg (reg); - VEC_free (tdesc_reg_p, feature->registers); - - for (ix =3D 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix+= +) - tdesc_free_type (type); - VEC_free (tdesc_type_p, feature->types); - - xfree (feature->name); - xfree (feature); -} - struct tdesc_feature * tdesc_create_feature (struct target_desc *tdesc, const char *name) { - struct tdesc_feature *new_feature =3D XCNEW (struct tdesc_feature); - - new_feature->name =3D xstrdup (name); + struct tdesc_feature *new_feature =3D new tdesc_feature (name); =20 VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature); return new_feature; @@ -1568,7 +1565,7 @@ free_target_description (void *arg) for (ix =3D 0; VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature); ix++) - tdesc_free_feature (feature); + delete feature; VEC_free (tdesc_feature_p, target_desc->features); =20 for (ix =3D 0;