Blame SOURCES/gdb-implicit-this.patch

2c2fa1
Index: gdb-7.6.1/gdb/c-exp.y
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/c-exp.y	2013-11-09 17:29:19.336729300 +0100
2c2fa1
+++ gdb-7.6.1/gdb/c-exp.y	2013-11-09 17:29:21.935727454 +0100
2c2fa1
@@ -2890,6 +2890,30 @@ classify_inner_name (const struct block
2c2fa1
     {
2c2fa1
     case LOC_BLOCK:
2c2fa1
     case LOC_LABEL:
2c2fa1
+      {
2c2fa1
+	struct field_of_this_result fot;
2c2fa1
+
2c2fa1
+	/* We might have erroneously found a constructor where we wanted
2c2fa1
+	   a type name.  The trick is ascertaining what the user wanted.
2c2fa1
+	   If cp_lookup_nested_symbol found a constructor, but it is for a
2c2fa1
+	   different type than CONTEXT, then this is really a type, not a
2c2fa1
+	   constructor.  Look for the type and return that.  */
2c2fa1
+	memset (&fot, 0, sizeof (fot));
2c2fa1
+	check_field (type, copy, &fot;;
2c2fa1
+	if (fot.fn_field != NULL
2c2fa1
+	    && TYPE_FN_FIELD_CONSTRUCTOR (fot.fn_field->fn_fields, 0)
2c2fa1
+	    && !types_equal (type, fot.type))
2c2fa1
+	  {
2c2fa1
+	    struct symbol *sym;
2c2fa1
+
2c2fa1
+	    sym = lookup_symbol (copy, block, STRUCT_DOMAIN, NULL);
2c2fa1
+	    if (sym != NULL)
2c2fa1
+	      {
2c2fa1
+		yylval.tsym.type = SYMBOL_TYPE (sym);
2c2fa1
+		return TYPENAME;
2c2fa1
+	      }
2c2fa1
+	  }
2c2fa1
+      }
2c2fa1
       return ERROR;
2c2fa1
 
2c2fa1
     case LOC_TYPEDEF:
2c2fa1
Index: gdb-7.6.1/gdb/symtab.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/symtab.c	2013-11-09 17:29:19.338729298 +0100
2c2fa1
+++ gdb-7.6.1/gdb/symtab.c	2013-11-09 17:29:21.936727453 +0100
2c2fa1
@@ -1260,7 +1260,7 @@ lookup_language_this (const struct langu
2c2fa1
    return 1 if the component named NAME from the ultimate target
2c2fa1
    structure/union is defined, otherwise, return 0.  */
2c2fa1
 
2c2fa1
-static int
2c2fa1
+int
2c2fa1
 check_field (struct type *type, const char *name,
2c2fa1
 	     struct field_of_this_result *is_a_field_of_this)
2c2fa1
 {
2c2fa1
Index: gdb-7.6.1/gdb/symtab.h
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/symtab.h	2013-11-09 17:29:19.339729298 +0100
2c2fa1
+++ gdb-7.6.1/gdb/symtab.h	2013-11-09 17:27:11.329820268 +0100
2c2fa1
@@ -1318,4 +1318,9 @@ void iterate_over_symbols (const struct
2c2fa1
 struct cleanup *demangle_for_lookup (const char *name, enum language lang,
2c2fa1
 				     const char **result_name);
2c2fa1
 
2c2fa1
+/* See comment in symtab.c.  */
2c2fa1
+
2c2fa1
+int check_field (struct type *type, const char *name,
2c2fa1
+		 struct field_of_this_result *is_a_field_of_this);
2c2fa1
+
2c2fa1
 #endif /* !defined(SYMTAB_H) */
2c2fa1
Index: gdb-7.6.1/gdb/valops.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/valops.c	2013-11-09 17:29:19.340729297 +0100
2c2fa1
+++ gdb-7.6.1/gdb/valops.c	2013-11-09 17:28:02.417784136 +0100
2c2fa1
@@ -3401,10 +3401,35 @@ value_struct_elt_for_reference (struct t
2c2fa1
 	    return value_from_longest
2c2fa1
 	      (lookup_memberptr_type (TYPE_FIELD_TYPE (t, i), domain),
2c2fa1
 	       offset + (TYPE_FIELD_BITPOS (t, i) >> 3));
2c2fa1
-	  else if (noside == EVAL_AVOID_SIDE_EFFECTS)
2c2fa1
+	  else if (noside != EVAL_NORMAL)
2c2fa1
 	    return allocate_value (TYPE_FIELD_TYPE (t, i));
2c2fa1
 	  else
2c2fa1
-	    error (_("Cannot reference non-static field \"%s\""), name);
2c2fa1
+	    {
2c2fa1
+	      /* Try to evaluate NAME as a qualified name with implicit
2c2fa1
+		 this pointer.  In this case, attempt to return the
2c2fa1
+		 equivalent to `this->*(&TYPE::NAME)'.  */
2c2fa1
+	      v = value_of_this_silent (current_language);
2c2fa1
+	      if (v != NULL)
2c2fa1
+		{
2c2fa1
+		  struct value *ptr;
2c2fa1
+		  long mem_offset;
2c2fa1
+		  struct type *type, *tmp;
2c2fa1
+
2c2fa1
+		  ptr = value_aggregate_elt (domain, name, NULL, 1, noside);
2c2fa1
+		  type = check_typedef (value_type (ptr));
2c2fa1
+		  gdb_assert (type != NULL
2c2fa1
+			      && TYPE_CODE (type) == TYPE_CODE_MEMBERPTR);
2c2fa1
+		  tmp = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
2c2fa1
+		  v = value_cast_pointers (tmp, v, 1);
2c2fa1
+		  mem_offset = value_as_long (ptr);
2c2fa1
+		  tmp = lookup_pointer_type (TYPE_TARGET_TYPE (type));
2c2fa1
+		  result = value_from_pointer (tmp,
2c2fa1
+					       value_as_long (v) + mem_offset);
2c2fa1
+		  return value_ind (result);
2c2fa1
+		}
2c2fa1
+
2c2fa1
+	      error (_("Cannot reference non-static field \"%s\""), name);
2c2fa1
+	    }
2c2fa1
 	}
2c2fa1
     }
2c2fa1
 
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.cc
2c2fa1
===================================================================
2c2fa1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.cc	2013-11-09 17:29:21.938727452 +0100
2c2fa1
@@ -0,0 +1,96 @@
2c2fa1
+/* This testcase is part of GDB, the GNU debugger.
2c2fa1
+
2c2fa1
+   Copyright 2013 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+   This program is free software; you can redistribute it and/or modify
2c2fa1
+   it under the terms of the GNU General Public License as published by
2c2fa1
+   the Free Software Foundation; either version 3 of the License, or
2c2fa1
+   (at your option) any later version.
2c2fa1
+
2c2fa1
+   This program is distributed in the hope that it will be useful,
2c2fa1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+   GNU General Public License for more details.
2c2fa1
+
2c2fa1
+   You should have received a copy of the GNU General Public License
2c2fa1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2c2fa1
+
2c2fa1
+#ifdef DEBUG
2c2fa1
+#include <stdio.h>
2c2fa1
+#endif
2c2fa1
+
2c2fa1
+class A
2c2fa1
+{
2c2fa1
+public:
2c2fa1
+  int i;
2c2fa1
+  int z;
2c2fa1
+  A () : i (1), z (10) {}
2c2fa1
+};
2c2fa1
+
2c2fa1
+class B : public virtual A
2c2fa1
+{
2c2fa1
+public:
2c2fa1
+  int i;
2c2fa1
+  B () : i (2) {}
2c2fa1
+};
2c2fa1
+
2c2fa1
+class C : public virtual A
2c2fa1
+{
2c2fa1
+public:
2c2fa1
+  int i;
2c2fa1
+  int c;
2c2fa1
+  C () : i (3), c (30) {}
2c2fa1
+};
2c2fa1
+
2c2fa1
+class D : public B, public C
2c2fa1
+{
2c2fa1
+public:
2c2fa1
+  int i;
2c2fa1
+  int x;
2c2fa1
+  D () : i (4), x (40) {}
2c2fa1
+
2c2fa1
+#ifdef DEBUG
2c2fa1
+#define SUM(X)					\
2c2fa1
+  do						\
2c2fa1
+    {						\
2c2fa1
+      sum += (X);				\
2c2fa1
+      printf ("" #X " = %d\n", (X));		\
2c2fa1
+    }						\
2c2fa1
+  while (0)
2c2fa1
+#else
2c2fa1
+#define SUM(X) sum += (X)
2c2fa1
+#endif
2c2fa1
+
2c2fa1
+int
2c2fa1
+f (void)
2c2fa1
+  {
2c2fa1
+    int sum = 0;
2c2fa1
+
2c2fa1
+    SUM (i);
2c2fa1
+    SUM (D::i);
2c2fa1
+    SUM (D::B::i);
2c2fa1
+    SUM (B::i);
2c2fa1
+    SUM (D::C::i);
2c2fa1
+    SUM (C::i);
2c2fa1
+    SUM (D::B::A::i);
2c2fa1
+    SUM (B::A::i);
2c2fa1
+    SUM (A::i);
2c2fa1
+    SUM (D::C::A::i);
2c2fa1
+    SUM (C::A::i);
2c2fa1
+    SUM (D::x);
2c2fa1
+    SUM (x);
2c2fa1
+    SUM (D::C::c);
2c2fa1
+    SUM (C::c);
2c2fa1
+    SUM (c);
2c2fa1
+
2c2fa1
+    return sum;
2c2fa1
+  }
2c2fa1
+};
2c2fa1
+
2c2fa1
+int
2c2fa1
+main (void)
2c2fa1
+{
2c2fa1
+  D d;
2c2fa1
+
2c2fa1
+  return d.f ();
2c2fa1
+}
2c2fa1
Index: gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.exp
2c2fa1
===================================================================
2c2fa1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
2c2fa1
+++ gdb-7.6.1/gdb/testsuite/gdb.cp/impl-this.exp	2013-11-09 17:29:21.939727451 +0100
2c2fa1
@@ -0,0 +1,89 @@
2c2fa1
+# Copyright 2013 Free Software Foundation, Inc.
2c2fa1
+
2c2fa1
+# This program is free software; you can redistribute it and/or modify
2c2fa1
+# it under the terms of the GNU General Public License as published by
2c2fa1
+# the Free Software Foundation; either version 3 of the License, or
2c2fa1
+# (at your option) any later version.
2c2fa1
+#
2c2fa1
+# This program is distributed in the hope that it will be useful,
2c2fa1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2c2fa1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c2fa1
+# GNU General Public License for more details.
2c2fa1
+#
2c2fa1
+# You should have received a copy of the GNU General Public License
2c2fa1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2c2fa1
+
2c2fa1
+# This file is part of the gdb testsuite
2c2fa1
+
2c2fa1
+# Test expressions which assume an implicit "this" with a qualified
2c2fa1
+# name.
2c2fa1
+
2c2fa1
+if {[skip_cplus_tests]} { continue }
2c2fa1
+
2c2fa1
+standard_testfile .cc
2c2fa1
+
2c2fa1
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
2c2fa1
+    return -1
2c2fa1
+}
2c2fa1
+
2c2fa1
+# First test expressions when there is no context.
2c2fa1
+gdb_test "print i" "No symbol \"i\" in current context."
2c2fa1
+gdb_test "print D::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print D::B::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print B::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print D::C::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print C::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print D::B::A::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print B::A::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print A::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print D::C::A::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print C::A::i" "Cannot reference non-static field \"i\""
2c2fa1
+gdb_test "print D::x" "Cannot reference non-static field \"x\""
2c2fa1
+gdb_test "print x" "No symbol \"x\" in current context."
2c2fa1
+gdb_test "print D::C::c" "Cannot reference non-static field \"c\""
2c2fa1
+gdb_test "print C::c" "Cannot reference non-static field \"c\""
2c2fa1
+gdb_test "print c" "No symbol \"c\" in current context."
2c2fa1
+
2c2fa1
+# Run to D::f.
2c2fa1
+if {![runto_main]} {
2c2fa1
+    perror "couldn't run to main"
2c2fa1
+    continue
2c2fa1
+}
2c2fa1
+
2c2fa1
+gdb_breakpoint "D::f"
2c2fa1
+gdb_continue_to_breakpoint "run to D::f"
2c2fa1
+
2c2fa1
+# Now test valid expressions in the class hierarchy for D.
2c2fa1
+gdb_test "print i" "= 4"
2c2fa1
+gdb_test "print D::i" "= 4"
2c2fa1
+gdb_test "print D::B::i" "= 2"
2c2fa1
+gdb_test "print B::i" "= 2"
2c2fa1
+gdb_test "print D::C::i" "= 3"
2c2fa1
+gdb_test "print C::i" "= 3"
2c2fa1
+gdb_test "print D::B::A::i" "= 1"
2c2fa1
+gdb_test "print B::A::i" "= 1"
2c2fa1
+gdb_test "print A::i" "= 1"
2c2fa1
+gdb_test "print D::C::A::i" "= 1"
2c2fa1
+gdb_test "print C::A::i" "= 1"
2c2fa1
+gdb_test "print D::x" "= 40"
2c2fa1
+gdb_test "print x" "= 40"
2c2fa1
+gdb_test "print D::C::c" "= 30"
2c2fa1
+gdb_test "print C::c" "= 30"
2c2fa1
+gdb_test "print c" "= 30"
2c2fa1
+
2c2fa1
+# Test some invalid expressions
2c2fa1
+gdb_test "print D::B::c" "There is no field named c"
2c2fa1
+gdb_test "print D::B::A::c" "There is no field named c"
2c2fa1
+gdb_test "print D::C::A::c" "There is no field named c"
2c2fa1
+gdb_test "print B::c" "There is no field named c"
2c2fa1
+gdb_test "print B::A::c" "There is no field named c"
2c2fa1
+gdb_test "print C::A::c" "There is no field named c"
2c2fa1
+gdb_test "print D::B::x" "There is no field named x"
2c2fa1
+gdb_test "print D::B::A::x" "There is no field named x"
2c2fa1
+gdb_test "print B::x" "There is no field named x"
2c2fa1
+gdb_test "print B::A::x" "There is no field named x"
2c2fa1
+gdb_test "print D::C::x" "There is no field named x"
2c2fa1
+gdb_test "print C::x" "There is no field named x"
2c2fa1
+gdb_test "print D::C::A::x" "There is no field named x"
2c2fa1
+gdb_test "print C::A::x" "There is no field named x"
2c2fa1
+