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