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