Blame SOURCES/gdb-rhbz1320945-float128-8of9.patch

a094f6
commit 9b790ce7227fa346d08a41462119e9a3e93f5e80
a094f6
Author: Ulrich Weigand <ulrich.weigand@de.ibm.com>
a094f6
Date:   Tue Sep 6 17:31:53 2016 +0200
a094f6
a094f6
    Add gdbarch callback to provide formats for debug info float types
a094f6
    
a094f6
    At this point, all TYPE_CODE_FLT types carry their floating-point format,
a094f6
    except for those creating from reading DWARF or stabs debug info.  Those
a094f6
    will be addressed by this commit.
a094f6
    
a094f6
    The main issue here is that we actually have to determine which floating-
a094f6
    point format to use.  Currently, we only have the type length as input
a094f6
    to this decision.  In the future, we may hopefully get --at least in
a094f6
    DWARF-- additional information to help disambiguate multiple different
a094f6
    formats of the same length.  For now, we can still look at the type name
a094f6
    as a hint.
a094f6
    
a094f6
    This decision logic is encapsulated in a gdbarch callback to allow
a094f6
    platform-specific overrides.  The default implementation use the same
a094f6
    logic (compare type length against the various gdbarch_..._bit sizes)
a094f6
    that is currently implemented in floatformat_from_length.
a094f6
    
a094f6
    With this commit, all platforms still use the default logic, so there
a094f6
    should be no actual change in behavior.  A follow-on commit will add
a094f6
    support for __float128 on Intel and Power.
a094f6
    
a094f6
    Once dwarf2read.c and stabsread.c make use of the new callback to
a094f6
    determine floating-point formats, we're now sure every TYPE_CODE_FLT
a094f6
    type will always carry its format.  The commit therefore adds asserts
a094f6
    to verify_floatformat to ensure new code will continue to always
a094f6
    provide formats, and removes the code in floatformat_from_type that
a094f6
    used to handle types with a NULL TYPE_FLOATFORMAT.
a094f6
    
a094f6
    gdb/ChangeLog:
a094f6
    
a094f6
            * gdbarch.sh (floatformat_for_type): New gdbarch callback.
a094f6
            * gdbarch.h, gdbarch.c: Re-generate.
a094f6
            * arch-utils.h (default_floatformat_for_type): New prototype.
a094f6
            * arch-utils.c (default_floatformat_for_type): New function.
a094f6
    
a094f6
            * doublest.c (floatformat_from_length): Remove.
a094f6
            (floatformat_from_type): Assume TYPE_FLOATFORMAT is non-NULL.
a094f6
            * gdbtypes.c (verify_floatformat): Require non-NULL format.
a094f6
    
a094f6
            * dwarf2read.c (dwarf2_init_float_type): New function.
a094f6
            (read_base_type): Use it.
a094f6
            * stabsread.c (dbx_init_float_type): New function.
a094f6
            (read_sun_floating_type): Use it.
a094f6
            (read_range_type): Likewise.
a094f6
    
a094f6
    Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
a094f6
a094f6
### a/gdb/ChangeLog
a094f6
### b/gdb/ChangeLog
a094f6
## -1,5 +1,22 @@
a094f6
 2016-09-05  Ulrich Weigand  <uweigand@de.ibm.com>
a094f6
 
a094f6
+	* gdbarch.sh (floatformat_for_type): New gdbarch callback.
a094f6
+	* gdbarch.h, gdbarch.c: Re-generate.
a094f6
+	* arch-utils.h (default_floatformat_for_type): New prototype.
a094f6
+	* arch-utils.c (default_floatformat_for_type): New function.
a094f6
+
a094f6
+	* doublest.c (floatformat_from_length): Remove.
a094f6
+	(floatformat_from_type): Assume TYPE_FLOATFORMAT is non-NULL.
a094f6
+	* gdbtypes.c (verify_floatformat): Require non-NULL format.
a094f6
+
a094f6
+	* dwarf2read.c (dwarf2_init_float_type): New function.
a094f6
+	(read_base_type): Use it.
a094f6
+	* stabsread.c (dbx_init_float_type): New function.
a094f6
+	(read_sun_floating_type): Use it.
a094f6
+	(read_range_type): Likewise.
a094f6
+
a094f6
+2016-09-05  Ulrich Weigand  <uweigand@de.ibm.com>
a094f6
+
a094f6
 	* ada-lang.c (ada_language_arch_info): Use gdbarch-provided
