Re: Variable objects: references formatting

Jim Blandy
2006-05-04T06:08:08Z

On 5/3/06, Vladimir Prus <ghost@cs.msu.su> wrote:
> > - In GDB, when traversing types, remember to call check_typedef to
> > avoid having your traversal stopped by typedef nodes.
>
> Thanks, noted. So, in this case I should have called check_typedef before
> checking if type is reference, right?

Well, the get_type function is taking care of that one for you. So
it's enough to check the new types you uncover with TYPE_TARGET_TYPE.

> Would you like me to resend the patch adjusted per your comments, or you've
> already done those changes locally?

I've already done them. Here's the patch I actually committed (which
I should have posted when I did so):

gdb/ChangeLog:
2006-05-03 Vladimir Prus <ghost@cs.msu.su>

* varobj.c (c_value_of_variable): Ignore top-level references.
(Committed by Jim Blandy.)

Index: gdb/varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.59
diff -u -p -r1.59 varobj.c
--- gdb/varobj.c 27 Mar 2006 00:15:22 -0000 1.59
+++ gdb/varobj.c 3 May 2006 18:07:43 -0000
@@ -2054,10 +2054,16 @@ c_variable_editable (struct varobj *var)
static char *
c_value_of_variable (struct varobj *var)
{
- /* BOGUS: if val_print sees a struct/class, it will print out its
- children instead of "{...}" */
+ /* BOGUS: if val_print sees a struct/class, or a reference to one,
+ it will print out its children instead of "{...}". So we need to
+ catch that case explicitly. */
+ struct type *type = get_type (var);
+
+ /* Strip top-level references. */
+ while (TYPE_CODE (type) == TYPE_CODE_REF)
+ type = check_typedef (TYPE_TARGET_TYPE (type));

- switch (TYPE_CODE (get_type (var)))
+ switch (TYPE_CODE (type))
{