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


Forgot to cc: gdb-patches.  Patches checked in.  Details below.

-- Jeff J.
--- Begin Message ---
Elena Zannoni wrote:
> 
> Keith Seitz writes:
>  > [off list]
>  >
>  > On Mon, 21 Oct 2002, Elena Zannoni wrote:
>  >
>  > > How are the fields organized within the structure? I am a bit confused by the
>  > > decreasing 'i'.
>  >
>  > They are organized in the order they are output in the debug info.
>  > Originally, the code presumed that the debug info was ordered. I also have
>  > a version of this patch (which I sent to Jeff) which removes this
>  > bad assumption entirely.
>  >
>  > It runs through the code and computes the childrens' indices on the fly.
>  > It's not as efficient as this, but it does get rid of the bad assumption
>  > entirely.
>  >
>  > Keith
>  >
> 
> Yeah, I saw the rewrite of the patch after I sent this mail out, so
> disregard.  I think Fernando approved the new version, and I am only
> bitching about the streq's.
> :-)
> 
> Elena


I have changed the STREQs over and also added a test case to the gdb.mi
testsuite.  The code is checked in.  I have included the patches.  

gdb/ChangeLog:

2002-11-05  Jeff Johnston  <jjohnstn@redhat.com>

        * varobj.c (child_exists, cplus_number_of_children): Change
        STREQ macro references to strcmp.
        (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.



gdb/testsuite/gdb.mi/ChangeLog:

2002-11-05  Jeff Johnston  <jjohnstn@redhat.com>

        * gdb792.cc: New file to test patch for PR gdb/792.
        * gdb792.exp: Ditto.
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.33
diff -u -r1.33 varobj.c
--- varobj.c	23 Oct 2002 23:54:33 -0000	1.33
+++ varobj.c	5 Nov 2002 22:24:43 -0000
@@ -1203,7 +1203,7 @@
 
   for (vc = var->children; vc != NULL; vc = vc->next)
     {
-      if (STREQ (vc->child->name, name))
+      if (strcmp (vc->child->name, name) == 0)
 	return vc->child;
     }
 
@@ -2123,9 +2123,9 @@
       type = get_type_deref (var->parent);
 
       cplus_class_num_children (type, kids);
-      if (STREQ (var->name, "public"))
+      if (strcmp (var->name, "public") == 0)
 	children = kids[v_public];
-      else if (STREQ (var->name, "private"))
+      else if (strcmp (var->name, "private") == 0)
 	children = kids[v_private];
       else
 	children = kids[v_protected];
@@ -2176,7 +2176,6 @@
 {
   char *name;
   struct type *type;
-  int children[3];
 
   if (CPLUS_FAKE_CHILD (parent))
     {
@@ -2191,55 +2190,97 @@
     {
     case TYPE_CODE_STRUCT:
     case TYPE_CODE_UNION:
-      cplus_class_num_children (type, children);
-
       if (CPLUS_FAKE_CHILD (parent))
 	{
-	  int i;
-
-	  /* 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];
+	  /* The fields of the class type are ordered as they
+	     appear in the class.  We are given an index for a
+	     particular access control type ("public","protected",
+	     or "private").  We must skip over fields that don't
+	     have the access control we are looking for to properly
+	     find the indexed field. */
+	  int type_index = TYPE_N_BASECLASSES (type);
+	  if (strcmp (parent->name, "private") == 0)
+	    {
+	      while (index >= 0)
+		{
+	  	  if (TYPE_VPTR_BASETYPE (type) == type
+	      	      && type_index == TYPE_VPTR_FIELDNO (type))
+		    ; /* ignore vptr */
+		  else if (TYPE_FIELD_PRIVATE (type, type_index))
+		    --index;
+		  ++type_index;
+		}
+	      --type_index;
+	    }
+	  else if (strcmp (parent->name, "protected") == 0)
+	    {
+	      while (index >= 0)
+		{
+	  	  if (TYPE_VPTR_BASETYPE (type) == type
+	      	      && type_index == TYPE_VPTR_FIELDNO (type))
+		    ; /* ignore vptr */
+		  else if (TYPE_FIELD_PROTECTED (type, type_index))
+		    --index;
+		  ++type_index;
+		}
+	      --type_index;
+	    }
+	  else
+	    {
+	      while (index >= 0)
+		{
+	  	  if (TYPE_VPTR_BASETYPE (type) == type
+	      	      && type_index == TYPE_VPTR_FIELDNO (type))
+		    ; /* ignore vptr */
+		  else if (!TYPE_FIELD_PRIVATE (type, type_index) &&
+		      !TYPE_FIELD_PROTECTED (type, type_index))
+		    --index;
+		  ++type_index;
+		}
+	      --type_index;
+	    }
 
-	  name = TYPE_FIELD_NAME (type, i);
+	  name = TYPE_FIELD_NAME (type, type_index);
 	}
       else if (index < TYPE_N_BASECLASSES (type))
+	/* We are looking up the name of a base class */
 	name = TYPE_FIELD_NAME (type, index);
       else
 	{
+	  int children[3];
+	  cplus_class_num_children(type, children);
+
 	  /* Everything beyond the baseclasses can
-	     only be "public", "private", or "protected" */
+	     only be "public", "private", or "protected"
+
+	     The special "fake" children are always output by varobj in
+	     this order. So if INDEX == 2, it MUST be "protected". */
 	  index -= TYPE_N_BASECLASSES (type);
 	  switch (index)
 	    {
 	    case 0:
-	      if (children[v_public] != 0)
-		{
-		  name = "public";
-		  break;
-		}
+	      if (children[v_public] > 0)
+	 	name = "public";
+	      else if (children[v_private] > 0)
+	 	name = "private";
+	      else 
+	 	name = "protected";
+	      break;
 	    case 1:
-	      if (children[v_private] != 0)
+	      if (children[v_public] > 0)
 		{
-		  name = "private";
-		  break;
+		  if (children[v_private] > 0)
+		    name = "private";
+		  else
+		    name = "protected";
 		}
+	      else if (children[v_private] > 0)
+	 	name = "protected";
+	      break;
 	    case 2:
-	      if (children[v_protected] != 0)
-		{
-		  name = "protected";
-		  break;
-		}
+	      /* Must be protected */
+	      name = "protected";
+	      break;
 	    default:
 	      /* error! */
 	      break;
Index: gdb792.exp
===================================================================
RCS file: gdb792.exp
diff -N gdb792.exp
--- gdb792.exp	1 Jan 1970 00:00:00 -0000
+++ gdb792.exp	5 Nov 2002 22:23:43 -0000
@@ -0,0 +1,90 @@
+# Copyright 2002 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@prep.ai.mit.edu
+
+#
+# test gdb/792
+#
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+set testfile gdb792
+set srcfile "$testfile.cc"
+set binfile $objdir/$subdir/$testfile
+
+if [get_compiler_info ${binfile} "c++"] {
+    return -1;
+}
+
+if {[gdb_compile $srcdir/$subdir/$srcfile $binfile executable {debug c++}] != ""} {
+  gdb_suppress_entire_file "Testcase compile failed, so all test in this file will automatically fail."
+}
+
+# Test that children of classes are properly reported
+
+# Run to main
+mi_run_to_main
+
+mi_gdb_test "-var-create - * a" \
+  "(&\".*\"\r\n)*\\^done,name=\"var1\",numchild=\"3\",type=\"A\"" \
+  "create var for class A"
+
+mi_gdb_test "-var-list-children var1" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"3\",children=\{child=\{name=\"var1\.public\",exp=\"public\",numchild=\"2\"\},child=\{name=\"var1\.private\",exp=\"private\",numchild=\"2\"\},child=\{name=\"var1\.protected\",exp=\"protected\",numchild=\"2\"\}\}" \
+  "list children of class A"
+
+mi_gdb_test "-var-list-children var1.public" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"2\",children=\{child=\{name=\"var1\.public\.x\",exp=\"x\",numchild=\"0\",type=\"int\"\},child=\{name=\"var1\.public\.buffer\",exp=\"buffer\",numchild=\"10\",type=\"char \\\[10\\\]\"\}\}" \
+  "list children of A.public"
+
+mi_gdb_test "-var-list-children var1.private" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"2\",children=\{child=\{name=\"var1\.private\.u\",exp=\"u\",numchild=\"0\",type=\"int\"\},child=\{name=\"var1\.private\.z\",exp=\"z\",numchild=\"0\",type=\"float\"\}\}" \
+  "list children of A.private"
+
+mi_gdb_test "-var-list-children var1.protected" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"2\",children=\{child=\{name=\"var1\.protected\.y\",exp=\"y\",numchild=\"0\",type=\"int\"\},child=\{name=\"var1\.protected\.b\",exp=\"b\",numchild=\"2\",type=\"B\"\}\}" \
+  "list children of A.protected"
+
+mi_gdb_test "-var-list-children var1.protected.b" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"2\",children=\{child=\{name=\"var1\.protected\.b\.public\",exp=\"public\",numchild=\"2\"\},child=\{name=\"var1\.protected\.b\.private\",exp=\"private\",numchild=\"1\"\}\}" \
+  "list children of A.protected.b"
+
+mi_gdb_test "-var-list-children var1.protected.b.public" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"2\",children=\{child=\{name=\"var1\.protected\.b\.public\.bx\",exp=\"bx\",numchild=\"0\",type=\"int\"\},child=\{name=\"var1\.protected\.b\.public\.by\",exp=\"by\",numchild=\"0\",type=\"int\"\}\}" \
+  "list children of A.protected.b.public"
+
+mi_gdb_test "-var-list-children var1.protected.b.private" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"1\",children=\{child=\{name=\"var1\.protected\.b\.private\.k\",exp=\"k\",numchild=\"0\",type=\"int\"\}\}" \
+  "list children of A.protected.b.private"
+
+mi_gdb_test "-var-create - * c" \
+  "(&\".*\"\r\n)*\\^done,name=\"var2\",numchild=\"3\",type=\"C\"" \
+  "create var for class C which has baseclass A"
+
+mi_gdb_test "-var-list-children var2" \
+  "(&\".*\"\r\n)*\\^done,numchild=\"3\",children=\{child=\{name=\"var2\.A\",exp=\"A\",numchild=\"3\",type=\"A\"\},child=\{name=\"var2\.public\",exp=\"public\",numchild=\"1\"\},child=\{name=\"var2\.private\",exp=\"private\",numchild=\"1\"\}\}" \
+  "list children of class C"
+
+mi_gdb_exit
+return 0
Index: gdb792.cc
===================================================================
RCS file: gdb792.cc
diff -N gdb792.cc
--- gdb792.cc	1 Jan 1970 00:00:00 -0000
+++ gdb792.cc	5 Nov 2002 22:23:43 -0000
@@ -0,0 +1,59 @@
+#include <string.h>
+#include <stdio.h>
+
+class Q
+{
+	int v;
+	protected:
+		int qx;
+		int qy;
+	int w;
+};
+
+class B
+{
+	int k;
+	public:
+		int bx;
+		int by;
+};
+
+class A
+{
+	int u;
+
+	public:
+		A()
+		{
+		};
+		int x;
+		char buffer[10];
+	
+	protected:
+		int y;
+		B b;
+	
+	private:
+		float z;
+};
+
+class C : public A
+{
+	public:
+		C()
+		{
+		};
+		int zzzz;
+	private:
+		int ssss;
+};
+
+int main()
+{
+	A a;
+	C c;
+	Q q;
+	strcpy( a.buffer, "test" );
+	printf ( "%.10s\n", a.buffer );
+	return 0;
+}
--- End Message ---

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