a094f6
 	platform ABI floating-point formats for built-in types.
a094f6
 	* d-lang.c (build_d_types): Likewise.
a094f6
Index: gdb-7.6.1/gdb/arch-utils.c
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/arch-utils.c	2017-03-11 21:42:26.681253106 +0100
a094f6
+++ gdb-7.6.1/gdb/arch-utils.c	2017-03-11 21:48:54.872873908 +0100
a094f6
@@ -216,6 +216,34 @@
a094f6
   *frame_offset = 0;
a094f6
 }
a094f6
 
a094f6
+/* Return a floating-point format for a floating-point variable of
a094f6
+   length LEN in bits.  If non-NULL, NAME is the name of its type.
a094f6
+   If no suitable type is found, return NULL.  */
a094f6
+
a094f6
+const struct floatformat **
a094f6
+default_floatformat_for_type (struct gdbarch *gdbarch,
a094f6
+			      const char *name, int len)
a094f6
+{
a094f6
+  const struct floatformat **format = NULL;
a094f6
+
a094f6
+  if (len == gdbarch_half_bit (gdbarch))
a094f6
+    format = gdbarch_half_format (gdbarch);
a094f6
+  else if (len == gdbarch_float_bit (gdbarch))
a094f6
+    format = gdbarch_float_format (gdbarch);
a094f6
+  else if (len == gdbarch_double_bit (gdbarch))
a094f6
+    format = gdbarch_double_format (gdbarch);
a094f6
+  else if (len == gdbarch_long_double_bit (gdbarch))
a094f6
+    format = gdbarch_long_double_format (gdbarch);
a094f6
+  /* On i386 the 'long double' type takes 96 bits,
a094f6
+     while the real number of used bits is only 80,
a094f6
+     both in processor and in memory.
a094f6
+     The code below accepts the real bit size.  */
a094f6
+  else if (gdbarch_long_double_format (gdbarch) != NULL
a094f6
+	   && len == gdbarch_long_double_format (gdbarch)[0]->totalsize)
a094f6
+    format = gdbarch_long_double_format (gdbarch);
a094f6
+
a094f6
+  return format;
a094f6
+}
a094f6
 
a094f6
 int
a094f6
 generic_convert_register_p (struct gdbarch *gdbarch, int regnum,
a094f6
Index: gdb-7.6.1/gdb/arch-utils.h
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/arch-utils.h	2017-03-11 21:42:26.681253106 +0100
a094f6
+++ gdb-7.6.1/gdb/arch-utils.h	2017-03-11 21:48:54.872873908 +0100
a094f6
@@ -88,6 +88,11 @@
a094f6
 
a094f6
 extern gdbarch_virtual_frame_pointer_ftype legacy_virtual_frame_pointer;
a094f6
 
a094f6
+/* Default implementation of gdbarch_floatformat_for_type.  */
a094f6
+extern const struct floatformat **
a094f6
+  default_floatformat_for_type (struct gdbarch *gdbarch,
a094f6
+				const char *name, int len);
a094f6
+
a094f6
 extern CORE_ADDR generic_skip_trampoline_code (struct frame_info *frame,
a094f6
 					       CORE_ADDR pc);
a094f6
 
a094f6
Index: gdb-7.6.1/gdb/doublest.c
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/doublest.c	2017-03-11 21:42:26.681253106 +0100
a094f6
+++ gdb-7.6.1/gdb/doublest.c	2017-03-11 21:51:53.062063411 +0100
a094f6
@@ -800,63 +800,16 @@
a094f6
 }
a094f6
 
