This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] varobj: call CHECK_TYPEDEF


On Wed, Jun 11, 2003 at 09:28:10PM -0400, Daniel Jacobowitz wrote:
> On Wed, Jun 11, 2003 at 05:36:02PM -0700, Keith Seitz wrote:
> > On Wed, 2003-06-11 at 16:49, David Carlton wrote: 
> > > I've just gone and looked over the thread and at Keith's patch; I
> > > think the idea is sound, but the implementation isn't.  The comments
> > > at the top of get_type say that it's supposed to skip past typedefs,
> > > so calling CHECK_TYPEDEF certainly seems legitimate.  But
> > > CHECK_TYPEDEF calls check_typedef, which already goes through chains
> > > of typedefs, so you can get rid of the loop in get_type.
> > 
> > Yup, I think you are correct. I'm sure that I was just being laz^Whasty.
> > :-)
> 
> David's analysis sounds right to me.  I'll look over the actual code
> tomorrow, really I will...

I don't think David's conversions are quite right; close though. 
However, something here is fishy.

Compare:
/* This returns the type of the variable. This skips past typedefs
   and returns the real type of the variable. It also dereferences
   pointers and references.
vs.
static struct type *
get_type (struct varobj *var)
{ 
  struct type *type;
  type = var->type;

  while (type != NULL && TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
    type = TYPE_TARGET_TYPE (type);

  return type;
}

That doesn't dereference pointers and references!  It looks like
get_type got inserted between get_type_deref and its comments?  Can you
confirm that it shouldn't dereference?

Assuming get_type is not supposed to dereference pointers, then this
would work:

/* This returns the type of the variable. It also skips past typedefs
   to return the real type of the variable.

   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
   except within get_target_type and get_type. */
static struct type *
get_type (struct varobj *var)
{
  struct type *type;  
  type = var->type;

  if (type != NULL)
    type = check_typedef (type);

  return type;
}

/* This returns the target type (or NULL) of TYPE, also skipping
   past typedefs, just like get_type ().
  
   NOTE: TYPE_TARGET_TYPE should NOT be used anywhere in this file
   except within get_target_type and get_type. */
static struct type *
get_target_type (struct type *type)
{
  if (type != NULL) 
    {
      type = TYPE_TARGET_TYPE (type);
      type = check_typedef (type);
    }

  return type;
}

Test results for that look OK but I don't have insight built at the
moment, so I didn't test it.


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]