Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] More type_align fixes
@ 2019-04-07 21:38 Andrew Burgess
  2019-04-07 21:38 ` [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields Andrew Burgess
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andrew Burgess @ 2019-04-07 21:38 UTC (permalink / raw)
  To: gdb-patches
  Cc: Jim Wilson, John Baldwin, Palmer Dabbelt, Tom Tromey, Andrew Burgess

This short series finally removes the riscv_type_alignment function
and replaces it with use of the common type_align function.

I found one more fix that was needed in order to allow this change
(patch #1), then the switch over is simple (patch #2).

--

Andrew Burgess (2):
  gdb: Fix alignment computation for structs with only static fields
  gdb/riscv: Remove riscv_type_alignment function

 gdb/ChangeLog                    | 12 ++++++++
 gdb/gdbtypes.c                   | 12 ++++----
 gdb/riscv-tdep.c                 | 60 ++++++++--------------------------------
 gdb/testsuite/ChangeLog          |  5 ++++
 gdb/testsuite/gdb.base/align.exp | 24 ++++++++++++----
 5 files changed, 53 insertions(+), 60 deletions(-)

-- 
2.14.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] gdb/riscv: Remove riscv_type_alignment function
  2019-04-07 21:38 [PATCH 0/2] More type_align fixes Andrew Burgess
  2019-04-07 21:38 ` [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields Andrew Burgess
@ 2019-04-07 21:38 ` Andrew Burgess
  2019-04-11 22:42 ` [PATCH 0/2] More type_align fixes Andrew Burgess
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2019-04-07 21:38 UTC (permalink / raw)
  To: gdb-patches
  Cc: Jim Wilson, John Baldwin, Palmer Dabbelt, Tom Tromey, Andrew Burgess

Make use of the type_align function and remove riscv_type_alignment as
it is no longer needed.  I tested this against a number of RV32 and
RV64 targets, and I also ran the tests with an assertion in place
checking that the old riscv_type_alignment function gives the same
answer as the common type_align function - it does, and all the tests
still pass.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_type_align): New function.
	(riscv_type_alignment): Delete.
	(riscv_arg_location): Use 'type_align'.
	(riscv_gdbarch_init): Register riscv_type_align gdbarch function.
---
 gdb/ChangeLog    |  7 +++++++
 gdb/riscv-tdep.c | 60 ++++++++++++--------------------------------------------
 2 files changed, 19 insertions(+), 48 deletions(-)

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index ff5f36e7621..ed75dc59951 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1620,55 +1620,18 @@ riscv_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
   return sp;
 }
 
-/* Compute the alignment of the type T.  Used while setting up the
-   arguments for a dummy call.  */
+/* Implement the gdbarch type alignment method, overrides the generic
+   alignment algorithm for anything that is RISC-V specific.  */
 
-static int
-riscv_type_alignment (struct type *t)
+static ULONGEST
+riscv_type_align (gdbarch *gdbarch, type *type)
 {
-  t = check_typedef (t);
-  switch (TYPE_CODE (t))
-    {
-    default:
-      error (_("Could not compute alignment of type"));
-
-    case TYPE_CODE_RANGE:
-    case TYPE_CODE_RVALUE_REF:
-    case TYPE_CODE_PTR:
-    case TYPE_CODE_ENUM:
-    case TYPE_CODE_INT:
-    case TYPE_CODE_FLT:
-    case TYPE_CODE_REF:
-    case TYPE_CODE_CHAR:
-    case TYPE_CODE_BOOL:
-      return TYPE_LENGTH (t);
+  type = check_typedef (type);
+  if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
+    return std::min (TYPE_LENGTH (type), (ULONGEST) BIGGEST_ALIGNMENT);
 
-    case TYPE_CODE_ARRAY:
-      if (TYPE_VECTOR (t))
-	return std::min (TYPE_LENGTH (t), (ULONGEST) BIGGEST_ALIGNMENT);
-      /* FALLTHROUGH */
-
-    case TYPE_CODE_COMPLEX:
-      return riscv_type_alignment (TYPE_TARGET_TYPE (t));
-
-    case TYPE_CODE_STRUCT:
-    case TYPE_CODE_UNION:
-      {
-	int i;
-	int align = 1;
-
-	for (i = 0; i < TYPE_NFIELDS (t); ++i)
-	  {
-	    if (TYPE_FIELD_LOC_KIND (t, i) == FIELD_LOC_KIND_BITPOS)
-	      {
-		int a = riscv_type_alignment (TYPE_FIELD_TYPE (t, i));
-		if (a > align)
-		  align = a;
-	      }
-	  }
-	return align;
-      }
-    }
+  /* Anything else will be aligned by the generic code.  */
+  return 0;
 }
 
 /* Holds information about a single argument either being passed to an
@@ -2231,7 +2194,7 @@ riscv_arg_location (struct gdbarch *gdbarch,
 {
   ainfo->type = type;
   ainfo->length = TYPE_LENGTH (ainfo->type);
-  ainfo->align = riscv_type_alignment (ainfo->type);
+  ainfo->align = type_align (ainfo->type);
   ainfo->is_unnamed = is_unnamed;
   ainfo->contents = nullptr;
 
@@ -2255,7 +2218,7 @@ riscv_arg_location (struct gdbarch *gdbarch,
 	}
 
       /* Recalculate the alignment requirement.  */