a094f6
 
a094f6
-/* Return a floating-point format for a floating-point variable of
a094f6
-   length LEN.  If no suitable floating-point format is found, an
a094f6
-   error is thrown.
a094f6
-
a094f6
-   We need this functionality since information about the
a094f6
-   floating-point format of a type is not always available to GDB; the
a094f6
-   debug information typically only tells us the size of a
a094f6
-   floating-point type.
a094f6
-
a094f6
-   FIXME: kettenis/2001-10-28: In many places, particularly in
a094f6
-   target-dependent code, the format of floating-point types is known,
a094f6
-   but not passed on by GDB.  This should be fixed.  */
a094f6
-
a094f6
-static const struct floatformat *
a094f6
-floatformat_from_length (struct gdbarch *gdbarch, LONGEST len)
a094f6
-{
a094f6
-  const struct floatformat *format;
a094f6
-
a094f6
-  if (len * TARGET_CHAR_BIT == gdbarch_half_bit (gdbarch))
a094f6
-    format = gdbarch_half_format (gdbarch)
a094f6
-	       [gdbarch_byte_order (gdbarch)];
a094f6
-  else if (len * TARGET_CHAR_BIT == gdbarch_float_bit (gdbarch))
a094f6
-    format = gdbarch_float_format (gdbarch)
a094f6
-	       [gdbarch_byte_order (gdbarch)];
a094f6
-  else if (len * TARGET_CHAR_BIT == gdbarch_double_bit (gdbarch))
a094f6
-    format = gdbarch_double_format (gdbarch)
a094f6
-	       [gdbarch_byte_order (gdbarch)];
a094f6
-  else if (len * TARGET_CHAR_BIT == gdbarch_long_double_bit (gdbarch))
a094f6
-    format = gdbarch_long_double_format (gdbarch)
a094f6
-	       [gdbarch_byte_order (gdbarch)];
a094f6
-  /* On i386 the 'long double' type takes 96 bits,
a094f6
-     while the real number of used bits is only 80,
a094f6
-     both in processor and in memory.
a094f6
-     The code below accepts the real bit size.  */ 
a094f6
-  else if ((gdbarch_long_double_format (gdbarch) != NULL)
a094f6
-	   && (len * TARGET_CHAR_BIT
a094f6
-               == gdbarch_long_double_format (gdbarch)[0]->totalsize))
a094f6
-    format = gdbarch_long_double_format (gdbarch)
a094f6
-	       [gdbarch_byte_order (gdbarch)];
a094f6
-  else
a094f6
-    format = NULL;
a094f6
-  if (format == NULL)
a094f6
-    error (_("Unrecognized %s-bit floating-point type."),
a094f6
-	   plongest (len * TARGET_CHAR_BIT));
a094f6
-  return format;
a094f6
-}
a094f6
+/* Return the floating-point format for a floating-point variable of
a094f6
+   type TYPE.  */
a094f6
 
a094f6
 const struct floatformat *
a094f6
 floatformat_from_type (const struct type *type)
a094f6
 {
a094f6
   struct gdbarch *gdbarch = get_type_arch (type);
a094f6
 
a094f6
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
a094f6
-  if (TYPE_FLOATFORMAT (type) != NULL)
a094f6
-    return TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
a094f6
-  else
a094f6
-    return floatformat_from_length (gdbarch, TYPE_LENGTH (type));
a094f6
+  gdb_assert (TYPE_FLOATFORMAT (type));
a094f6
+  return TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
a094f6
 }
a094f6
 
