gdb/fortran: Change GDB print for fortran default types

Currently, when asking GDB to print the type of a Fortran default type
such as INTEGER or REAL, GDB will return the default name of that type,
e.g. "integer"/"real":

   (gdb) ptype integer
   type = integer
   (gdb) ptype real
   type = real

For LOGICAL and COMPLEX it would return the actual underlying types

   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex
   type = complex*4

Similarly, GDB would print the default integer type for the underlying
default type:

   (gdb) ptype integer*4
   type = integer
   (gdb) ptype real*4
   type = real
   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex*4
   type = complex*4

This is inconsistent and a bit confusing.  Both options somehow indicate
what the internal underlying type for the default type is - but I think
the logical/complex version is a bit clearer.

Consider again:

   (gdb) ptype integer
   type = integer

This indicates to a user that the type of "integer" is Fortran's default
integer type.  Without examining "ptype integer*4" I would expect, that
any variable declared integer in the actual code would also fit into a
GDB integer.  But, since we cannot adapt out internal types to the
compiler flags used at compile time of a debugged binary, this might be
wrong.  Consider debugging Fortran code compiled with GNU and e.g. the
"-fdefault-integer-8" flag.  In this case the gfortran default integer
would be integer*8 while GDB internally still would use a builtin_integer,
so an integer of the size of an integer*4 type.  On the other hand having
GDB print

   (gdb) ptype integer
   type = integer*4

makes this clearer.  I would still be tempted to fit a variable declared
integer in the code into a GDB integer - but at least ptype would
directly tell me what is going on.  Note, that when debugging a binary
compiled with "-fdefault-integer-8" a user will always see the actual
underlying type of any variable declared "integer" in the Fortran code.
So having the code

   program test
     integer :: a = 5
     print *, a ! breakpt
   end program test

will, when breaking at breakpt print

   (gdb) ptype var
   type = integer(kind=4)

or

   (gdb) ptype var
   type = integer(kind=8)

depending on the compiler flag.

This patch changes the outputs for the REAL and INTEGER default types to
actually print the internally used type over the default type name.

The new behavior for the above examples is:

   (gdb) ptype integer
   type = integer*4
   (gdb) ptype integer*4
   type = integer*4

Existing testcases have been adapted to reflect the new behavior.
This commit is contained in:
Nils-Christian Kempke 2022-04-11 14:06:56 +02:00
parent adc29023a7
commit 87abd9825d
3 changed files with 11 additions and 16 deletions

View File

@ -1636,7 +1636,7 @@ build_fortran_types (struct gdbarch *gdbarch)
= arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
builtin_f_type->builtin_integer
= arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer");
= arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer*4");
builtin_f_type->builtin_integer_s8
= arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
@ -1644,7 +1644,7 @@ build_fortran_types (struct gdbarch *gdbarch)
builtin_f_type->builtin_real
= arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
"real", gdbarch_float_format (gdbarch));
"real*4", gdbarch_float_format (gdbarch));
builtin_f_type->builtin_real_s8
= arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),

View File

@ -45,13 +45,13 @@ gdb_test "print c16" " = \\(-874,19\\)"
gdb_test "whatis c" "type = $complex4"
gdb_test "print \$_creal (c)" " = 1000"
with_test_prefix "c" {
gdb_test "whatis \$" " = real"
gdb_test "whatis \$" " = real\\*4"
}
gdb_test "whatis c4" "type = $complex4"
gdb_test "print \$_creal (c4)" " = 1000"
with_test_prefix "c4" {
gdb_test "whatis \$" " = real"
gdb_test "whatis \$" " = real\\*4"
}
gdb_test "whatis c8" "type = $complex8"
gdb_test "print \$_creal (c8)" " = 321"

View File

@ -73,26 +73,21 @@ proc test_float_literal_types_accepted {} {
# Test the default primitive Fortran types.
proc test_default_types {} {
gdb_test "ptype integer*4" "type = integer"
gdb_test "ptype integer_4" "type = integer"
gdb_test "ptype logical" "type = logical*4"
gdb_test "ptype real*4" "type = real"
gdb_test "ptype real_4" "type = real"
gdb_test "ptype complex" "type = complex*4"
gdb_test "ptype integer" "type = integer\\*4"
gdb_test "ptype logical" "type = logical\\*4"
gdb_test "ptype real" "type = real\\*4"
gdb_test "ptype complex" "type = complex\\*4"
}
# Test the the primitive Fortran types, those that GDB should always
# know, even if the program does not define them, are in fact, known.
proc test_primitive_types_known {} {
foreach type {void character \
integer*1 integer*2 integer integer*8 \
integer_1 integer_2 integer_8 \
integer*1 integer*2 integer*4 integer*8 \
integer_1 integer_2 integer_4 integer_8 \
logical*1 logical*2 logical*4 logical*8 \
logical_1 logical_2 logical_4 logical_8 \
real real*8 real*16 real_8 real_16 \
real*4 real*8 real*16 real_4 real_8 real_16 \
complex*4 complex*8 complex*16 \
complex_4 complex_8 complex_16} {