-      ainfo->align = riscv_type_alignment (ainfo->type);
+      ainfo->align = type_align (ainfo->type);
       riscv_call_arg_scalar_int (ainfo, cinfo);
       break;
 
@@ -3156,6 +3119,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
   set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
   set_gdbarch_ptr_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8);
   set_gdbarch_char_signed (gdbarch, 0);
+  set_gdbarch_type_align (gdbarch, riscv_type_align);
 
   /* Information about the target architecture.  */
   set_gdbarch_return_value (gdbarch, riscv_return_value);
-- 
2.14.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields
  2019-04-07 21:38 [PATCH 0/2] More type_align fixes Andrew Burgess
@ 2019-04-07 21:38 ` Andrew Burgess
  2019-04-07 22:36   ` Tom Tromey
  2019-04-07 21:38 ` [PATCH 2/2] gdb/riscv: Remove riscv_type_alignment function Andrew Burgess
  2019-04-11 22:42 ` [PATCH 0/2] More type_align fixes Andrew Burgess
  2 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2019-04-07 21:38 UTC (permalink / raw)
  To: gdb-patches
  Cc: Jim Wilson, John Baldwin, Palmer Dabbelt, Tom Tromey, Andrew Burgess

The current code in gdbtypes.c:type_align incorrectly returns 0 as the
alignment for a structure containing only static fields.  After this
patch the correct value of 1 is returned.  The gdb.base/align.exp test
is extended to cover this case.

gdb/ChangeLog:

	* gdbtypes.c (type_align): A struct with no non-static fields also
	has alignment of 1.

gdb/testsuite/ChangeLog:

	* gdb.base/align.exp: Extend test to cover structures containing
	only static fields.
---
 gdb/ChangeLog                    |  5 +++++
 gdb/gdbtypes.c                   | 12 ++++++------
 gdb/testsuite/ChangeLog          |  5 +++++
 gdb/testsuite/gdb.base/align.exp | 24 ++++++++++++++++++------
 4 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b1a51374d96..1d7ff145b98 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3015,16 +3015,12 @@ type_align (struct type *type)
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
       {
-	if (TYPE_NFIELDS (type) == 0)
-	  {
-	    /* An empty struct has alignment 1.  */
-	    align = 1;
-	    break;
-	  }
+	int number_of_non_static_fields = 0;
 	for (unsigned i = 0; i < TYPE_NFIELDS (type); ++i)
 	  {
 	    if (!field_is_static (&TYPE_FIELD (type, i)))
 	      {
+		number_of_non_static_fields++;
 		ULONGEST f_align = type_align (TYPE_FIELD_TYPE (type, i));
 		if (f_align == 0)
 		  {
@@ -3036,6 +3032,10 @@ type_align (struct type *type)
 		  align = f_align;
 	      }
 	  }
+	/* A struct with no fields, or with only static fields has an
+	   alignment of 1.  */
+	if (number_of_non_static_fields == 0)
+	  align = 1;
       }
       break;
 
diff --git a/gdb/testsuite/gdb.base/align.exp b/gdb/testsuite/gdb.base/align.exp
index 558625d1b3e..e3ca0470e94 100644
--- a/gdb/testsuite/gdb.base/align.exp
+++ b/gdb/testsuite/gdb.base/align.exp
@@ -67,8 +67,10 @@ proc prepare_test_source_file { lang } {
     puts -nonewline $outfile "#define DEF(T,U) struct align_pair_ ## T ## _x_ ## U "
     puts $outfile "{ T one; U two; }"
     if { $lang == "c++" } {
-	puts -nonewline $outfile "#define DEF_WITH_STATIC(T,U) struct align_pair_static_ ## T ## _x_ ## U "
+	puts -nonewline $outfile "#define DEF_WITH_1_STATIC(T,U) struct align_pair_static_ ## T ## _x_ ## U "
 	puts $outfile "{ static T one; U two; }"
+	puts -nonewline $outfile "#define DEF_WITH_2_STATIC(T,U) struct align_pair_static_ ## T ## _x_static_ ## U "
+	puts $outfile "{ static T one; static U two; }"
     }
     if { $lang == "c" } {
 	puts $outfile "unsigned a_void = ${align_func} (void);"
@@ -99,11 +101,17 @@ proc prepare_test_source_file { lang } {
 	    puts $outfile "  = ${align_func} (struct align_pair_${joined});"
 
 	    if { $lang == "c++" } {
-		puts $outfile "DEF_WITH_STATIC ($utype, $uinner);"
-		set joined "${utype}_x_${uinner}"
-		puts $outfile "struct align_pair_static_$joined item_static_${joined};"
-		puts $outfile "unsigned a_static_${joined}"
-		puts $outfile "  = ${align_func} (struct align_pair_static_${joined});"
+		puts $outfile "DEF_WITH_1_STATIC ($utype, $uinner);"
+		set joined "static_${utype}_x_${uinner}"
+		puts $outfile "struct align_pair_$joined item_${joined};"
+		puts $outfile "unsigned a_${joined}"
+		puts $outfile "  = ${align_func} (struct align_pair_${joined});"
+
+		puts $outfile "DEF_WITH_2_STATIC ($utype, $uinner);"
+		set joined "static_${utype}_x_static_${uinner}"
+		puts $outfile "struct align_pair_$joined item_${joined};"
+		puts $outfile "unsigned a_${joined}"
+		puts $outfile "  = ${align_func} (struct align_pair_${joined});"
 	    }
 	}
     }
@@ -160,6 +168,10 @@ proc run_alignment_test { lang } {
 		set expected [get_integer_valueof a_static_${utype}_x_${uinner} 0]
 		gdb_test "print ${align_func}(struct align_pair_static_${utype}_x_${uinner})" \
 		    " = $expected"
+
+		set expected [get_integer_valueof a_static_${utype}_x_static_${uinner} 0]
+		gdb_test "print ${align_func}(struct align_pair_static_${utype}_x_static_${uinner})" \
+		    " = $expected"
 	    }
 	}
     }