a094f6
 /* Extract a floating-point number of type TYPE from a target-order
a094f6
Index: gdb-7.6.1/gdb/dwarf2read.c
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/dwarf2read.c	2017-03-11 21:45:39.098565504 +0100
a094f6
+++ gdb-7.6.1/gdb/dwarf2read.c	2017-03-11 21:48:54.877873941 +0100
a094f6
@@ -12901,6 +12901,27 @@
a094f6
   return this_type;
a094f6
 }
a094f6
 
a094f6
+/* Allocate a floating-point type of size BITS and name NAME.  Pass NAME_HINT
a094f6
+   (which may be different from NAME) to the architecture back-end to allow
a094f6
+   it to guess the correct format if necessary.  */
a094f6
+
a094f6
+static struct type *
a094f6
+dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
a094f6
+			const char *name_hint)
a094f6
+{
a094f6
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
a094f6
+  const struct floatformat **format;
a094f6
+  struct type *type;
a094f6
+
a094f6
+  format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
a094f6
+  if (format)
a094f6
+    type = init_float_type (objfile, bits, name, format);
a094f6
+  else
a094f6
+    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, name);
a094f6
+
a094f6
+  return type;
a094f6
+}
a094f6
+
a094f6
 /* Find a representation of a given base type and install
a094f6
    it in the TYPE field of the die.  */
a094f6
 
a094f6
@@ -12941,14 +12962,14 @@
a094f6
 	type = init_boolean_type (objfile, bits, 1, name);
a094f6
 	break;
a094f6
       case DW_ATE_complex_float:
a094f6
-	type = init_float_type (objfile, bits / 2, NULL, NULL);
a094f6
+	type = dwarf2_init_float_type (objfile, bits / 2, NULL, name);
a094f6
 	type = init_complex_type (objfile, name, type);
a094f6
 	break;
a094f6
       case DW_ATE_decimal_float:
a094f6
 	type = init_decfloat_type (objfile, bits, name);
a094f6
 	break;
a094f6
       case DW_ATE_float:
a094f6
-	type = init_float_type (objfile, bits, name, NULL);
a094f6
+	type = dwarf2_init_float_type (objfile, bits, name, name);
a094f6
 	break;
a094f6
       case DW_ATE_signed:
a094f6
 	type = init_integer_type (objfile, bits, 0, name);
a094f6
Index: gdb-7.6.1/gdb/gdbarch.c
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/gdbarch.c	2017-03-11 21:42:26.681253106 +0100
a094f6
+++ gdb-7.6.1/gdb/gdbarch.c	2017-03-11 21:49:55.628279481 +0100
a094f6
@@ -181,6 +181,7 @@
a094f6
   const struct floatformat ** double_format;
a094f6
   int long_double_bit;
a094f6
   const struct floatformat ** long_double_format;
a094f6
+  gdbarch_floatformat_for_type_ftype *floatformat_for_type;
a094f6
   int ptr_bit;
a094f6
   int addr_bit;
a094f6
   int dwarf2_addr_size;
a094f6
@@ -353,6 +354,7 @@
a094f6
   0,  /* double_format */
a094f6
   8 * sizeof (long double),  /* long_double_bit */
a094f6
   0,  /* long_double_format */
a094f6
+  default_floatformat_for_type,  /* floatformat_for_type */
a094f6
   8 * sizeof (void*),  /* ptr_bit */
a094f6
   8 * sizeof (void*),  /* addr_bit */
a094f6
   sizeof (void*),  /* dwarf2_addr_size */
a094f6
@@ -438,7 +440,7 @@
a094f6
   default_register_reggroup_p,  /* register_reggroup_p */
a094f6
   0,  /* fetch_pointer_argument */
a094f6
   0,  /* regset_from_core_section */
a094f6
-  0,  /* core_regset_sections */
a094f6
+  0,  /* iterate_over_regset_sections */
a094f6
   0,  /* make_corefile_notes */
a094f6
   0,  /* elfcore_write_linux_prpsinfo */
a094f6
   0,  /* find_memory_regions */
a094f6
@@ -530,6 +532,7 @@
a094f6
   gdbarch->float_bit = 4*TARGET_CHAR_BIT;
a094f6
   gdbarch->double_bit = 8*TARGET_CHAR_BIT;
a094f6
   gdbarch->long_double_bit = 8*TARGET_CHAR_BIT;
a094f6
+  gdbarch->floatformat_for_type = default_floatformat_for_type;
a094f6
   gdbarch->ptr_bit = gdbarch->int_bit;
