Add scalar_storage_order support for floating point
authorTom Tromey <tromey@adacore.com>
Mon, 25 Nov 2019 18:13:52 +0000 (11:13 -0700)
committerTom Tromey <tromey@adacore.com>
Wed, 4 Dec 2019 16:31:18 +0000 (09:31 -0700)
Testing the scalar_storage_order patch pointed out that it does not
handle floating point properly.  This patch fixes this problem.

gdb/ChangeLog
2019-12-04  Tom Tromey  <tromey@adacore.com>

* dwarf2read.c (dwarf2_init_float_type)
(dwarf2_init_complex_target_type): Add byte_order parameter.
(read_base_type): Compute byte order earlier.
* gdbtypes.c (init_float_type): Add byte_order parameter.
* gdbtypes.h (init_float_type): Add byte_order parameter.

gdb/testsuite/ChangeLog
2019-12-04  Tom Tromey  <tromey@adacore.com>

* gdb.base/endianity.c (struct otherendian) <f>: New field.
(main): Initialize it.
* gdb.base/endianity.exp: Update.

Change-Id: Ic02eb711d80ce678ef0ecf8c506a626e441b8440

gdb/ChangeLog
gdb/dwarf2read.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/endianity.c
gdb/testsuite/gdb.base/endianity.exp

index 8837a23888142ed3e5e6f60efebd45b7b58f38cf..ffae6086301e8ddbed07d37556a508a70ea52a90 100644 (file)
@@ -1,3 +1,11 @@
+2019-12-04  Tom Tromey  <tromey@adacore.com>
+
+       * dwarf2read.c (dwarf2_init_float_type)
+       (dwarf2_init_complex_target_type): Add byte_order parameter.
+       (read_base_type): Compute byte order earlier.
+       * gdbtypes.c (init_float_type): Add byte_order parameter.
+       * gdbtypes.h (init_float_type): Add byte_order parameter.
+
 2019-12-04  Tom Tromey  <tromey@adacore.com>
 
        * unittests/tui-selftests.c: Conditionally include tui-winsource.h.
index f99061d40db0246bff701467b3ddd19beca431d1..40d93c9b0e482aa32bface30a75515bab6b9541a 100644 (file)
@@ -17624,7 +17624,7 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
 
 static struct type *
 dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
-                       const char *name_hint)
+                       const char *name_hint, enum bfd_endian byte_order)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const struct floatformat **format;
@@ -17632,7 +17632,7 @@ dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
 
   format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
   if (format)
-    type = init_float_type (objfile, bits, name, format);
+    type = init_float_type (objfile, bits, name, format, byte_order);
   else
     type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
 
@@ -17671,7 +17671,8 @@ dwarf2_init_integer_type (struct dwarf2_cu *cu, struct objfile *objfile,
 static struct type *
 dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
                                 struct objfile *objfile,
-                                int bits, const char *name_hint)
+                                int bits, const char *name_hint,
+                                enum bfd_endian byte_order)
 {
   gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *tt = nullptr;
@@ -17720,7 +17721,7 @@ dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
     tt = nullptr;
 
   const char *name = (tt == nullptr) ? nullptr : TYPE_NAME (tt);
-  return dwarf2_init_float_type (objfile, bits, name, name_hint);
+  return dwarf2_init_float_type (objfile, bits, name, name_hint, byte_order);
 }
 
 /* Find a representation of a given base type and install
@@ -17733,7 +17734,6 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   struct type *type;
   struct attribute *attr;
   int encoding = 0, bits = 0;
-  int endianity = 0;
   const char *name;
   gdbarch *arch;
 
@@ -17746,11 +17746,29 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   name = dwarf2_name (die, cu);
   if (!name)
     complaint (_("DW_AT_name missing from DW_TAG_base_type"));
+
+  arch = get_objfile_arch (objfile);
+  enum bfd_endian byte_order = gdbarch_byte_order (arch);
+
   attr = dwarf2_attr (die, DW_AT_endianity, cu);
   if (attr)
-    endianity = DW_UNSND (attr);
+    {
+      int endianity = DW_UNSND (attr);
+
+      switch (endianity)
+       {
+       case DW_END_big:
+         byte_order = BFD_ENDIAN_BIG;
+         break;
+       case DW_END_little:
+         byte_order = BFD_ENDIAN_LITTLE;
+         break;
+       default:
+         complaint (_("DW_AT_endianity has unrecognized value %d"), endianity);
+         break;
+       }
+    }
 
-  arch = get_objfile_arch (objfile);
   switch (encoding)
     {
       case DW_ATE_address:
@@ -17762,14 +17780,15 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
        type = init_boolean_type (objfile, bits, 1, name);
        break;
       case DW_ATE_complex_float:
-       type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name);
+       type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
+                                               byte_order);
        type = init_complex_type (objfile, name, type);
        break;
       case DW_ATE_decimal_float:
        type = init_decfloat_type (objfile, bits, name);
        break;
       case DW_ATE_float:
-       type = dwarf2_init_float_type (objfile, bits, name, name);
+       type = dwarf2_init_float_type (objfile, bits, name, name, byte_order);
        break;
       case DW_ATE_signed:
        type = dwarf2_init_integer_type (cu, objfile, bits, 0, name);
@@ -17827,17 +17846,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
 
   maybe_set_alignment (cu, die, type);
 
-  switch (endianity)
-    {
-      case DW_END_big:
-        if (gdbarch_byte_order (arch) == BFD_ENDIAN_LITTLE)
-          TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
-        break;
-      case DW_END_little:
-        if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
-          TYPE_ENDIANITY_NOT_DEFAULT (type) = 1;
-        break;
-    }
+  TYPE_ENDIANITY_NOT_DEFAULT (type) = gdbarch_byte_order (arch) != byte_order;
 
   return set_die_type (die, type, cu);
 }
index f10f65d0dab5897d53d27ea9d6008045119c9c28..06096344b4afc3a6e94c17594e13c3b663e9d013 100644 (file)
@@ -2976,15 +2976,22 @@ init_boolean_type (struct objfile *objfile,
 /* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
    BIT is the type size in bits; if BIT equals -1, the size is
    determined by the floatformat.  NAME is the type name.  Set the
-   TYPE_FLOATFORMAT from FLOATFORMATS.  */
+   TYPE_FLOATFORMAT from FLOATFORMATS.  BYTE_ORDER is the byte order
+   to use.  If it is BFD_ENDIAN_UNKNOWN (the default), then the byte
+   order of the objfile's architecture is used.  */
 
 struct type *
 init_float_type (struct objfile *objfile,
                 int bit, const char *name,
-                const struct floatformat **floatformats)
+                const struct floatformat **floatformats,
+                enum bfd_endian byte_order)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
+  if (byte_order == BFD_ENDIAN_UNKNOWN)
+    {
+      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      byte_order = gdbarch_byte_order (gdbarch);
+    }
+  const struct floatformat *fmt = floatformats[byte_order];
   struct type *t;
 
   bit = verify_floatformat (bit, fmt);
