This is the mail archive of the gdb-patches@sourceware.org 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]

MI: fix base members in references


A KDevelop user reported the following bug. If you have C++ reference variable 
that refers to a class type, and that class has bases, gdb is not able to 
show the values of any fields of bases. The trimmed down example is this:

	struct S { int i; int j; };
	struct S2 : S {};
	
	int foo(S2& s)
	{
		return s.i;
	}
	
	int main()
	{
		S2 s;
		s.i = 1;
		s.j = 2;
		return foo(s);
	}

If you are in 'foo' and try to create MI variable objects for s, and navigate 
it, the varobjs for 'i' and 'j' members of the base class will have no value.

The problem happens when creating varobj for the base object. MI sees that 
it's reference and tries to pass it via value_ind. The latter immediately 
removes top-level reference and rightly refuses to deference a structure.

MI should just do nothing about references -- the value_cast function used to
obtain base handles references just fine.

The attached patch fixed the problem, no regression. I'll write a testcase for 
it as soon as my previous references patch is reviewed -- I don't want to 
pile too many testcases in as-yet-uncommitted file.

OK?

If this patch is fine, can I also commit it to 6.6 branch? The bug in question 
is quite problematic for C++ code.

- Volodya



Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.62
diff -u -p -r1.62 varobj.c
--- varobj.c	29 Nov 2006 06:41:13 -0000	1.62
+++ varobj.c	29 Nov 2006 12:51:53 -0000
@@ -2428,8 +2428,9 @@ cplus_value_of_child (struct varobj *par
 	    {
 	      struct value *temp = NULL;
 
+	      /* No special processing for references is needed --
+		 value_cast below handles references.  */
 	      if (TYPE_CODE (value_type (parent->value)) == TYPE_CODE_PTR
-		  || TYPE_CODE (value_type (parent->value)) == TYPE_CODE_REF)
 		{
 		  if (!gdb_value_ind (parent->value, &temp))
 		    return NULL;

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