Re: [PATCHv2] gdb/fortran: Fix printing of logical true values for Flang

Andrew Burgess
2020-03-03T17:24:24Z

* Tom Tromey <tom@tromey.com> [2020-03-03 09:31:55 -0700]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
>
> Andrew> Thanks for looking into this. I think that the best solution right
> Andrew> now will be to handle TYPE_CODE_BOOL in f_val_print rather than
> Andrew> modifying generic_val_print_bool.
>
> Agreed.
>
> Andrew> The other possibility would be, I think, to add a new field to 'struct
> Andrew> language_defn' and use this in generic_val_print_bool instead of
> Andrew> comparing the value of current_lanuage directly, however, this isn't
> Andrew> the common approach, so I'd prefer to handle this case just like other
> Andrew> TYPE_CODE_* are handled for now.
>
> It would be nice if we could get away from having separate printing code
> for each language. I don't know how practical this is though.

I am slowly working on converting the language structure into a true
class, my thinking is that this would make it much easier to add more
per-language functions, and specialise as needed.

In this case we would then remove the special handling for Fortran and
make the common code be something like:

....
const gdb_byte *valaddr = value_contents_for_printing (original_value);

val = unpack_long (type, valaddr + embedded_offset * unit_size);
if (current_language->is_logical_false (val))
fputs_filtered (decorations->false_name, stream);
else if (current_language->is_logical_true (val))
fputs_filtered (decorations->true_name, stream);
else
print_longest (stream, 'd', 0, val);
....

I think there's lots of places in the value printing (and maybe
evaluation) code where we copy blocks of code just to allow for small
specialisations, I'd hope we could start to recombine some of this
stuff...

Thanks,
Andrew

>
> Andrew> I know that in places within GDB we do compare the value of
> Andrew> current_lanuage to the know language structures, but I'd like to move
> Andrew> us away from doing this.
>
> Also agreed.
>
> Tom