index 963314dcc81932b674b7aa4c7ef877b14c5566e3..f6879e85a9bb09d763d518a03b7f1bd005136422 100644 (file)
@@ -1821,7 +1821,8 @@ extern struct type *init_character_type (struct objfile *, int, int,
 extern struct type *init_boolean_type (struct objfile *, int, int,
                                       const char *);
 extern struct type *init_float_type (struct objfile *, int, const char *,
-                                    const struct floatformat **);
+                                    const struct floatformat **,
+                                    enum bfd_endian = BFD_ENDIAN_UNKNOWN);
 extern struct type *init_decfloat_type (struct objfile *, int, const char *);
 extern struct type *init_complex_type (struct objfile *, const char *,
                                       struct type *);
index 112049f2ed208eabb42fc1856fe15db05e899015..1c8aa8633e47f2895d59ef9fd0e50df70d0edfcc 100644 (file)
@@ -1,3 +1,9 @@
+2019-12-04  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.base/endianity.c (struct otherendian) <f>: New field.
+       (main): Initialize it.
+       * gdb.base/endianity.exp: Update.
+
 2019-12-04  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.mi/mi-sym-info.exp: Add tests for -max-results parameter.
index 5ab090dd3d25e1dae427b38f132dbef3efb366a3..42ee9ae13af0e2b8bc72fd040812c230f2cd3b96 100644 (file)
@@ -21,6 +21,9 @@ struct otherendian
 {
   int v;
   short w;
+  float f;
+  __complex__ float cplx;
+  double d;
 }
 #if defined __GNUC__ && (__GNUC__ >= 6)
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -39,7 +42,7 @@ do_nothing (struct otherendian *c)
 int
 main (void)
 {
-  struct otherendian o = {3,2};
+  struct otherendian o = {3, 2, 23.5, 1.25 + 7.25i, 75};
 
   do_nothing (&o); /* START */
 }
index 80df01213e485f53b3fa424b38788625fbd4bf48..4277c1f9e7d757d3d4938d07bf82f641e7b02aee 100644 (file)
@@ -25,10 +25,13 @@ if ![runto "endianity.c:$bp_location" ] then {
   return -1
 }
 
-gdb_test "print o" "= {v = 3, w = 2}" "print o before assignment"
+gdb_test "print o" "= {v = 3, w = 2, f = 23.5, cplx = 1.25 \\+ 7.25 \\* I, d = 75}" \
+    "print o before assignment"
 
 gdb_test "print o.v = 4" "= 4"
 gdb_test "print o.w = 3" "= 3"
+gdb_test "print o.f = 1.5" "= 1.5"
+gdb_test "print o.d = -23.125" "= -23.125"
 
 # scalar_storage_order requires gcc >= 6
 if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
@@ -37,4 +40,5 @@ if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } {
 gdb_test "x/x &o.v" "0x04000000"
 gdb_test "x/xh &o.w" "0x0300"
 
-gdb_test "print o" "= {v = 4, w = 3}" "print o after assignment"
+gdb_test "print o" "= {v = 4, w = 3, f = 1.5, cplx = 1.25 \\+ 7.25 \\* I, d = -23.125}" \
+    "print o after assignment"
This page took 0.043572 seconds and 4 git commands to generate.