[PATCH/RFA] Do not emit "field_type" var if not needed on "maint print c-tdesc"

Simon Marchi simon.marchi@ericsson.com
Thu Dec 21 23:24:00 GMT 2017


On 2017-12-21 04:10 AM, Yao Qi wrote:
> Simon Marchi <simon.marchi@ericsson.com> writes:
> 
>> A simpler way would be to emit the field lazily when we actually need it, see patch
>> below for an example.  There's a bit more collateral damage in the generated files,
>> since some declarations change place.  We would need to do the same for the other
>> variable declarations.
> 
> Yes, your patch in target-descriptions.c is simpler.  The patch is good
> to me.
> 

Thanks, here's what I pushed.


>From a8d2e5856f87a658d69018fe1ccd56482eebdd59 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Thu, 21 Dec 2017 18:19:17 -0500
Subject: [PATCH] Do not emit "field_type" var if not needed on "maint print
 c-tdesc"

While fiddling a bit with -Wunused-variable, Sergio 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.

This patch changes the print_c_tdesc class to only output the field
declaration when we actually need it.

It shouldn't be necessary to do the same with the other variable
declarations (type_with_fields and element_type), because they are
always if they are declared.

The C files in features/ are regenerated, some declarations of
field_type are removed, as expected, while some others move to where
they are used for the first time.

gdb/ChangeLog:

	* target-descriptions.c (print_c_tdesc) <visit>: Don't output
	field_type declaration, use printf_field_type_assignment
	instead.
	<printf_field_type_assignment>: New method.
	* features/aarch64-core.c, features/aarch64-fpu.c
	features/arc-arcompact.c, features/arc-v2.c,
	features/arm/arm-with-iwmmxt.c, features/i386/32bit-core.c,
	features/i386/32bit-mpx.c, features/i386/32bit-sse.c,
	features/i386/64bit-avx512.c, features/i386/64bit-core.c,
	features/i386/64bit-mpx.c, features/i386/64bit-sse.c,
	features/i386/x32-core.c, features/or1k.c,
	features/rs6000/powerpc-7400.c,
	features/rs6000/powerpc-altivec32.c,
	features/rs6000/powerpc-altivec32l.c,
	features/rs6000/powerpc-altivec64.c,
	features/rs6000/powerpc-altivec64l.c,
	features/rs6000/powerpc-cell32l.c,
	features/rs6000/powerpc-cell64l.c,
	features/rs6000/powerpc-isa205-altivec32l.c,
	features/rs6000/powerpc-isa205-altivec64l.c,
	features/rs6000/powerpc-isa205-vsx32l.c,
	features/rs6000/powerpc-isa205-vsx64l.c,
	features/rs6000/powerpc-vsx32.c,
	features/rs6000/powerpc-vsx32l.c,
	features/rs6000/powerpc-vsx64.c,
	features/rs6000/powerpc-vsx64l.c, features/s390-gs-linux64.c,
	features/s390-tevx-linux64.c, features/s390-vx-linux64.c,
	features/s390x-gs-linux64.c, features/s390x-tevx-linux64.c,
	features/s390x-vx-linux64.c: Re-generate.
---
 gdb/ChangeLog                                   | 33 ++++++++++++++++++++
 gdb/features/aarch64-core.c                     |  1 -
 gdb/features/aarch64-fpu.c                      |  2 +-
 gdb/features/arc-arcompact.c                    |  1 -
 gdb/features/arc-v2.c                           |  1 -
 gdb/features/arm/arm-with-iwmmxt.c              |  2 +-
 gdb/features/i386/32bit-core.c                  |  1 -
 gdb/features/i386/32bit-mpx.c                   |  2 +-
 gdb/features/i386/32bit-sse.c                   |  2 +-
 gdb/features/i386/64bit-avx512.c                |  2 +-
 gdb/features/i386/64bit-core.c                  |  1 -
 gdb/features/i386/64bit-mpx.c                   |  2 +-
 gdb/features/i386/64bit-sse.c                   |  2 +-
 gdb/features/i386/x32-core.c                    |  1 -
 gdb/features/or1k.c                             |  1 -
 gdb/features/rs6000/powerpc-7400.c              |  2 +-
 gdb/features/rs6000/powerpc-altivec32.c         |  2 +-
 gdb/features/rs6000/powerpc-altivec32l.c        |  2 +-
 gdb/features/rs6000/powerpc-altivec64.c         |  2 +-
 gdb/features/rs6000/powerpc-altivec64l.c        |  2 +-
 gdb/features/rs6000/powerpc-cell32l.c           |  2 +-
 gdb/features/rs6000/powerpc-cell64l.c           |  2 +-
 gdb/features/rs6000/powerpc-isa205-altivec32l.c |  2 +-
 gdb/features/rs6000/powerpc-isa205-altivec64l.c |  2 +-
 gdb/features/rs6000/powerpc-isa205-vsx32l.c     |  2 +-
 gdb/features/rs6000/powerpc-isa205-vsx64l.c     |  2 +-
 gdb/features/rs6000/powerpc-vsx32.c             |  2 +-
 gdb/features/rs6000/powerpc-vsx32l.c            |  2 +-
 gdb/features/rs6000/powerpc-vsx64.c             |  2 +-
 gdb/features/rs6000/powerpc-vsx64l.c            |  2 +-
 gdb/features/s390-gs-linux64.c                  |  2 +-
 gdb/features/s390-tevx-linux64.c                |  2 +-
 gdb/features/s390-vx-linux64.c                  |  2 +-
 gdb/features/s390x-gs-linux64.c                 |  2 +-
 gdb/features/s390x-tevx-linux64.c               |  2 +-
 gdb/features/s390x-vx-linux64.c                 |  2 +-
 gdb/target-descriptions.c                       | 41 +++++++++++++++----------
 37 files changed, 86 insertions(+), 51 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4f2c5c3..1b4b13a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,36 @@
