From patchwork Tue Dec 19 19:18:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 25023 Received: (qmail 50992 invoked by alias); 19 Dec 2017 19:18:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 50979 invoked by uid 89); 19 Dec 2017 19:18:29 -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, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=visit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Dec 2017 19:18:27 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87329C0A848F for ; Tue, 19 Dec 2017 19:18:26 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93CA484D2F; Tue, 19 Dec 2017 19:18:23 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Sergio Durigan Junior Subject: [PATCH/RFA] Do not emit "field_type" var if not needed on "maint print c-tdesc" Date: Tue, 19 Dec 2017 14:18:17 -0500 Message-Id: <20171219191817.7554-1-sergiodj@redhat.com> X-IsSubscribed: yes 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 * 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) : 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;