From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 08/10] Make tdesc_type::name an std::string
Date: Tue, 31 Oct 2017 01:42:00 -0000 [thread overview]
Message-ID: <1509414120-14659-9-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1509414120-14659-1-git-send-email-simon.marchi@ericsson.com>
From: Simon Marchi <simon.marchi@polymtl.ca>
This patch makes tdesc_type::name an std::string. This way, we don't
need to free it manually in ~tdesc_type. I think the comment on top of
name is not correct, the string is always malloc'ed.
gdb/ChangeLog:
* target-descriptions.c (struct tdesc_type) <name>: Change type
to std::string.
<~tdesc_type>: Don't manually free name.
<operator==>: Adjust.
(tdesc_named_type): Adjust.
(tdesc_find_type): Adjust.
(tdesc_gdb_type): Adjust.
(class print_c_tdesc) <visit>: Adjust.
---
gdb/target-descriptions.c | 51 ++++++++++++++++++++++-------------------------
1 file changed, 24 insertions(+), 27 deletions(-)
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 13d6884..77a9c1c 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -194,8 +194,8 @@ enum tdesc_type_kind
struct tdesc_type : tdesc_element
{
- tdesc_type (const char *name_, enum tdesc_type_kind kind_)
- : name (xstrdup (name_)), kind (kind_)
+ tdesc_type (const std::string &name_, enum tdesc_type_kind kind_)
+ : name (name_), kind (kind_)
{
memset (&u, 0, sizeof (u));
}
@@ -224,15 +224,12 @@ struct tdesc_type : tdesc_element
default:
break;
}
- xfree ((char *) name);
}
DISABLE_COPY_AND_ASSIGN (tdesc_type);
- /* 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). */
- const char *name;
+ /* The name of this type. */
+ std::string name;
/* Identify the kind of this type. */
enum tdesc_type_kind kind;
@@ -262,7 +259,7 @@ struct tdesc_type : tdesc_element
bool operator== (const tdesc_type &other) const
{
- return (streq (name, other.name) && kind == other.kind);
+ return name == other.name && kind == other.kind;
}
bool operator!= (const tdesc_type &other) const
@@ -761,12 +758,12 @@ tdesc_named_type (const struct tdesc_feature *feature, const char *id)
{
/* First try target-defined types. */
for (const tdesc_type_up &type : feature->types)
- if (strcmp (type->name, id) == 0)
+ if (type->name == id)
return type.get ();
/* Next try the predefined types. */
for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
- if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
+ if (tdesc_predefined_types[ix].name == id)
return &tdesc_predefined_types[ix];
return NULL;
@@ -789,7 +786,7 @@ tdesc_find_type (struct gdbarch *gdbarch, const char *id)
if (reg->reg
&& reg->reg->tdesc_type
&& reg->type
- && strcmp (id, reg->reg->tdesc_type->name) == 0)
+ && reg->reg->tdesc_type->name == id)
return reg->type;
}
@@ -850,7 +847,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
break;
}
- type = tdesc_find_type (gdbarch, tdesc_type->name);
+ type = tdesc_find_type (gdbarch, tdesc_type->name.c_str ());
if (type)
return type;
@@ -879,7 +876,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
type = init_vector_type (field_type, tdesc_type->u.v.count);
- TYPE_NAME (type) = xstrdup (tdesc_type->name);
+ TYPE_NAME (type) = xstrdup (tdesc_type->name.c_str ());
return type;
}
@@ -891,7 +888,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
int ix;
type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- TYPE_NAME (type) = xstrdup (tdesc_type->name);
+ TYPE_NAME (type) = xstrdup (tdesc_type->name.c_str ());
TYPE_TAG_NAME (type) = TYPE_NAME (type);
for (ix = 0;
@@ -953,7 +950,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
int ix;
type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- TYPE_NAME (type) = xstrdup (tdesc_type->name);
+ TYPE_NAME (type) = xstrdup (tdesc_type->name.c_str ());
for (ix = 0;
VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
@@ -976,7 +973,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
struct tdesc_type_field *f;
int ix;
- type = arch_flags_type (gdbarch, tdesc_type->name,
+ type = arch_flags_type (gdbarch, tdesc_type->name.c_str (),
tdesc_type->u.u.size * TARGET_CHAR_BIT);
for (ix = 0;
VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
@@ -1001,7 +998,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
type = arch_type (gdbarch, TYPE_CODE_ENUM,
tdesc_type->u.u.size * TARGET_CHAR_BIT,
- tdesc_type->name);
+ tdesc_type->name.c_str ());
TYPE_UNSIGNED (type) = 1;
for (ix = 0;
VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
@@ -1020,7 +1017,7 @@ tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
internal_error (__FILE__, __LINE__,
"Type \"%s\" has an unknown kind %d",
- tdesc_type->name, tdesc_type->kind);
+ tdesc_type->name.c_str (), tdesc_type->kind);
}
\f
@@ -1917,10 +1914,10 @@ public:
case TDESC_TYPE_VECTOR:
printf_unfiltered
(" field_type = tdesc_named_type (feature, \"%s\");\n",
- type->u.v.type->name);
+ type->u.v.type->name.c_str ());
printf_unfiltered
(" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
- type->name, type->u.v.count);
+ type->name.c_str (), type->u.v.count);
break;
case TDESC_TYPE_STRUCT:
case TDESC_TYPE_FLAGS:
@@ -1928,7 +1925,7 @@ public:
{
printf_unfiltered
(" type = tdesc_create_struct (feature, \"%s\");\n",
- type->name);
+ type->name.c_str ());
if (type->u.u.size != 0)
printf_unfiltered
(" tdesc_set_struct_size (type, %d);\n",
@@ -1938,7 +1935,7 @@ public:
{
printf_unfiltered
(" type = tdesc_create_flags (feature, \"%s\", %d);\n",
- type->name, type->u.u.size);
+ type->name.c_str (), type->u.u.size);
}
for (int ix3 = 0;
VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
@@ -1947,7 +1944,7 @@ public:
const char *type_name;
gdb_assert (f->type != NULL);
- type_name = f->type->name;
+ type_name = f->type->name.c_str ();
/* To minimize changes to generated files, don't emit type
info for fields that have defaulted types. */
@@ -1999,14 +1996,14 @@ public:
case TDESC_TYPE_UNION:
printf_unfiltered
(" type = tdesc_create_union (feature, \"%s\");\n",
- type->name);
+ type->name.c_str ());
for (int ix3 = 0;
VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
ix3++)
{
printf_unfiltered
(" field_type = tdesc_named_type (feature, \"%s\");\n",
- f->type->name);
+ f->type->name.c_str ());
printf_unfiltered
(" tdesc_add_field (type, \"%s\", field_type);\n",
f->name);
@@ -2015,7 +2012,7 @@ public:
case TDESC_TYPE_ENUM:
printf_unfiltered
(" type = tdesc_create_enum (feature, \"%s\", %d);\n",
- type->name, type->u.u.size);
+ type->name.c_str (), type->u.u.size);
for (int ix3 = 0;
VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
ix3++)
@@ -2024,7 +2021,7 @@ public:
f->start, f->name);
break;
default:
- error (_("C output is not supported type \"%s\"."), type->name);
+ error (_("C output is not supported type \"%s\"."), type->name.c_str ());
}
printf_unfiltered ("\n");
}
--
2.7.4
next prev parent reply other threads:[~2017-10-31 1:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-31 1:42 [PATCH 00/10] Use std::vector and std::string throughout target-descriptions.c Simon Marchi
2017-10-31 1:42 ` [PATCH 07/10] Make tdesc_feature::types an std::vector Simon Marchi
2017-10-31 1:42 ` [PATCH 01/10] Make target_desc::properties " Simon Marchi
2017-10-31 1:42 ` [PATCH 06/10] Make tdesc_reg string fields std::string Simon Marchi
2017-11-02 9:43 ` Yao Qi
2017-11-02 13:24 ` Simon Marchi
2017-10-31 1:42 ` [PATCH 03/10] Make target_desc::features an std::vector Simon Marchi
2017-11-02 9:29 ` Yao Qi
2017-11-02 13:20 ` Simon Marchi
2017-10-31 1:42 ` Simon Marchi [this message]
2017-10-31 1:42 ` [PATCH 09/10] Make tdesc_type::u::u::fields " Simon Marchi
2017-11-02 10:02 ` Yao Qi
2017-11-02 13:27 ` Simon Marchi
2017-12-03 16:04 ` [PATCH 11/10] Split tdesc_type into multiple classes Simon Marchi
2017-12-05 16:46 ` Yao Qi
2017-12-05 21:42 ` Simon Marchi
2017-10-31 1:42 ` [PATCH 10/10] Make tdesc_arch_data::arch_regs an std::vector Simon Marchi
2017-10-31 1:42 ` [PATCH 04/10] Make tdesc_feature::name an std::string Simon Marchi
2017-10-31 1:42 ` [PATCH 05/10] Make tdesc_feature::registers an std::vector Simon Marchi
2017-11-02 9:32 ` Yao Qi
2017-11-02 13:22 ` Simon Marchi
2017-10-31 1:43 ` [PATCH 02/10] Make target_desc::compatible " Simon Marchi
2017-11-02 10:16 ` [PATCH 00/10] Use std::vector and std::string throughout target-descriptions.c Yao Qi
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=1509414120-14659-9-git-send-email-simon.marchi@ericsson.com \
--to=simon.marchi@ericsson.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).