+2017-12-21  Simon Marchi  <simon.marchi@ericsson.com>
+	    Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	* target-descriptions.c (print_c_tdesc) <visit>: Don't output
+	field_type declaration, use printf_field_type_assignment
+	instead.
+	<printf_field_type_assignment>: New method.
+	* features/aarch64-core.c, features/aarch64-fpu.c
+	features/arc-arcompact.c, features/arc-v2.c,
+	features/arm/arm-with-iwmmxt.c, features/i386/32bit-core.c,
+	features/i386/32bit-mpx.c, features/i386/32bit-sse.c,
+	features/i386/64bit-avx512.c, features/i386/64bit-core.c,
+	features/i386/64bit-mpx.c, features/i386/64bit-sse.c,
+	features/i386/x32-core.c, features/or1k.c,
+	features/rs6000/powerpc-7400.c,
+	features/rs6000/powerpc-altivec32.c,
+	features/rs6000/powerpc-altivec32l.c,
+	features/rs6000/powerpc-altivec64.c,
+	features/rs6000/powerpc-altivec64l.c,
+	features/rs6000/powerpc-cell32l.c,
+	features/rs6000/powerpc-cell64l.c,
+	features/rs6000/powerpc-isa205-altivec32l.c,
+	features/rs6000/powerpc-isa205-altivec64l.c,
+	features/rs6000/powerpc-isa205-vsx32l.c,
+	features/rs6000/powerpc-isa205-vsx64l.c,
+	features/rs6000/powerpc-vsx32.c,
+	features/rs6000/powerpc-vsx32l.c,
+	features/rs6000/powerpc-vsx64.c,
+	features/rs6000/powerpc-vsx64l.c, features/s390-gs-linux64.c,
+	features/s390-tevx-linux64.c, features/s390-vx-linux64.c,
+	features/s390x-gs-linux64.c, features/s390x-tevx-linux64.c,
+	features/s390x-vx-linux64.c: Re-generate.
+
 2017-12-20  Uros Bizjak  <ubizjak@gmail.com>

 	* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Remove
diff --git a/gdb/features/aarch64-core.c b/gdb/features/aarch64-core.c
index 618a7ef..3707b7e 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/aarch64-fpu.c b/gdb/features/aarch64-fpu.c
index 7328eb1..cac3981 100644
--- a/gdb/features/aarch64-fpu.c
+++ b/gdb/features/aarch64-fpu.c
@@ -47,8 +47,8 @@ create_feature_aarch64_fpu (struct target_desc *result, long regnum)
   tdesc_create_vector (feature, "v1i", element_type, 1);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vnd");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v2d");
   tdesc_add_field (type_with_fields, "f", field_type);
   field_type = tdesc_named_type (feature, "v2u");
diff --git a/gdb/features/arc-arcompact.c b/gdb/features/arc-arcompact.c
index 79b6889..f81f0a2 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 9908b4c..b2254b2 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/arm/arm-with-iwmmxt.c b/gdb/features/arm/arm-with-iwmmxt.c
index 5d6c357..8729285 100644
--- a/gdb/features/arm/arm-with-iwmmxt.c
+++ b/gdb/features/arm/arm-with-iwmmxt.c
@@ -45,8 +45,8 @@ initialize_tdesc_arm_with_iwmmxt (void)
   tdesc_create_vector (feature, "iwmmxt_v2u32", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "iwmmxt_vec64i");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "iwmmxt_v8u8");
   tdesc_add_field (type_with_fields, "u8", field_type);
   field_type = tdesc_named_type (feature, "iwmmxt_v4u16");
