[PATCH] gdb/fortran Fixed printing of logical true values for Flang

Sharma, Alok Kumar
2020-03-02T17:00:58Z

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

Hi all,

I request you all to please review the patch. Below are the details.

Problem Description:

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.
--------------

Root cause:

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 flang
compiler uses -1. GDB should accept all the non zero values as TRUE.

Resolution:

Now function 'generic_val_print_bool' is modified to be able to print
true logical value for the Flang compiler.

Testing:

- No regression seen

Please let me know your comments.

Regards,
Alok

[-- Attachment #2: 0001-gdb-fortran-Fixed-printing-of-logical-true-values-fo.patch --]
[-- Type: application/octet-stream, Size: 1883 bytes --]

From f8a7a8070df398a143e49ed6f8d2702583689342 Mon Sep 17 00:00:00 2001
From: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
Date: Mon, 2 Mar 2020 21:49:50 +0530
Subject: [PATCH] gdb/fortran Fixed 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 flang
compiler uses -1. GDB should accept all the non zero values as TRUE.
Now function 'generic_val_print_bool' is modified to be able to print
true logical value for the Flang compiler.

gdb/ChangeLog:

* valprint.c (generic_val_print_bool): Changed to treat any
non-zero value as TRUE for fortran LOGICAL type.

Change-Id: I0509c5b50bf3481b9fca2aad46fb17742ec9aae3
---
gdb/valprint.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 8adbb3df45..1de0ebd3df 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -793,7 +793,10 @@ generic_val_print_bool (struct type *type,
val = unpack_long (type, valaddr + embedded_offset * unit_size);
if (val == 0)
fputs_filtered (decorations->false_name, stream);
- else if (val == 1)
+ /* The fortran standard doesnt specify how LOGICAL types are represented.
+ Different compilers use different non zero values to represent LOGICAL
+ TRUE. */
+ else if (current_language == &f_language_defn || val == 1)
fputs_filtered (decorations->true_name, stream);
else
print_longest (stream, 'd', 0, val);
--
2.17.1