From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: ppluzhnikov@google.com (Paul Pluzhnikov)
Cc: tromey@redhat.com (Tom Tromey), gdb-patches@sourceware.org
Subject: Re: [RFC] [patch] 'p->x' vs. 'p.x' and 'print object on'
Date: Wed, 22 Oct 2008 22:32:00 -0000 [thread overview]
Message-ID: <200810222231.m9MMVb4P020569@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <8ac60eac0808191104r38efbd1fi28db42c05ae04d1d@mail.gmail.com> from "Paul Pluzhnikov" at Aug 19, 2008 11:04:42 AM
Paul Pluzhnikov wrote:
> gdb/ChangeLog
>
> 2008-08-19 Paul Pluzhnikov <ppluzhnikov@google.com>
>
> Changes to treat 'p.x' and 'p->x' the same.
> * eval.c (value_static_or_dynamic_member): New.
> (evaluate_subexp_standard): Call it.
>
> gdb/testsuite/ChangeLog
>
> 2008-08-19 Paul Pluzhnikov <ppluzhnikov@google.com>
>
> * gdb.cp/class3.exp: New test case.
> * gdb.cp/class3.cc: New source file.
Sorry for the late review. Tom just pointed me to this
patch in the context of a different discussion ...
In general, I think the approach looks right to me.
However, the current patch does seem to have a couple
of issues:
> +static struct value *
> +value_static_or_dynamic_member(struct value *arg, char *string,
> + char *name, enum noside noside)
> +{
> + struct type *type = value_type (arg);
> + struct value *temp;
> +
> + if (noside == EVAL_AVOID_SIDE_EFFECTS)
> + return value_zero (lookup_struct_elt_type (type, string, 0),
> + lval_memory);
> + temp = arg;
> + {
> + volatile struct gdb_exception except;
> + struct value *v = NULL;
> + TRY_CATCH (except, RETURN_MASK_ERROR)
> + {
> + v = value_struct_elt (&temp, NULL, string, NULL, name);
> + }
> + if (v)
> + return v;
> + }
> +
> + /* If we got here, value_struct_elt() above must have thrown,
> + and there is no field 'name' in 'type'.
> + Try dynamic type of 'arg' instead. */
> +
> + if (TYPE_TARGET_TYPE(type)
> + && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
> + {
> + struct type *real_type;
> + int full, top, using_enc;
> + real_type = value_rtti_target_type (arg, &full, &top, &using_enc);
> + if (real_type)
> + {
> + if (TYPE_CODE (type) == TYPE_CODE_PTR)
> + real_type = lookup_pointer_type (real_type);
> + else
> + real_type = lookup_reference_type (real_type);
> +
> + temp = arg = value_cast (real_type, arg);
> + }
> + }
> + return value_struct_elt (&temp, NULL, string, NULL, name);
> +}
You're treating looking up for type (EVAL_AVOID_SIDE_EFFECTS)
differently from looking up for value; in the first case, you
*never* look at the dynamic type -- that doesn't seem right
to me (and in fact differs from what the original code does).
Maybe you should add some "ptype p->x" tests to exercise
this path as well.
Also, you're calling value_static_or_dynamic_member both for
class types *and* for pointer types -- but the whole dynamic
type lookup as written only works for pointer types (starting
with the if (TYPE_TARGET_TYPE)).
If you really want to treat p.x and p->x equivalent in every
case, why don't you call value_static_or_dynamic_member *always*
with the class type (using a value_ind in the STRUCTOP_PTR case)?
Then you'd use value_rtti_type instead of value_rtti_target_type.
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
prev parent reply other threads:[~2008-10-22 22:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-17 21:49 Paul Pluzhnikov
2008-07-22 0:53 ` Tom Tromey
2008-07-30 17:51 ` Paul Pluzhnikov
2008-08-07 17:31 ` Tom Tromey
2008-08-07 20:20 ` Daniel Jacobowitz
2008-08-11 15:09 ` Tom Tromey
2008-08-19 18:05 ` Paul Pluzhnikov
2008-08-26 16:45 ` Paul Pluzhnikov
2008-10-22 22:32 ` Ulrich Weigand [this message]
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=200810222231.m9MMVb4P020569@d12av02.megacenter.de.ibm.com \
--to=uweigand@de.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=ppluzhnikov@google.com \
--cc=tromey@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