public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
@ 2016-07-13  7:56 Christoph Weinmann
  2016-07-13  8:03 ` Jan Kratochvil
  2016-07-13 10:17 ` Andrew Burgess
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Weinmann @ 2016-07-13  7:56 UTC (permalink / raw)
  To: qiyaoltc, gdb-patches; +Cc: jan.kratochvil

A Logical value in Fortran may be either .FALSE. or .TRUE.
When converting from integer, a subset of compilers evaluate
the whole value, while others only check if the least significant
bit is set.  This patch unifies the printing output by evaluating
only the lsb.

2014-03-25  Christoph Weinmann  <christoph.t.weinmann@intel.com>

	* f-valprint.c (f_val_print): Print .FALSE. when the lsb
	is '0'.  Print .TRUE. in all other cases.


Signed-off-by: Christoph Weinmann <christoph.t.weinmann@intel.com>
---
 gdb/f-valprint.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index b6d1ab9..06154d1 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -350,6 +350,20 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
       fprintf_filtered (stream, " )");
       break;     
 
+    case TYPE_CODE_BOOL:
+      {
+	int val = unpack_long (type, valaddr + embedded_offset);
+	/* As a superset of compilers treat logical values
+	  differently (e.g. .TRUE. can be "-1" or "1", the
+	  common baseline is to evaluate if the least
+	  significant bit is set or not.  */
+	if ((val & 1) == 0)
+	  fputs_filtered (f_decorations.false_name, stream);
+	else
+	  fputs_filtered (f_decorations.true_name, stream);
+      }
+      break;
+
     case TYPE_CODE_REF:
     case TYPE_CODE_FUNC:
     case TYPE_CODE_FLAGS:
@@ -359,7 +373,6 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
     case TYPE_CODE_RANGE:
     case TYPE_CODE_UNDEF:
     case TYPE_CODE_COMPLEX:
