gdb: Restructure type_align and gdbarch_type_align
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 22 Feb 2019 20:49:04 +0000 (20:49 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 27 Feb 2019 08:38:15 +0000 (10:38 +0200)
This commit restructures the relationship between the type_align
function and the gdbarch_type_align method.

The problem being addressed with this commit is this; previously the
type_align function was structured so that for "basic" types (int,
float, etc) the gdbarch_type_align hook was called, which for
"compound" types (arrays, structs, etc) the common type_align code has
a fixed method for how to extract a "basic" type and would then call
itself on that "basic" type.

The problem is that if an architecture wants to modify the alignment
rules for a "compound" type then this is not currently possible.

In the revised structure, all types pass through the
gdbarch_type_align method.  If this method returns 0 then this
indicates that the architecture has no special rules for this type,
and GDB should apply the default rules for alignment.  However, the
architecture is free to provide an alignment for any type, both
"basic" and "compound".

After this commit the default alignment rules now all live in the
type_align function, the default_type_align only ever returns 0,
meaning apply the default rules.

I've updated the 3 targets (arc, i386, and nios2) that already
override the gdbarch_type_align method to fit the new scheme.

Tested on X86-64/GNU Linux with no regressions.

gdb/ChangeLog:

* arc-tdep.c (arc_type_align): Provide alignment for basic types,
return 0 for other types.
* arch-utils.c (default_type_align): Always return 0.
* gdbarch.h: Regenerate.
* gdbarch.sh (type_align): Extend comment.
* gdbtypes.c (type_align): Add additional comments, always call
gdbarch_type_align before applying the default rules.
* i386-tdep.c (i386_type_align): Return 0 as the default rule,
generic code will then apply a suitable default.
* nios2-tdep.c (nios2_type_align): Provide alignment for basic
types, return 0 for other types.

gdb/ChangeLog
gdb/arc-tdep.c
gdb/arch-utils.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/gdbtypes.c
gdb/i386-tdep.c
gdb/nios2-tdep.c

index b0fce99b940fad1700c9d3f59aea3a304109a48d..07f3c478b283ec2778660e7602bfed41b1a52731 100644 (file)
@@ -1,3 +1,17 @@
+2019-02-27  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * arc-tdep.c (arc_type_align): Provide alignment for basic types,
+       return 0 for other types.
+       * arch-utils.c (default_type_align): Always return 0.
+       * gdbarch.h: Regenerate.
+       * gdbarch.sh (type_align): Extend comment.
+       * gdbtypes.c (type_align): Add additional comments, always call
+       gdbarch_type_align before applying the default rules.
+       * i386-tdep.c (i386_type_align): Return 0 as the default rule,
+       generic code will then apply a suitable default.
+       * nios2-tdep.c (nios2_type_align): Provide alignment for basic
+       types, return 0 for other types.
+
 2019-02-27  Joel Brobecker  <brobecker@adacore.com>
 
        * NEWS: Create a new section for the next release branch.
index cd2762cb5cd61b654c4b7a38eaeae87d8638dd8c..235fb276e4796cb27d3b4c659caa5514c9414f53 100644 (file)
@@ -1963,8 +1963,27 @@ arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
 static ULONGEST
 arc_type_align (struct gdbarch *gdbarch, struct type *type)
 {
-  type = check_typedef (type);
-  return std::min<ULONGEST> (4, TYPE_LENGTH (type));
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_PTR:
+    case TYPE_CODE_FUNC:
+    case TYPE_CODE_FLAGS:
+    case TYPE_CODE_INT:
+    case TYPE_CODE_RANGE:
+    case TYPE_CODE_FLT:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
+    case TYPE_CODE_CHAR:
+    case TYPE_CODE_BOOL:
+    case TYPE_CODE_DECFLOAT:
+    case TYPE_CODE_METHODPTR:
+    case TYPE_CODE_MEMBERPTR:
+      type = check_typedef (type);
+      return std::min<ULONGEST> (4, TYPE_LENGTH (type));
+    default:
+      return 0;
+    }
 }
 
 /* Implement the "init" gdbarch method.  */
index d2e27d95558cab7fa0d8c4023deac84334c25cac..52a08daa3b9aa266046d1ae7335c71829664c04d 100644 (file)
@@ -993,7 +993,7 @@ default_in_indirect_branch_thunk (gdbarch *gdbarch, CORE_ADDR pc)
 ULONGEST
 default_type_align (struct gdbarch *gdbarch, struct type *type)
 {
-  return type_length_units (check_typedef (type));
+  return 0;
 }
 
 void
