This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
- From: Andrew Burgess <andrew dot burgess at embecosm dot com>
- To: Christoph Weinmann <christoph dot t dot weinmann at intel dot com>
- Cc: qiyaoltc at gmail dot com, gdb-patches at sourceware dot org, jan dot kratochvil at redhat dot com
- Date: Wed, 13 Jul 2016 11:17:22 +0100
- Subject: Re: [PATCH] fortran: Print logical values as either .FALSE. or .TRUE.
- Authentication-results: sourceware.org; auth=none
- References: <1468396596-19212-1-git-send-email-christoph.t.weinmann@intel.com>
* 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