diff --git a/gdb/features/i386/32bit-core.c b/gdb/features/i386/32bit-core.c
index de2ce47..294e86d 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/32bit-mpx.c b/gdb/features/i386/32bit-mpx.c
index 38910d3..8f1be3a 100644
--- a/gdb/features/i386/32bit-mpx.c
+++ b/gdb/features/i386/32bit-mpx.c
@@ -10,8 +10,8 @@ create_feature_i386_32bit_mpx (struct target_desc *result, long regnum)

   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx", "32bit-mpx.xml");
   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_struct (feature, "br128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint64");
   tdesc_add_field (type_with_fields, "lbound", field_type);
   field_type = tdesc_named_type (feature, "uint64");
diff --git a/gdb/features/i386/32bit-sse.c b/gdb/features/i386/32bit-sse.c
index 1c8a7e8..cf48960 100644
--- a/gdb/features/i386/32bit-sse.c
+++ b/gdb/features/i386/32bit-sse.c
@@ -29,8 +29,8 @@ create_feature_i386_32bit_sse (struct target_desc *result, long regnum)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/i386/64bit-avx512.c b/gdb/features/i386/64bit-avx512.c
index a565f42..e103e43 100644
--- a/gdb/features/i386/64bit-avx512.c
+++ b/gdb/features/i386/64bit-avx512.c
@@ -29,8 +29,8 @@ create_feature_i386_64bit_avx512 (struct target_desc *result, long regnum)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/i386/64bit-core.c b/gdb/features/i386/64bit-core.c
index f4cad06..9e39ee4 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/64bit-mpx.c b/gdb/features/i386/64bit-mpx.c
index f8730b4..725e76a 100644
--- a/gdb/features/i386/64bit-mpx.c
+++ b/gdb/features/i386/64bit-mpx.c
@@ -10,8 +10,8 @@ create_feature_i386_64bit_mpx (struct target_desc *result, long regnum)

   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx", "64bit-mpx.xml");
   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_struct (feature, "br128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint64");
   tdesc_add_field (type_with_fields, "lbound", field_type);
   field_type = tdesc_named_type (feature, "uint64");
