From 5e5d66b6a46c7b0353308bfb508b96a59f1addbf Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Mon, 2 Mar 2020 18:08:49 +0000 Subject: gdb/fortran: Fix printing of logical true values for Flang GDB is not able to print logical true values for Flang compiler. Actual result: (gdb) p l $1 = 4294967295 Expected result: (gdb) p l $1 = .TRUE. This is due to GDB expecting representation of true value being 1. The Fortran standard doesnt specify how LOGICAL types are represented. Different compilers use different non-zero values to represent logical true. The gfortran compiler uses 1 to represent logical true and the flang compiler uses -1. GDB should accept all the non-zero values as true. This is achieved by handling TYPE_CODE_BOOL in f_val_print and printing any non-zero value as true. gdb/ChangeLog: * f-valprint.c (f_val_print): Handle TYPE_CODE_BOOL, any non-zero value should be printed as true. gdb/testsuite/ChangeLog: * gdb.fortran/logical.exp: Add tests that any non-zero value is printed as true. --- gdb/testsuite/gdb.fortran/logical.exp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gdb/testsuite/gdb.fortran') diff --git a/gdb/testsuite/gdb.fortran/logical.exp b/gdb/testsuite/gdb.fortran/logical.exp index f002815..96e6f8f 100644 --- a/gdb/testsuite/gdb.fortran/logical.exp +++ b/gdb/testsuite/gdb.fortran/logical.exp @@ -33,3 +33,21 @@ gdb_test "p l1" " = \\.TRUE\\." gdb_test "p l2" " = \\.TRUE\\." gdb_test "p l4" " = \\.TRUE\\." gdb_test "p l8" " = \\.TRUE\\." + +# Different Fortran compilers use different values for logical true. +# Check how GDB handles this by modifying the underlying value for our +# logical variables and check they still print as true. +foreach_with_prefix var { l l1 l2 l4 l8 } { + set len [get_integer_valueof "sizeof (${var})" "get sizeof ${var}"] + set addr [get_hexadecimal_valueof "&l" "get address of ${var}"] + + for { set i 0 } { $i < $len } { incr i } { + with_test_prefix "byte $i" { + gdb_test_no_output "set *((uint8_t *) ${addr}) = 0xff" \ + "set contents of byte at offset $i" + gdb_test "p l" " = \\.TRUE\\." + incr addr + set addr [format "0x%x" $addr] + } + } +} -- cgit v1.1