index 5b265a462aa8084974388b74e938776f255c4694..75618376abb192eca11a41d42921c483d3be76a3 100644 (file)
@@ -1589,7 +1589,10 @@ extern void set_gdbarch_disassembler_options (struct gdbarch *gdbarch, char ** d
 extern const disasm_options_and_args_t * gdbarch_valid_disassembler_options (struct gdbarch *gdbarch);
 extern void set_gdbarch_valid_disassembler_options (struct gdbarch *gdbarch, const disasm_options_and_args_t * valid_disassembler_options);
 
-/* Type alignment. */
+/* Type alignment override method.  Return the architecture specific
+   alignment required for TYPE.  If there is no special handling
+   required for TYPE then return the value 0, GDB will then apply the
+   default rules as laid out in gdbtypes.c:type_align. */
 
 typedef ULONGEST (gdbarch_type_align_ftype) (struct gdbarch *gdbarch, struct type *type);
 extern ULONGEST gdbarch_type_align (struct gdbarch *gdbarch, struct type *type);
index d53bbcc2ff4889859acd2bad4985e0d92c4dcf21..48fcebd19a08749c826528a6475ef9e960643da0 100755 (executable)
@@ -1171,7 +1171,10 @@ v;const char *;disassembler_options_implicit;;;0;0;;0;pstring (gdbarch->disassem
 v;char **;disassembler_options;;;0;0;;0;pstring_ptr (gdbarch->disassembler_options)
 v;const disasm_options_and_args_t *;valid_disassembler_options;;;0;0;;0;host_address_to_string (gdbarch->valid_disassembler_options)
 
-# Type alignment.
+# Type alignment override method.  Return the architecture specific
+# alignment required for TYPE.  If there is no special handling
+# required for TYPE then return the value 0, GDB will then apply the
+# default rules as laid out in gdbtypes.c:type_align.
 m;ULONGEST;type_align;struct type *type;type;;default_type_align;;0
 
 EOF
index 0d293393daede5825eb9991643c5edcb71b03577..63dec3c8b7dea1473e402dacc204211e0ff0725f 100644 (file)
@@ -2992,11 +2992,17 @@ type_raw_align (struct type *type)
 unsigned
 type_align (struct type *type)
 {
+  /* Check alignment provided in the debug information.  */
   unsigned raw_align = type_raw_align (type);
   if (raw_align != 0)
     return raw_align;
 
-  ULONGEST align = 0;
+  /* Allow the architecture to provide an alignment.  */
+  struct gdbarch *arch = get_type_arch (type);
+  ULONGEST align = gdbarch_type_align (arch, type);
+  if (align != 0)
+    return align;
+
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_PTR:
@@ -3013,10 +3019,7 @@ type_align (struct type *type)
     case TYPE_CODE_DECFLOAT:
     case TYPE_CODE_METHODPTR:
     case TYPE_CODE_MEMBERPTR:
-      {
-       struct gdbarch *arch = get_type_arch (type);
-       align = gdbarch_type_align (arch, type);
-      }
+      align = type_length_units (check_typedef (type));
       break;
 
     case TYPE_CODE_ARRAY:
index 663d510a915807ffbdb609d12f879b3e5d366526..bc9ba752edf1f40848449ecf9416f9b6a2b0d72d 100644 (file)
@@ -8348,7 +8348,7 @@ i386_type_align (struct gdbarch *gdbarch, struct type *type)
        return 4;
     }
 
-  return TYPE_LENGTH (type);
+  return 0;
 }
 
 \f
index aa49a577ddad204258b317529023bb1a7f5099ff..ee45db98af634a9d705947c2545cbed428adb7df 100644 (file)
@@ -2233,8 +2233,27 @@ nios2_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
 static ULONGEST
 nios2_type_align (struct gdbarch *gdbarch, struct type *type)
 {
-  type = check_typedef (type);
-  return std::min<ULONGEST> (4, TYPE_LENGTH (type));
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_PTR:
+    case TYPE_CODE_FUNC:
+    case TYPE_CODE_FLAGS:
+    case TYPE_CODE_INT:
+    case TYPE_CODE_RANGE:
+    case TYPE_CODE_FLT:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
+    case TYPE_CODE_CHAR:
+    case TYPE_CODE_BOOL:
+    case TYPE_CODE_DECFLOAT:
+    case TYPE_CODE_METHODPTR:
+    case TYPE_CODE_MEMBERPTR:
+      type = check_typedef (type);
+      return std::min<ULONGEST> (4, TYPE_LENGTH (type));
+    default:
+      return 0;
+    }
 }
 
 /* Implement the gcc_target_options gdbarch method.  */
This page took 0.030575 seconds and 4 git commands to generate.