diff --git a/gdb/features/i386/64bit-sse.c b/gdb/features/i386/64bit-sse.c
index e4f99c2..2859217 100644
--- a/gdb/features/i386/64bit-sse.c
+++ b/gdb/features/i386/64bit-sse.c
@@ -29,8 +29,8 @@ create_feature_i386_64bit_sse (struct target_desc *result, long regnum)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/i386/x32-core.c b/gdb/features/i386/x32-core.c
index acafc7d..c268e11 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 929a5f9..9169cae 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/features/rs6000/powerpc-7400.c b/gdb/features/rs6000/powerpc-7400.c
index ba9f12c..58f8a69 100644
--- a/gdb/features/rs6000/powerpc-7400.c
+++ b/gdb/features/rs6000/powerpc-7400.c
@@ -152,8 +152,8 @@ initialize_tdesc_powerpc_7400 (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-altivec32.c b/gdb/features/rs6000/powerpc-altivec32.c
index 9cb83ca..bbb36c8 100644
--- a/gdb/features/rs6000/powerpc-altivec32.c
+++ b/gdb/features/rs6000/powerpc-altivec32.c
@@ -104,8 +104,8 @@ initialize_tdesc_powerpc_altivec32 (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-altivec32l.c b/gdb/features/rs6000/powerpc-altivec32l.c
index afaf8ed..81862cb 100644
--- a/gdb/features/rs6000/powerpc-altivec32l.c
+++ b/gdb/features/rs6000/powerpc-altivec32l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_altivec32l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-altivec64.c b/gdb/features/rs6000/powerpc-altivec64.c
index 94041e1..f7a7c72 100644
--- a/gdb/features/rs6000/powerpc-altivec64.c
+++ b/gdb/features/rs6000/powerpc-altivec64.c
@@ -104,8 +104,8 @@ initialize_tdesc_powerpc_altivec64 (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-altivec64l.c b/gdb/features/rs6000/powerpc-altivec64l.c
index c7ed171..ce0bc86 100644
--- a/gdb/features/rs6000/powerpc-altivec64l.c
+++ b/gdb/features/rs6000/powerpc-altivec64l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_altivec64l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-cell32l.c b/gdb/features/rs6000/powerpc-cell32l.c
index 390d7b2..74c42f9 100644
--- a/gdb/features/rs6000/powerpc-cell32l.c
+++ b/gdb/features/rs6000/powerpc-cell32l.c
@@ -110,8 +110,8 @@ initialize_tdesc_powerpc_cell32l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-cell64l.c b/gdb/features/rs6000/powerpc-cell64l.c
index 39890ba..cbfda4c 100644
--- a/gdb/features/rs6000/powerpc-cell64l.c
+++ b/gdb/features/rs6000/powerpc-cell64l.c
@@ -110,8 +110,8 @@ initialize_tdesc_powerpc_cell64l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-isa205-altivec32l.c b/gdb/features/rs6000/powerpc-isa205-altivec32l.c
index 203bb4a..09f5c07 100644
--- a/gdb/features/rs6000/powerpc-isa205-altivec32l.c
+++ b/gdb/features/rs6000/powerpc-isa205-altivec32l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_isa205_altivec32l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-isa205-altivec64l.c b/gdb/features/rs6000/powerpc-isa205-altivec64l.c
index 8f66a16..246fcef 100644
--- a/gdb/features/rs6000/powerpc-isa205-altivec64l.c
+++ b/gdb/features/rs6000/powerpc-isa205-altivec64l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_isa205_altivec64l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-isa205-vsx32l.c b/gdb/features/rs6000/powerpc-isa205-vsx32l.c
index fc0f615..2a6e232 100644
--- a/gdb/features/rs6000/powerpc-isa205-vsx32l.c
+++ b/gdb/features/rs6000/powerpc-isa205-vsx32l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_isa205_vsx32l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-isa205-vsx64l.c b/gdb/features/rs6000/powerpc-isa205-vsx64l.c
index 3313d04..d0e32f2 100644
--- a/gdb/features/rs6000/powerpc-isa205-vsx64l.c
+++ b/gdb/features/rs6000/powerpc-isa205-vsx64l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_isa205_vsx64l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-vsx32.c b/gdb/features/rs6000/powerpc-vsx32.c
index 1a824a8..9eafb1c 100644
--- a/gdb/features/rs6000/powerpc-vsx32.c
+++ b/gdb/features/rs6000/powerpc-vsx32.c
@@ -104,8 +104,8 @@ initialize_tdesc_powerpc_vsx32 (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-vsx32l.c b/gdb/features/rs6000/powerpc-vsx32l.c
index f5bf11e..f08df14 100644
--- a/gdb/features/rs6000/powerpc-vsx32l.c
+++ b/gdb/features/rs6000/powerpc-vsx32l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_vsx32l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-vsx64.c b/gdb/features/rs6000/powerpc-vsx64.c
index 601df39..7991115 100644
--- a/gdb/features/rs6000/powerpc-vsx64.c
+++ b/gdb/features/rs6000/powerpc-vsx64.c
@@ -104,8 +104,8 @@ initialize_tdesc_powerpc_vsx64 (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/rs6000/powerpc-vsx64l.c b/gdb/features/rs6000/powerpc-vsx64l.c
index d34bd81..1726e67 100644
--- a/gdb/features/rs6000/powerpc-vsx64l.c
+++ b/gdb/features/rs6000/powerpc-vsx64l.c
@@ -108,8 +108,8 @@ initialize_tdesc_powerpc_vsx64l (void)
   tdesc_create_vector (feature, "v16i8", element_type, 16);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_add_field (type_with_fields, "uint128", field_type);
   field_type = tdesc_named_type (feature, "v4f");
diff --git a/gdb/features/s390-gs-linux64.c b/gdb/features/s390-gs-linux64.c
index 126835b..1416183 100644
--- a/gdb/features/s390-gs-linux64.c
+++ b/gdb/features/s390-gs-linux64.c
@@ -135,8 +135,8 @@ initialize_tdesc_s390_gs_linux64 (void)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/s390-tevx-linux64.c b/gdb/features/s390-tevx-linux64.c
index a9ee9e1..ae62e8d 100644
--- a/gdb/features/s390-tevx-linux64.c
+++ b/gdb/features/s390-tevx-linux64.c
@@ -135,8 +135,8 @@ initialize_tdesc_s390_tevx_linux64 (void)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/s390-vx-linux64.c b/gdb/features/s390-vx-linux64.c
index b6c5dda..d3ec081 100644
--- a/gdb/features/s390-vx-linux64.c
+++ b/gdb/features/s390-vx-linux64.c
@@ -113,8 +113,8 @@ initialize_tdesc_s390_vx_linux64 (void)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/s390x-gs-linux64.c b/gdb/features/s390x-gs-linux64.c
index 5ab3e3d..d253a09 100644
--- a/gdb/features/s390x-gs-linux64.c
+++ b/gdb/features/s390x-gs-linux64.c
@@ -119,8 +119,8 @@ initialize_tdesc_s390x_gs_linux64 (void)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/s390x-tevx-linux64.c b/gdb/features/s390x-tevx-linux64.c
index e5ecedf..1ac3249 100644
--- a/gdb/features/s390x-tevx-linux64.c
+++ b/gdb/features/s390x-tevx-linux64.c
@@ -119,8 +119,8 @@ initialize_tdesc_s390x_tevx_linux64 (void)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/features/s390x-vx-linux64.c b/gdb/features/s390x-vx-linux64.c
index 1f24349..2e3d382 100644
--- a/gdb/features/s390x-vx-linux64.c
+++ b/gdb/features/s390x-vx-linux64.c
@@ -97,8 +97,8 @@ initialize_tdesc_s390x_vx_linux64 (void)
   tdesc_create_vector (feature, "v2i64", element_type, 2);

   tdesc_type_with_fields *type_with_fields;
-  tdesc_type *field_type;
   type_with_fields = tdesc_create_union (feature, "vec128");
+  tdesc_type *field_type;
   field_type = tdesc_named_type (feature, "v4f");
   tdesc_add_field (type_with_fields, "v4_float", field_type);
   field_type = tdesc_named_type (feature, "v2d");
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 88ac55f..5dcc4c4 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -1894,13 +1894,6 @@ public:
 	m_printed_type_with_fields = true;
       }

-    if (!type->fields.empty ()
-	&& !m_printed_field_type)
-      {
-	printf_unfiltered ("  tdesc_type *field_type;\n");
-	m_printed_field_type = true;
-      }
-
     switch (type->kind)
       {
       case TDESC_TYPE_STRUCT:
@@ -1949,8 +1942,8 @@ public:
 		  }
 		else
 		  {
-		    printf_unfiltered
-		      ("  field_type = tdesc_named_type (feature, \"%s\");\n",
+		    printf_field_type_assignment
+		      ("tdesc_named_type (feature, \"%s\");\n",
 		       type_name);
 		    printf_unfiltered
 		      ("  tdesc_add_typed_bitfield (type_with_fields, \"%s\","
@@ -1962,10 +1955,8 @@ public:
 	      {
 		gdb_assert (f.end == -1);
 		gdb_assert (type->kind == TDESC_TYPE_STRUCT);
-		printf_unfiltered
-		  ("  field_type = tdesc_named_type (feature,"
-		   " \"%s\");\n",
-		   type_name);
+		printf_field_type_assignment
+		  ("tdesc_named_type (feature, \"%s\");\n", type_name);
 		printf_unfiltered
 		  ("  tdesc_add_field (type_with_fields, \"%s\", field_type);\n",
 		   f.name.c_str ());
@@ -1978,9 +1969,8 @@ public:
 	   type->name.c_str ());
 	for (const tdesc_type_field &f : type->fields)
 	  {
-	    printf_unfiltered
-	      ("  field_type = tdesc_named_type (feature, \"%s\");\n",
-	       f.type->name.c_str ());
+	    printf_field_type_assignment
+	      ("tdesc_named_type (feature, \"%s\");\n", f.type->name.c_str ());
 	    printf_unfiltered
 	      ("  tdesc_add_field (type_with_fields, \"%s\", field_type);\n",
 	       f.name.c_str ());
@@ -2018,6 +2008,25 @@ protected:
   std::string m_filename_after_features;

 private:
+
+  /* Print an assignment to the field_type variable.  Print the declaration
+     of field_type if that has not been done yet.  */
+  void printf_field_type_assignment (const char *fmt, ...)
+  {
+    if (!m_printed_field_type)
+      {
+	printf_unfiltered ("  tdesc_type *field_type;\n");
+	m_printed_field_type = true;
+      }
+
+    printf_unfiltered ("  field_type = ");
+
+    va_list args;
+    va_start (args, fmt);
+    vprintf_unfiltered (fmt, args);
+    va_end (args);
+  }
+
   char *m_function;

   /* Did we print "struct tdesc_type *element_type;" yet?  */
-- 
2.7.4



More information about the Gdb-patches mailing list