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: Patch for gdb/mi 792


J. Johnston writes:
 > The following is a proposed patch for gdb/mi 792.  The problem occurs because
 > the code is trying to reference public, private, and protected via indexes.
 > The order of the fields in the type are in the order they are entered so the
 > index cannot be used computationally.  The new code takes the index and
 > does a loop through the fields verifying that the field has the desired
 > access control.  It decrements the index until the desired indexed value
 > with the specified access is found.
 > 
 > gdb/ChangeLog:
 > 
 > 2002-10-11  Jeff Johnston  <jjohnstn@redhat.com>
 > 
 > 	* varobj.c (cplus_name_of_child): Change code to handle the fact that
 > 	fields are not necessarily contiguous with regards to their access control.
 > 	This is a fix for PR gdb/792.
 > 
 > May this code be committed?
 > 
 > -- Jeff J.--- varobj.0.c	Fri Oct 11 15:46:03 2002
 > +++ varobj.c	Fri Oct 11 18:28:06 2002
 > @@ -2195,23 +2195,49 @@
 >  
 >        if (CPLUS_FAKE_CHILD (parent))
 >  	{
 > -	  int i;
 > +	  int i = index;
 >  
 >  	  /* Skip over vptr, if it exists. */
 >  	  if (TYPE_VPTR_BASETYPE (type) == type
 >  	      && index >= TYPE_VPTR_FIELDNO (type))
 >  	    index++;
 >  
 > -	  /* FIXME: This assumes that type orders
 > -	     inherited, public, private, protected */
 > -	  i = index + TYPE_N_BASECLASSES (type);
 > -	  if (STREQ (parent->name, "private")
 > -	      || STREQ (parent->name, "protected"))
 > -	    i += children[v_public];
 > -	  if (STREQ (parent->name, "protected"))
 > -	    i += children[v_private];
 > +	  index = TYPE_N_BASECLASSES (type);
 > +	  if (STREQ (parent->name, "private"))

Argh!! STREQ! Run away! We are trying to kill STREQ from gdb, you
should just use strcmp().
[BTW, you know about the ARI? very useful, http://sources.redhat.com/gdb/ari/]



 > +	    {
 > +	      while (i >= 0)
 > +		{
 > +		  if (TYPE_FIELD_PRIVATE (type, index))
 > +		    --i;
 > +		  ++index;
 > +		}
 > +	      --index;
 > +	    }
 > +

How are the fields organized within the structure? I am a bit confused by the
decreasing 'i'.

Elena


	  else if (STREQ (parent->name, "protected"))
 > +	    {
 > +	      while (i >= 0)
 > +		{
 > +		  if (TYPE_FIELD_PROTECTED (type, index))
 > +		    --i;
 > +		  ++index;
 > +		}
 > +	      --index;
 > +	    }
 > +	  else if (STREQ (parent->name, "public"))
 > +	    {
 > +	      while (i >= 0)
 > +		{
 > +		  if (!TYPE_FIELD_PRIVATE (type, index) &&
 > +		      !TYPE_FIELD_PROTECTED (type, index))
 > +		    --i;
 > +		  ++index;
 > +		}
 > +	      --index;
 > +	    }
 > +	  else
 > +	    index += i;
 >  
 > -	  name = TYPE_FIELD_NAME (type, i);
 > +	  name = TYPE_FIELD_NAME (type, index);
 >  	}
 >        else if (index < TYPE_N_BASECLASSES (type))
 >  	name = TYPE_FIELD_NAME (type, index);


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