a094f6
   gdbarch->char_signed = -1;
a094f6
   gdbarch->virtual_frame_pointer = legacy_virtual_frame_pointer;
a094f6
@@ -652,6 +655,7 @@
a094f6
   /* Skip verify of long_double_bit, invalid_p == 0 */
a094f6
   if (gdbarch->long_double_format == 0)
a094f6
     gdbarch->long_double_format = floatformats_ieee_double;
a094f6
+  /* Skip verify of floatformat_for_type, invalid_p == 0 */
a094f6
   /* Skip verify of ptr_bit, invalid_p == 0 */
a094f6
   if (gdbarch->addr_bit == 0)
a094f6
     gdbarch->addr_bit = gdbarch_ptr_bit (gdbarch);
a094f6
@@ -1021,6 +1025,9 @@
a094f6
                       "gdbarch_dump: float_format = %s\n",
a094f6
                       pformat (gdbarch->float_format));
a094f6
   fprintf_unfiltered (file,
a094f6
+                      "gdbarch_dump: floatformat_for_type = <%s>\n",
a094f6
+                      host_address_to_string (gdbarch->floatformat_for_type));
a094f6
+  fprintf_unfiltered (file,
a094f6
                       "gdbarch_dump: fp0_regnum = %s\n",
a094f6
                       plongest (gdbarch->fp0_regnum));
a094f6
   fprintf_unfiltered (file,
a094f6
@@ -1738,6 +1745,23 @@
a094f6
   gdbarch->long_double_format = long_double_format;
a094f6
 }
a094f6
 
a094f6
+const struct floatformat **
a094f6
+gdbarch_floatformat_for_type (struct gdbarch *gdbarch, const char *name, int length)
a094f6
+{
a094f6
+  gdb_assert (gdbarch != NULL);
a094f6
+  gdb_assert (gdbarch->floatformat_for_type != NULL);
a094f6
+  if (gdbarch_debug >= 2)
a094f6
+    fprintf_unfiltered (gdb_stdlog, "gdbarch_floatformat_for_type called\n");
a094f6
+  return gdbarch->floatformat_for_type (gdbarch, name, length);
a094f6
+}
a094f6
+
a094f6
+void
a094f6
+set_gdbarch_floatformat_for_type (struct gdbarch *gdbarch,
a094f6
+                                  gdbarch_floatformat_for_type_ftype floatformat_for_type)
a094f6
+{
a094f6
+  gdbarch->floatformat_for_type = floatformat_for_type;
a094f6
+}
a094f6
+
a094f6
 int
a094f6
 gdbarch_ptr_bit (struct gdbarch *gdbarch)
