From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>
Subject: [PATCH/RFA] Do not emit "field_type" var if not needed on "maint print c-tdesc"
Date: Tue, 19 Dec 2017 19:18:00 -0000 [thread overview]
Message-ID: <20171219191817.7554-1-sergiodj@redhat.com> (raw)
While fiddling a bit with -Wunused-variable, I noticed that "maint
print c-tdesc" was always generating code for the
"tdesc_type *field_type" variable, even when it wasn't used. This is
caught by GCC when using -Wunused-variable, of course. So I modified
the "print_c_tdesc" class to check whether "field_type" will be needed
or not.
In order to do the check, I basically copied the logic implemented on
"void visit (const tdesc_type_with_fields *type)", specifically the
"switch" part, and simplified it to determine which types need
"field_type". It's on a new simple function called
"need_field_type". Then, we can simply call this function when
deciding whether to print "field_type", and that's it.
I've also regenerated all the C files under gdb/features/, and as
expected only those that don't need "field_type" were modified.
yyyy-mm-dd Sergio Durigan Junior <sergiodj@redhat.com>
* features/aarch64-core.c: Regenerate.
* features/arc-arcompact.c: Regenerate.
* features/arc-v2.c: Regenerate.
* features/i386/32bit-core.c: Regenerate.
* features/i386/64bit-core.c: Regenerate.
* features/i386/x32-core.c: Regenerate.
* features/or1k.c: Regenerate.
* target-descriptions.c (class print_c_tdesc)
<need_field_type>: New method.
---
gdb/features/aarch64-core.c | 1 -
gdb/features/arc-arcompact.c | 1 -
gdb/features/arc-v2.c | 1 -
gdb/features/i386/32bit-core.c | 1 -
gdb/features/i386/64bit-core.c | 1 -
gdb/features/i386/x32-core.c | 1 -
gdb/features/or1k.c | 1 -
gdb/target-descriptions.c | 41 ++++++++++++++++++++++++++++++++++++++++-
8 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/gdb/features/aarch64-core.c b/gdb/features/aarch64-core.c
index 618a7ef787..3707b7e055 100644
--- a/gdb/features/aarch64-core.c
+++ b/gdb/features/aarch64-core.c
@@ -10,7 +10,6 @@ create_feature_aarch64_core (struct target_desc *result, long regnum)
feature = tdesc_create_feature (result, "org.gnu.gdb.aarch64.core", "aarch64-core.xml");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "cpsr_flags", 4);
tdesc_add_flag (type_with_fields, 0, "SP");
tdesc_add_flag (type_with_fields, 1, "");
diff --git a/gdb/features/arc-arcompact.c b/gdb/features/arc-arcompact.c
index 79b6889172..f81f0a26ba 100644
--- a/gdb/features/arc-arcompact.c
+++ b/gdb/features/arc-arcompact.c
@@ -52,7 +52,6 @@ initialize_tdesc_arc_arcompact (void)
feature = tdesc_create_feature (result, "org.gnu.gdb.arc.aux-minimal");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "status32_type", 4);
tdesc_add_flag (type_with_fields, 0, "H");
tdesc_add_bitfield (type_with_fields, "E", 1, 2);
diff --git a/gdb/features/arc-v2.c b/gdb/features/arc-v2.c
index 9908b4c5ec..b2254b293c 100644
--- a/gdb/features/arc-v2.c
+++ b/gdb/features/arc-v2.c
@@ -52,7 +52,6 @@ initialize_tdesc_arc_v2 (void)
feature = tdesc_create_feature (result, "org.gnu.gdb.arc.aux-minimal");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "status32_type", 4);
tdesc_add_flag (type_with_fields, 0, "H");
tdesc_add_bitfield (type_with_fields, "E", 1, 4);
diff --git a/gdb/features/i386/32bit-core.c b/gdb/features/i386/32bit-core.c
index de2ce474d5..294e86d81e 100644
--- a/gdb/features/i386/32bit-core.c
+++ b/gdb/features/i386/32bit-core.c
@@ -10,7 +10,6 @@ create_feature_i386_32bit_core (struct target_desc *result, long regnum)
feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core", "32bit-core.xml");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "i386_eflags", 4);
tdesc_add_flag (type_with_fields, 0, "CF");
tdesc_add_flag (type_with_fields, 1, "");
diff --git a/gdb/features/i386/64bit-core.c b/gdb/features/i386/64bit-core.c
index f4cad06e66..9e39ee42d9 100644
--- a/gdb/features/i386/64bit-core.c
+++ b/gdb/features/i386/64bit-core.c
@@ -10,7 +10,6 @@ create_feature_i386_64bit_core (struct target_desc *result, long regnum)
feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core", "64bit-core.xml");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "i386_eflags", 4);
tdesc_add_flag (type_with_fields, 0, "CF");
tdesc_add_flag (type_with_fields, 1, "");
diff --git a/gdb/features/i386/x32-core.c b/gdb/features/i386/x32-core.c
index acafc7dace..c268e11bea 100644
--- a/gdb/features/i386/x32-core.c
+++ b/gdb/features/i386/x32-core.c
@@ -10,7 +10,6 @@ create_feature_i386_x32_core (struct target_desc *result, long regnum)
feature = tdesc_create_feature (result, "org.gnu.gdb.i386.core", "x32-core.xml");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "i386_eflags", 4);
tdesc_add_flag (type_with_fields, 0, "CF");
tdesc_add_flag (type_with_fields, 1, "");
diff --git a/gdb/features/or1k.c b/gdb/features/or1k.c
index 929a5f9208..9169cae940 100644
--- a/gdb/features/or1k.c
+++ b/gdb/features/or1k.c
@@ -16,7 +16,6 @@ initialize_tdesc_or1k (void)
feature = tdesc_create_feature (result, "org.gnu.gdb.or1k.group0");
tdesc_type_with_fields *type_with_fields;
- tdesc_type *field_type;
type_with_fields = tdesc_create_flags (feature, "sr_flags", 4);
tdesc_add_flag (type_with_fields, 0, "SM");
tdesc_add_flag (type_with_fields, 1, "TEE");
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 88ac55f404..fe4b5efbf5 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -1886,6 +1886,44 @@ public:
printf_unfiltered ("\n");
}
+ /* Some targets don't need the "tdesc_type *field_type" variable.
+ This function returns true if TYPE is going to need it, false
+ otherwise. */
+ bool need_field_type (const tdesc_type_with_fields *type)
+ {
+ switch (type->kind)
+ {
+ case TDESC_TYPE_UNION:
+ return true;
+
+ case TDESC_TYPE_ENUM:
+ return false;
+
+ case TDESC_TYPE_STRUCT:
+ case TDESC_TYPE_FLAGS:
+ for (const tdesc_type_field &f : type->fields)
+ {
+ if (f.start != -1)
+ {
+ if (f.type->kind == TDESC_TYPE_BOOL)
+ continue;
+ else if ((type->size == 4 && f.type->kind == TDESC_TYPE_UINT32)
+ || (type->size == 8
+ && f.type->kind == TDESC_TYPE_UINT64))
+ continue;
+ else
+ return true;
+ }
+ else /* Not a bitfield. */
+ return true;
+ }
+ break;
+ default:
+ error (_("C output is not supported type \"%s\"."), type->name.c_str ());
+ }
+ return false;
+ }
+
void visit (const tdesc_type_with_fields *type) override
{
if (!m_printed_type_with_fields)
@@ -1895,7 +1933,8 @@ public:
}
if (!type->fields.empty ()
- && !m_printed_field_type)
+ && !m_printed_field_type
+ && need_field_type (type))
{
printf_unfiltered (" tdesc_type *field_type;\n");
m_printed_field_type = true;
--
2.14.3
next reply other threads:[~2017-12-19 19:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-19 19:18 Sergio Durigan Junior [this message]
2017-12-19 20:16 ` Simon Marchi
2017-12-19 20:51 ` Sergio Durigan Junior
2017-12-21 9:10 ` Yao Qi
2017-12-21 23:24 ` Simon Marchi
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=20171219191817.7554-1-sergiodj@redhat.com \
--to=sergiodj@redhat.com \
--cc=gdb-patches@sourceware.org \
/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