-    case TYPE_CODE_BOOL:
     case TYPE_CODE_CHAR:
     default:
       generic_val_print (type, valaddr, embedded_offset, address,
-- 
1.7.0.7

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
  2016-07-13  7:56 [PATCH] fortran: Print logical values as either .FALSE. or .TRUE Christoph Weinmann
@ 2016-07-13  8:03 ` Jan Kratochvil
  2016-07-13 13:32   ` Weinmann, Christoph T
  2016-07-13 10:17 ` Andrew Burgess
  1 sibling, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2016-07-13  8:03 UTC (permalink / raw)
  To: Christoph Weinmann; +Cc: qiyaoltc, gdb-patches

On Wed, 13 Jul 2016 09:56:36 +0200, Christoph Weinmann wrote:
> A Logical value in Fortran may be either .FALSE. or .TRUE.
> When converting from integer, a subset of compilers evaluate
> the whole value, while others only check if the least significant
> bit is set.  This patch unifies the printing output by evaluating
> only the lsb.
[...]
> +	if ((val & 1) == 0)
> +	  fputs_filtered (f_decorations.false_name, stream);
> +	else
> +	  fputs_filtered (f_decorations.true_name, stream);

Doesn't it need to check DW_AT_producer then?  GDB already does that in some
cases.

If the compiler evaluates the whole value, val==16, then GDB will print
something different than what the compiler evaluates.


Jan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
  2016-07-13  7:56 [PATCH] fortran: Print logical values as either .FALSE. or .TRUE Christoph Weinmann
  2016-07-13  8:03 ` Jan Kratochvil
@ 2016-07-13 10:17 ` Andrew Burgess
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2016-07-13 10:17 UTC (permalink / raw)
  To: Christoph Weinmann; +Cc: qiyaoltc, gdb-patches, jan.kratochvil

* Christoph Weinmann <christoph.t.weinmann@intel.com> [2016-07-13 09:56:36 +0200]:

> A Logical value in Fortran may be either .FALSE. or .TRUE.
> When converting from integer, a subset of compilers evaluate
> the whole value, while others only check if the least significant
> bit is set.  This patch unifies the printing output by evaluating
> only the lsb.
> 
> 2014-03-25  Christoph Weinmann  <christoph.t.weinmann@intel.com>
> 
> 	* f-valprint.c (f_val_print): Print .FALSE. when the lsb
> 	is '0'.  Print .TRUE. in all other cases.
> 
> 
> Signed-off-by: Christoph Weinmann <christoph.t.weinmann@intel.com>
> ---
>  gdb/f-valprint.c |   15 ++++++++++++++-
>  1 files changed, 14 insertions(+), 1 deletions(-)
> 
> diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
> index b6d1ab9..06154d1 100644
> --- a/gdb/f-valprint.c
> +++ b/gdb/f-valprint.c
> @@ -350,6 +350,20 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
>        fprintf_filtered (stream, " )");
>        break;     
>  
> +    case TYPE_CODE_BOOL:
> +      {
> +	int val = unpack_long (type, valaddr + embedded_offset);
> +	/* As a superset of compilers treat logical values
> +	  differently (e.g. .TRUE. can be "-1" or "1", the
> +	  common baseline is to evaluate if the least
> +	  significant bit is set or not.  */
> +	if ((val & 1) == 0)
> +	  fputs_filtered (f_decorations.false_name, stream);
> +	else
> +	  fputs_filtered (f_decorations.true_name, stream);
> +      }
> +      break;
> +

Comparing this code to valprint.c:generic_val_print_bool then I see
that we loose the ability to force scalar formatting, so I guess:

   p/d some_bool_variable

will no longer work with your patch.

I would suggest creating fortran_val_print_bool as a copy of
generic_val_print_bool, and then modify only as needed.

I agree with Jan that checking the producer string would be the best
solution, but failing that I'd write the check of val as:

   if (val == 0)
      fputs_filtered ( ... false ... );
   else
      fputs_filtered ( ... true ... );

but I guess that's just a C background, where I'd consider anything
non-zero, even if the LSB _was_ zero as true.

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
  2016-07-13  8:03 ` Jan Kratochvil
@ 2016-07-13 13:32   ` Weinmann, Christoph T
  2016-07-13 13:54     ` Jan Kratochvil
  0 siblings, 1 reply; 5+ messages in thread
From: Weinmann, Christoph T @ 2016-07-13 13:32 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: qiyaoltc, gdb-patches

> -----Original Message-----
> From: Jan Kratochvil [mailto:jan.kratochvil@redhat.com]
> Sent: Wednesday, July 13, 2016 10:03 AM
> To: Weinmann, Christoph T <christoph.t.weinmann@intel.com>
> Cc: qiyaoltc@gmail.com; gdb-patches@sourceware.org
> Subject: Re: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
> 
> On Wed, 13 Jul 2016 09:56:36 +0200, Christoph Weinmann wrote:
> > A Logical value in Fortran may be either .FALSE. or .TRUE.
> > When converting from integer, a subset of compilers evaluate the whole
> > value, while others only check if the least significant bit is set.
> > This patch unifies the printing output by evaluating only the lsb.
> [...]
> > +	if ((val & 1) == 0)
> > +	  fputs_filtered (f_decorations.false_name, stream);
> > +	else
> > +	  fputs_filtered (f_decorations.true_name, stream);
> 
> Doesn't it need to check DW_AT_producer then?  GDB already does that in
> some cases.
>
Thanks for the hint Jan, I will take a look.

> If the compiler evaluates the whole value, val==16, then GDB will print
> something different than what the compiler evaluates.
>
I will investigate here too, as I confess I was focused on gfortran and ifort here.
 
> 
> Jan

Thanks,
Cchristoph
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
  2016-07-13 13:32   ` Weinmann, Christoph T
@ 2016-07-13 13:54     ` Jan Kratochvil
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Kratochvil @ 2016-07-13 13:54 UTC (permalink / raw)
  To: Weinmann, Christoph T; +Cc: qiyaoltc, gdb-patches

On Wed, 13 Jul 2016 15:32:40 +0200, Weinmann, Christoph T wrote:
> > If the compiler evaluates the whole value, val==16, then GDB will print
> > something different than what the compiler evaluates.
> >
> I will investigate here too, as I confess I was focused on gfortran and ifort here.

It may be good to write into the comment how specifically gfortran and how
ifort behave.

And for example if gfortran always uses only 0 or 1 then GDB should print
rather the value as number if it is >=2 - as it indicates some bug in the
inferior code.


Thanks,
Jan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-13 13:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-13  7:56 [PATCH] fortran: Print logical values as either .FALSE. or .TRUE Christoph Weinmann
2016-07-13  8:03 ` Jan Kratochvil
2016-07-13 13:32   ` Weinmann, Christoph T
2016-07-13 13:54     ` Jan Kratochvil
2016-07-13 10:17 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).