a094f6
 {
a094f6
Index: gdb-7.6.1/gdb/gdbarch.h
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/gdbarch.h	2017-03-11 21:42:26.681253106 +0100
a094f6
+++ gdb-7.6.1/gdb/gdbarch.h	2017-03-11 21:48:54.879873955 +0100
a094f6
@@ -176,6 +176,14 @@
a094f6
 extern const struct floatformat ** gdbarch_long_double_format (struct gdbarch *gdbarch);
a094f6
 extern void set_gdbarch_long_double_format (struct gdbarch *gdbarch, const struct floatformat ** long_double_format);
a094f6
 
a094f6
+/* Returns the floating-point format to be used for values of length LENGTH.
a094f6
+   NAME, if non-NULL, is the type name, which may be used to distinguish
a094f6
+   different target formats of the same length. */
a094f6
+
a094f6
+typedef const struct floatformat ** (gdbarch_floatformat_for_type_ftype) (struct gdbarch *gdbarch, const char *name, int length);
a094f6
+extern const struct floatformat ** gdbarch_floatformat_for_type (struct gdbarch *gdbarch, const char *name, int length);
a094f6
+extern void set_gdbarch_floatformat_for_type (struct gdbarch *gdbarch, gdbarch_floatformat_for_type_ftype *floatformat_for_type);
a094f6
+
a094f6
 /* For most targets, a pointer on the target and its representation as an
a094f6
    address in GDB have the same size and "look the same".  For such a
a094f6
    target, you need only set gdbarch_ptr_bit and gdbarch_addr_bit
a094f6
Index: gdb-7.6.1/gdb/gdbarch.sh
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/gdbarch.sh	2017-03-11 21:42:26.681253106 +0100
a094f6
+++ gdb-7.6.1/gdb/gdbarch.sh	2017-03-11 21:48:54.880873961 +0100
a094f6
@@ -383,6 +383,11 @@
a094f6
 v:int:long_double_bit:::8 * sizeof (long double):8*TARGET_CHAR_BIT::0
a094f6
 v:const struct floatformat **:long_double_format:::::floatformats_ieee_double::pformat (gdbarch->long_double_format)
a094f6
 
a094f6
+# Returns the floating-point format to be used for values of length LENGTH.
a094f6
+# NAME, if non-NULL, is the type name, which may be used to distinguish
a094f6
+# different target formats of the same length.
a094f6
+m:const struct floatformat **:floatformat_for_type:const char *name, int length:name, length:0:default_floatformat_for_type::0
a094f6
+
a094f6
 # For most targets, a pointer on the target and its representation as an
a094f6
 # address in GDB have the same size and "look the same".  For such a
a094f6
 # target, you need only set gdbarch_ptr_bit and gdbarch_addr_bit
a094f6
Index: gdb-7.6.1/gdb/stabsread.c
a094f6
===================================================================
a094f6
--- gdb-7.6.1.orig/gdb/stabsread.c	2017-03-11 21:48:47.133822245 +0100
a094f6
+++ gdb-7.6.1/gdb/stabsread.c	2017-03-11 21:48:54.881873968 +0100
a094f6
@@ -338,6 +338,24 @@
a094f6
   return (*type_addr);
a094f6
 }
a094f6
 
a094f6
+/* Allocate a floating-point type of size BITS.  */
a094f6
+
a094f6
+static struct type *
a094f6
+dbx_init_float_type (struct objfile *objfile, int bits)
a094f6
+{
a094f6
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
a094f6
+  const struct floatformat **format;
a094f6
+  struct type *type;
a094f6
+
a094f6
+  format = gdbarch_floatformat_for_type (gdbarch, NULL, bits);
a094f6
+  if (format)
a094f6
+    type = init_float_type (objfile, bits, NULL, format);
a094f6
+  else
a094f6
+    type = init_type (objfile, TYPE_CODE_ERROR, bits / TARGET_CHAR_BIT, NULL);
a094f6
+
a094f6
+  return type;
a094f6
+}
a094f6
+
a094f6
 /* for all the stabs in a given stab vector, build appropriate types 
a094f6
    and fix their symbols in given symbol vector.  */
a094f6
 
a094f6
@@ -3842,11 +3860,11 @@
a094f6
   if (details == NF_COMPLEX || details == NF_COMPLEX16
a094f6
       || details == NF_COMPLEX32)
a094f6
     {
a094f6
-      rettype = init_float_type (objfile, nbits / 2, NULL, NULL);
a094f6
+      rettype = dbx_init_float_type (objfile, nbits / 2);
a094f6
       return init_complex_type (objfile, NULL, rettype);
a094f6
     }
a094f6
 
a094f6
-  return init_float_type (objfile, nbits, NULL, NULL);
a094f6
+  return dbx_init_float_type (objfile, nbits);
a094f6
 }
a094f6
 
a094f6
 /* Read a number from the string pointed to by *PP.
a094f6
@@ -4133,7 +4151,7 @@
a094f6
   if (n3 == 0 && n2 > 0)
a094f6
     {
a094f6
       struct type *float_type
a094f6
-	= init_float_type (objfile, n2 * TARGET_CHAR_BIT, NULL, NULL);
a094f6
+	= dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT);
a094f6
 
a094f6
       if (self_subrange)
a094f6
 	return init_complex_type (objfile, NULL, float_type);