-- 
2.14.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields
  2019-04-07 21:38 ` [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields Andrew Burgess
@ 2019-04-07 22:36   ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2019-04-07 22:36 UTC (permalink / raw)
  To: Andrew Burgess
  Cc: gdb-patches, Jim Wilson, John Baldwin, Palmer Dabbelt, Tom Tromey

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:

Andrew> 	* gdbtypes.c (type_align): A struct with no non-static fields also
Andrew> 	has alignment of 1.

Andrew> gdb/testsuite/ChangeLog:

Andrew> 	* gdb.base/align.exp: Extend test to cover structures containing
Andrew> 	only static fields.

Thanks for doing this.
It looks good to me.

Tom


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] More type_align fixes
  2019-04-07 21:38 [PATCH 0/2] More type_align fixes Andrew Burgess
  2019-04-07 21:38 ` [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields Andrew Burgess
  2019-04-07 21:38 ` [PATCH 2/2] gdb/riscv: Remove riscv_type_alignment function Andrew Burgess
@ 2019-04-11 22:42 ` Andrew Burgess
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2019-04-11 22:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jim Wilson, John Baldwin, Palmer Dabbelt, Tom Tromey

* Andrew Burgess <andrew.burgess@embecosm.com> [2019-04-07 22:37:53 +0100]:

> This short series finally removes the riscv_type_alignment function
> and replaces it with use of the common type_align function.
> 
> I found one more fix that was needed in order to allow this change
> (patch #1), then the switch over is simple (patch #2).
> 
> --
> 
> Andrew Burgess (2):
>   gdb: Fix alignment computation for structs with only static fields
>   gdb/riscv: Remove riscv_type_alignment function

I've pushed both of these patches now.

Thanks,
Andrew



> 
>  gdb/ChangeLog                    | 12 ++++++++
>  gdb/gdbtypes.c                   | 12 ++++----
>  gdb/riscv-tdep.c                 | 60 ++++++++--------------------------------
>  gdb/testsuite/ChangeLog          |  5 ++++
>  gdb/testsuite/gdb.base/align.exp | 24 ++++++++++++----
>  5 files changed, 53 insertions(+), 60 deletions(-)
> 
> -- 
> 2.14.5
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-11 22:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-07 21:38 [PATCH 0/2] More type_align fixes Andrew Burgess
2019-04-07 21:38 ` [PATCH 1/2] gdb: Fix alignment computation for structs with only static fields Andrew Burgess
2019-04-07 22:36   ` Tom Tromey
2019-04-07 21:38 ` [PATCH 2/2] gdb/riscv: Remove riscv_type_alignment function Andrew Burgess
2019-04-11 22:42 ` [PATCH 0/2] More type_align fixes Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox