public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature
Date: Tue, 20 Jun 2017 10:31:00 -0000	[thread overview]
Message-ID: <8660fr54sf.fsf@gmail.com> (raw)
In-Reply-To: <9f54f8e4d6eec605f0620ceeae7d6842@polymtl.ca> (Simon Marchi's	message of "Mon, 19 Jun 2017 23:30:28 +0200")

Simon Marchi <simon.marchi@polymtl.ca> writes:

> Oh, I forgot to mention: you could take this opportunity to make these
> expression respect our coding style (use != NULL to check for NULL
> pointer).

Thanks for the review.  They are fixed.  Patch below is pushed in.

-- 
Yao (齐尧)
From 72ddacb77e3301a0481003a23b2d8dced7116de5 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
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  <yao.qi@linaro.org>

	* 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  <yao.qi@linaro.org>
+
+	* 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  <jhb@FreeBSD.org>
 
 	* 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);
 
 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_ != NULL ? xstrdup (group_) : NULL),
+      bitsize (bitsize_),
+      type (type_ != NULL ? xstrdup (type_) : xstrdup ("<unknown>"))
+  {
+    /* 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.  */
+    tdesc_type = tdesc_named_type (feature, type);
+  }
+
+  ~tdesc_reg ()
+  {
+    xfree (name);
+    xfree (type);
+    xfree (group);
+  }
+
+  /* Disable copying.  */
+  tdesc_reg (const tdesc_reg &) = delete;
+  tdesc_reg &operator= (const tdesc_reg &) = 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
 
 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 = 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 &) = delete;
+  tdesc_type &operator= (const tdesc_type &) = 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);
 
 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 = 0; VEC_iterate (tdesc_reg_p, registers, ix, reg); ix++)
+      delete reg;
+    VEC_free (tdesc_reg_p, registers);
+
+    for (ix = 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 &) = delete;
+  tdesc_feature &operator= (const tdesc_feature &) = delete;
+
   /* The name of this feature.  It may be recognized by the architecture
      support code.  */
   char *name;
 
   /* The registers associated with this feature.  */
-  VEC(tdesc_reg_p) *registers;
+  VEC(tdesc_reg_p) *registers = NULL;
 
   /* The types associated with this feature.  */
-  VEC(tdesc_type_p) *types;
+  VEC(tdesc_type_p) *types = NULL;
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
@@ -1274,81 +1360,23 @@ tdesc_use_registers (struct gdbarch *gdbarch,
 }
 \f
 
