Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Martin Galvan <martin.galvan@tallertechnologies.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH v2][PR gdb/19893] Fix handling of synthetic C++ references
Date: Tue, 24 May 2016 20:36:00 -0000	[thread overview]
Message-ID: <CAOKbPbZjzy=KnbM1BYK27CQC9hfpko=BBT3E3svn6ACQ6_Nrcg@mail.gmail.com> (raw)
In-Reply-To: <d646b112-1542-ff3d-a018-dbbef37e3eca@redhat.com>

I've just realized that my comment isn't entirely clear. The
"@address" string is shown only for structure types, not for regular
variables, arrays or such. It makes sense because only those are
affected by set print object, but the comment doesn't explicitly say
so.

I don't know whether it'd be preferable to have <synthetic pointer>
everywhere as opposed to @address. I guess @address is more consistent
with non-synthetic references, and it also hides the fact they're
synthetic from the user, but there are cases (such as
DW_AT_const_value) where @address wouldn't work/make sense.

So I think before proceeding we should decide which output is better.
Perhaps we could show @address whenever possible, and <synthetic
pointer> for the corner cases?

On Tue, May 24, 2016 at 11:51 AM, Pedro Alves <palves@redhat.com> wrote:
> But normal pointers don't print @address either, only references do.

Yeah, I was referring to references :)

> Not printing "@address" with "set print object off" seems like
> hiding information from the user, information that we could show.
> We always print it for non-synthetic references, AFAICS.

Yes, we do.

> Your comment in the patch, in generic_val_print_ref, reads:
>
> +        if options->objectprint is true, c_value_print will call value_addr
> +        on the reference, which coerces synthetic references and returns a
> +        'not_lval'.  */
>
> So if that works, I don't understand -- wouldn't calling value_addr
> or coerce_ref in generic_val_print_ref if you have a synthetic
> reference, or any reference even, be what you'd want?

If I'm not mistaken, doing that would cause us to always print
"@address". Which again, may be in fact the right thing to do.

>> I *could*, however, manually call
>> value->location.computed.funcs->check_synthetic_pointer in
>> generic_val_print_ref instead of using value_bits_synthetic_pointer,
>> thus avoiding the check for lval_computed. But that's a bit ugly IMHO.
>
> I don't understand this one.  Only lval_computed values have a
> "location.computed.funcs" to call.

Yeah, you're right. For a moment I thought all values had an
lval_funcs member, but only computed ones do.

> So is the problem that this bit:
>
>    if (options->addressprint)
>      {
>       CORE_ADDR addr
>         = extract_typed_address (valaddr + embedded_offset, type);
>
> doesn't work / doesn't make sense with synthetic pointers?

Exactly. IIRC extract_typed_address would return zero (or maybe just
garbage?), because valaddr would actually be a pointer to the
synthetic pointer's lval_funcs instead of a target address.

On a related note, it'd be great (for debugging at least!) if unions
such as this had at least a discriminant of sorts.

> Should we be calling value_addr instead?

Perhaps. I stuck to calling extract_typed_address because I tried to
change as little code as possible. I'm seeing that
generic_val_print_ref has a path which coerces the reference anyway,
so we could always coerce it, get its address, and only print the
referenced value when required. I'd have to test it thoroughly to be
sure, though.

> Or are we perhaps missing a lval_funcs method?  (Ideally, all
> value properties/methods would go through a vtable like
> lval_funcs; think "making struct value a proper C++ class" going
> forward.)

Right now I don't think so. The existing methods should be enough to
handle these cases. Speaking of which, are there any plans to rewrite
this sort of object-oriented code in C++? I'd love to take a shot at
this in the future.

> I don't know where, but I think this should indeed be covered by
> tests somewhere.

Ok.


  reply	other threads:[~2016-05-24 20:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 16:00 Martin Galvan
2016-05-23 18:36 ` Martin Galvan
2016-05-24 10:48 ` Pedro Alves
2016-05-24 14:08   ` Martin Galvan
2016-05-24 14:51     ` Pedro Alves
2016-05-24 20:36       ` Martin Galvan [this message]
2016-05-25 18:24         ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOKbPbZjzy=KnbM1BYK27CQC9hfpko=BBT3E3svn6ACQ6_Nrcg@mail.gmail.com' \
    --to=martin.galvan@tallertechnologies.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox