From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: qiyaoltc@gmail.com (Yao Qi)
Cc: gdb-patches@sourceware.org (gdb-patches@sourceware.org),
tom@tromey.com (Tom Tromey)
Subject: Re: set_value_component_location in apply_val_pretty_printer
Date: Fri, 28 Oct 2016 18:58:00 -0000 [thread overview]
Message-ID: <20161028185834.0145C10B927@oc8523832656.ibm.com> (raw)
In-Reply-To: <CAH=s-PNzFsJ7GYJEnOeLaTdy1L0Z+hyvbQr-FSQ=aq6bDRuyZQ@mail.gmail.com> from "Yao Qi" at Oct 28, 2016 03:18:33 PM
Yao Qi wrote:
> I don't understand this piece of code in apply_val_pretty_printer,
> why do we need to call set_value_component_location?
>
> set_value_component_location (value, val);
> /* set_value_component_location resets the address, so we may
> need to set it again. */
> if (VALUE_LVAL (value) !=3D lval_internalvar
> && VALUE_LVAL (value) !=3D lval_internalvar_component
> && VALUE_LVAL (value) !=3D lval_computed)
> set_value_address (value, address + embedded_offset);
>
> It was added by Tom in
> https://sourceware.org/ml/gdb-patches/2010-06/msg00132.html
> There wasn't much information in email and ChangeLog.
This the case I mentioned in my recent email to Pedro here,
where we want to create a subobject of the original object.
The problem with the value printing routines is that if you
are printing an object of some complicated type, the routines
recurse through subobjects. However, you don't always want
to allocate a new value object for the current subobject
just so you can make the recursive call.
That's why all the val_print routines not just receive the
original value object (which remains unchanged even while
recursing through subobjects), but also an idenfication of
the subobject that is to be processed: this is a pair of
offset and type, and means, the subobject of type "type"
starting at offset "offset" within the larger object.
This works fine for the various routines in the valprint
files. However, when using a Python pretty-printer, you
can only pass a normal value object; the pretty-printer
is not set up to handle subobjects. Therefore, at this
point apply_val_pretty_printer does actually have to
allocate a new value object to hold the subobject.
It's reasonably simple to just create a new object of
the correct type and having the correct contents. However,
some of the value printers also want to use the value's
*location*. Just allocating a fresh object would have
no location information. That's why the code above
calls set_value_component_location to set the location
of the new value to the same as the location of the old.
But this isn't really correct either, since we need the
location of the *subobject*. Now if the value resides
in inferior memory, we can get there simply by adding
the offset to the value address. But that's not actually
correct for values with other location types.
I think we should either add an offset parameter to
set_value_component_location, and have it attempt to
do the best thing possible to describe the subobject
location, or maybe even provide a function that creates
the subobject directly in one go, along the lines of
value_primitive_field, except not based on struct
types but simply using an offset and subobject type.
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com
next prev parent reply other threads:[~2016-10-28 18:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-28 14:18 Yao Qi
2016-10-28 18:58 ` Ulrich Weigand [this message]
2016-10-31 3:07 ` Tom Tromey
2016-11-14 12:52 ` Yao Qi
2016-11-14 16:38 ` Ulrich Weigand
2016-11-21 14:14 ` Yao Qi
2016-11-21 18:23 ` Yao Qi
2016-11-21 20:37 ` Yao Qi
2016-11-22 9:00 ` Yao Qi
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=20161028185834.0145C10B927@oc8523832656.ibm.com \
--to=uweigand@de.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
--cc=tom@tromey.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