-/* 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 = XCNEW (struct tdesc_reg);
-
-  reg->name = xstrdup (name);
-  reg->target_regnum = regnum;
-  reg->save_restore = save_restore;
-  reg->group = group ? xstrdup (group) : NULL;
-  reg->bitsize = bitsize;
-  reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
-
-  /* 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 = tdesc_named_type (feature, reg->type);
+  tdesc_reg *reg = new tdesc_reg (feature, name, regnum, save_restore,
+				  group, bitsize, type);
 
   VEC_safe_push (tdesc_reg_p, feature->registers, reg);
 }
 
-/* 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 = 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 = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_VECTOR);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_VECTOR;
   type->u.v.type = field_type;
   type->u.v.count = count;
 
@@ -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 = XCNEW (struct tdesc_type);
-
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_STRUCT;
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_STRUCT);
 
   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 = XCNEW (struct tdesc_type);
-
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_UNION;
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_UNION);
 
   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 = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_FLAGS);
 
   gdb_assert (size > 0);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_FLAGS;
   type->u.u.size = size;
 
   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 = XCNEW (struct tdesc_type);
+  struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_ENUM);
 
   gdb_assert (size > 0);
 
-  type->name = xstrdup (name);
-  type->kind = TDESC_TYPE_ENUM;
   type->u.u.size = size;
 
   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);
 }
 
-static void
-tdesc_free_feature (struct tdesc_feature *feature)
-{
-  struct tdesc_reg *reg;
-  struct tdesc_type *type;
-  int ix;
-
-  for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
-    tdesc_free_reg (reg);
-  VEC_free (tdesc_reg_p, feature->registers);
-
-  for (ix = 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 = XCNEW (struct tdesc_feature);
-
-  new_feature->name = xstrdup (name);
+  struct tdesc_feature *new_feature = new tdesc_feature (name);
 
   VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
   return new_feature;
@@ -1568,7 +1565,7 @@ free_target_description (void *arg)
   for (ix = 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);
 
   for (ix = 0;

  reply	other threads:[~2017-06-20 10:31 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-12  8:42 [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Yao Qi
2017-06-12  8:42 ` [PATCH 01/25] Move initialize_tdesc_mips* calls from mips-linux-nat.c to mips-linux-tdep.c Yao Qi
2017-06-12 15:25   ` Maciej W. Rozycki
2017-06-13  8:07     ` Yao Qi
2017-06-12  8:42 ` [PATCH 20/25] Centralize amd64-linux target descriptions Yao Qi
2017-06-12  8:42 ` [PATCH 14/25] [RFC] GDBserver self test Yao Qi
2017-06-28 17:09   ` Pedro Alves
2017-06-29  9:08     ` Yao Qi
2017-06-12  8:42 ` [PATCH 02/25] Adjust the order of 32bit-linux.xml and 32bit-sse.xml in i386/i386-linux.xml Yao Qi
2017-06-19 20:22   ` Simon Marchi
2017-06-19 21:24     ` Pedro Alves
2017-06-19 21:48       ` Simon Marchi
2017-06-19 21:56         ` Pedro Alves
2017-06-20  9:20           ` Yao Qi
2017-06-20 10:12             ` Pedro Alves
2017-06-20 11:09               ` Yao Qi
2017-06-12  8:42 ` [PATCH 15/25] [RFC] GDBserver unit test to i386_tdesc Yao Qi
2017-06-28 17:22   ` Pedro Alves
2017-06-29  9:27     ` Yao Qi
2017-06-12  8:42 ` [PATCH 17/25] Remove features/i386/i386-*linux.c Yao Qi
2017-06-12  8:42 ` [PATCH 23/25] [GDBserver] Convert amd64-linux target descriptions Yao Qi
2017-06-28 19:00   ` Pedro Alves
2017-06-12  8:42 ` [PATCH 04/25] Centralize i386 linux " Yao Qi
2017-06-19 21:27   ` Simon Marchi
2017-06-12  8:42 ` [PATCH 25/25] Remove features/i386/amd64-*linux.c and features/i386/x32-*linux.c Yao Qi
2017-06-12  8:42 ` [PATCH 08/25] Add "maint check xml-descriptions" to test builtin xml target descriptions Yao Qi
2017-06-28 16:13   ` Pedro Alves
2017-06-12  8:42 ` [PATCH 05/25] Use visitor pattern for "maint print c-tdesc" Yao Qi
2017-06-20 23:37   ` Simon Marchi
2017-06-12  8:42 ` [PATCH 11/25] Use VEC for target_desc.reg_defs Yao Qi
2017-06-28 19:01   ` Pedro Alves
2017-06-29 11:05     ` Yao Qi
2017-06-29 11:31       ` Pedro Alves
2017-06-29 13:24         ` Yao Qi
2017-06-12  8:42 ` [PATCH 18/25] [GDBserver] Use pre-generated tdesc as test Yao Qi
2017-06-12  8:42 ` [PATCH 06/25] Generate c for feature instead of tdesc Yao Qi
2017-06-12 14:48   ` Eli Zaretskii
2017-06-13 12:07     ` Yao Qi
2017-06-13 14:49       ` Eli Zaretskii
2017-06-13 15:31         ` Yao Qi
2017-06-13 15:41           ` Eli Zaretskii
2017-06-14 16:21             ` Yao Qi
2017-06-14 16:32               ` Eli Zaretskii
2017-06-15 13:19                 ` Yao Qi
2017-06-15 14:45                   ` Eli Zaretskii
2017-06-20 10:59   ` Pedro Alves
2017-06-22 14:49     ` Yao Qi
2017-06-22 15:36       ` Pedro Alves
2017-06-22 15:58         ` Yao Qi
2017-06-26 21:38   ` Simon Marchi
2017-06-29 15:24     ` Yao Qi
2017-06-12  8:42 ` [PATCH 12/25] [GDBserver] Centralize tdesc for i386-linux Yao Qi
2017-06-12  8:42 ` [PATCH 13/25] Dynamically create tdesc in GDBserver Yao Qi
2017-06-12  8:42 ` [PATCH 21/25] Lazily and dynamically create amd64-linux target descriptions Yao Qi
2017-06-12  8:42 ` [PATCH 16/25] Dynamically composite xml in reply to GDB Yao Qi
2017-06-12  8:42 ` [PATCH 24/25] [GDBserver] Use pre-generated amd64-linux tdesc as test Yao Qi
2017-06-12  8:42 ` [PATCH 22/25] Regenerate two regformats/i386/.dat files Yao Qi
2017-06-22 12:43   ` Yao Qi
2017-06-12  8:42 ` [PATCH 09/25] Use target_desc fields expedite_regs and xmltarget ifndef IN_PROCESS_AGENT Yao Qi
2017-06-28 16:16   ` Pedro Alves
2017-06-28 17:42     ` Pedro Alves
2017-06-28 17:45       ` Pedro Alves
2017-06-29 11:45     ` Yao Qi
2017-06-12  8:42 ` [PATCH 07/25] Lazily and dynamically create i386-linux target descriptions Yao Qi
2017-06-20 11:01   ` Pedro Alves
2017-06-20 14:07     ` Yao Qi
2017-06-28 15:30       ` Pedro Alves
2017-06-12  8:42 ` [PATCH 19/25] GDBserver: remove srv_i386_linux_xmlfiles Yao Qi
2017-06-12  8:42 ` [PATCH 03/25] Class-fy tdesc_reg tdesc_type and tdesc_feature Yao Qi
2017-06-19 20:55   ` Simon Marchi
2017-06-19 21:30   ` Simon Marchi
2017-06-20 10:31     ` Yao Qi [this message]
2017-06-12  8:42 ` [PATCH 10/25] Adjust code generated by regformats/regdat.sh Yao Qi
2017-06-20 11:09   ` Pedro Alves
2017-06-21 14:28     ` Yao Qi
2017-06-19 19:59 ` [PATCH 00/25 V2] Make GDB builtin target descriptions more flexible Simon Marchi
2017-06-20 11:02   ` Yao Qi
2017-06-26 14:45   ` Tedeschi, Walfred
2017-06-27 13:49     ` Alan Hayward
2017-06-28  8:28       ` Yao Qi
2017-06-28  8:06     ` Yao Qi
2017-06-28 19:06 ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8660fr54sf.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).