gdb/fortran: Handle gdbarch_floatformat_for_type returning nullptr
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 21 May 2019 21:14:05 +0000 (22:14 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 21 May 2019 22:46:07 +0000 (23:46 +0100)
In this commit:

  commit 34d11c682fd96c7dbe3ebd6cd9033e65d51ec7a3
  Date:   Fri May 3 15:23:55 2019 +0100

      gdb/fortran: Use floatformats_ia64_quad for fortran 16-byte floats

GDB was changed such that the Fortran's 16-byte float format was
obtained by calling gdbarch_floatformat_for_type instead of just using
gdbarch_long_double_format as it was before.

The problem with this default_floatformat_for_type can return NULL in
some cases, and the code introduced in 34d11c682f didn't consider
this.

This commit introduces several alternative strategies for finding a
suitable 16-byte floating point type.  First GDB calls
gdbarch_floatformat_for_type (this was what 34d11c682f added), if this
returns null GDB will use gdbarch_long_double_format if it is the
correct size (this was the format used before 34d11c682f).  Finally,
if neither of the above provides a suitable type then GDB will create
a new dummy type.

This final dummy type is unlikely to provide an correct debug
experience as far as examining the 16-byte floats, but it should
prevent GDB crashing.

gdb/ChangeLog:

PR gdb/18644:
* f-lang.c (build_fortran_types): Handle the case where
gdbarch_floatformat_for_type returns a nullptr.

gdb/ChangeLog
gdb/f-lang.c

index 86f522d42e02b9eca1d13f21e69a9edb495111eb..b0b7503b28433e1e42dcc54943ec22f5dbf4e846 100644 (file)
@@ -1,3 +1,9 @@
+2019-05-21  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       PR gdb/18644:
+       * f-lang.c (build_fortran_types): Handle the case where
+       gdbarch_floatformat_for_type returns a nullptr.
+
 2019-05-21  Tom de Vries  <tdevries@suse.de>
 
        PR cli/24587
index 5855c68b38c632d566bf42bd65c4002964223349..e612eeda7f7fe0ad7b8c1f2dd8603b093d0f322a 100644 (file)
@@ -728,8 +728,16 @@ build_fortran_types (struct gdbarch *gdbarch)
     = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
                       "real*8", gdbarch_double_format (gdbarch));
   auto fmt = gdbarch_floatformat_for_type (gdbarch, "real(kind=16)", 128);
-  builtin_f_type->builtin_real_s16
-    = arch_float_type (gdbarch, 128, "real*16", fmt);
+  if (fmt != nullptr)
+    builtin_f_type->builtin_real_s16
+      = arch_float_type (gdbarch, 128, "real*16", fmt);
+  else if (gdbarch_long_double_bit (gdbarch) == 128)
+    builtin_f_type->builtin_real_s16
+      = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
+                        "real*16", gdbarch_long_double_format (gdbarch));
+  else
+    builtin_f_type->builtin_real_s16
+      = arch_type (gdbarch, TYPE_CODE_ERROR, 128, "real*16");
 
   builtin_f_type->builtin_complex_s8
     = arch_complex_type (gdbarch, "complex*8",
This page took 0.031788 seconds and 4 git commands to generate.