1# Copyright 2013-2016 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This file is part of the gdb testsuite 17 18# Test expressions which assume an implicit "this" with a qualified 19# name. 20 21if {[skip_cplus_tests]} { continue } 22 23standard_testfile .cc 24 25if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { 26 return -1 27} 28 29# First test expressions when there is no context. 30with_test_prefix "before run" { 31 gdb_test "print i" "No symbol \"i\" in current context." 32 gdb_test "print D::i" "Cannot reference non-static field \"i\"" 33 gdb_test "print D::B<int>::i" "Cannot reference non-static field \"i\"" 34 gdb_test "print B<int>::i" "Cannot reference non-static field \"i\"" 35 gdb_test "print D::C::i" "Cannot reference non-static field \"i\"" 36 gdb_test "print C::i" "Cannot reference non-static field \"i\"" 37 gdb_test "print D::B<int>::A<int>::i" \ 38 "Cannot reference non-static field \"i\"" 39 gdb_test "print B<int>::A<int>::i" "Cannot reference non-static field \"i\"" 40 gdb_test "print A<int>::i" "Cannot reference non-static field \"i\"" 41 gdb_test "print D::C::A<int>::i" "Cannot reference non-static field \"i\"" 42 gdb_test "print C::A<int>::i" "Cannot reference non-static field \"i\"" 43 gdb_test "print D::x" "Cannot reference non-static field \"x\"" 44 gdb_test "print x" "No symbol \"x\" in current context." 45 gdb_test "print D::C::c" "Cannot reference non-static field \"c\"" 46 gdb_test "print C::c" "Cannot reference non-static field \"c\"" 47 gdb_test "print c" "No symbol \"c\" in current context." 48 gdb_test "print D::A<int>::i" "Cannot reference non-static field \"i\"" 49} 50 51# Run to D::f. 52if {![runto_main]} { 53 perror "couldn't run to main" 54 continue 55} 56 57gdb_breakpoint "D::f" 58gdb_continue_to_breakpoint "continue to D::f" 59 60# Now test valid expressions in the class hierarchy for D. 61with_test_prefix "at D::f (valid expressions)" { 62 gdb_test "print i" "= 4" 63 gdb_test "print D::i" "= 4" 64 gdb_test "print D::B<int>::i" "= 2" 65 gdb_test "print B<int>::i" "= 2" 66 gdb_test "print D::Bint::i" \ 67 "No type \"Bint\" within class or namespace \"D\"." 68 gdb_test "print Bint::i" "= 2" 69 gdb_test "print D::C::i" "= 3" 70 gdb_test "print C::i" "= 3" 71 gdb_test "print D::B<int>::A<int>::i" "= 1" 72 gdb_test "print B<int>::A<int>::i" "= 1" 73 gdb_test "print D::Bint::A<int>::i" \ 74 "No type \"Bint\" within class or namespace \"D\"." 75 gdb_test "print Bint::A<int>::i" "= 1" 76 gdb_test "print A<int>::i" "= 1" 77 gdb_test "print D::C::A<int>::i" "= 1" 78 gdb_test "print C::A<int>::i" "= 1" 79 gdb_test "print D::x" "= 40" 80 gdb_test "print x" "= 40" 81 gdb_test "print D::C::c" "= 30" 82 gdb_test "print C::c" "= 30" 83 gdb_test "print c" "= 30" 84 gdb_test "print D::A<int>::i" "= 1" 85} 86 87# Test some invalid expressions 88with_test_prefix "at D::f (invalid expressions)" { 89 gdb_test "print D::B<int>::c" "There is no field named c" 90 gdb_test "print D::B<int>::A<int>::c" "There is no field named c" 91 gdb_test "print D::Bint::c" \ 92 "No type \"Bint\" within class or namespace \"D\"." 93 94 gdb_test "print D::Bint::A<int>::c" \ 95 "No type \"Bint\" within class or namespace \"D\"." 96 gdb_test "print D::C::A<int>::c" "There is no field named c" 97 gdb_test "print B<int>::c" "There is no field named c" 98 gdb_test "print B<int>::A<int>::c" "There is no field named c" 99 gdb_test "print Bint::c" "There is no field named c" 100 gdb_test "print Bint::A<int>::c" "There is no field named c" 101 gdb_test "print C::A<int>::c" "There is no field named c" 102 gdb_test "print D::B<int>::x" "There is no field named x" 103 gdb_test "print D::B<int>::A<int>::x" "There is no field named x" 104 gdb_test "print D::Bint::x" \ 105 "No type \"Bint\" within class or namespace \"D\"." 106 gdb_test "print D::Bint::A<int>::x" \ 107 "No type \"Bint\" within class or namespace \"D\"." 108 gdb_test "print B<int>::x" "There is no field named x" 109 gdb_test "print B<int>::A<int>::x" "There is no field named x" 110 gdb_test "print Bint::x" "There is no field named x" 111 gdb_test "print Bint::A<int>::x" "There is no field named x" 112 gdb_test "print D::C::x" "There is no field named x" 113 gdb_test "print C::x" "There is no field named x" 114 gdb_test "print D::C::A<int>::x" "There is no field named x" 115 gdb_test "print C::A<int>::x" "There is no field named x" 116} 117 118# Test some ambiguous names 119with_test_prefix "at D::f (ambiguous names)" { 120 gdb_test "print B<int>::common" " = 200" 121 gdb_test "print Bint::common" " = 200" 122 gdb_test "print C::common" " = 300" 123 gdb_test "print am.i" " = 1000" 124 gdb_test "print am.A<int>::i" \ 125 "base class 'A<int>' is ambiguous in type 'Ambig'" 126 gdb_test "print am.BB::A<int>::i" \ 127 "base class 'A<int>' is ambiguous in type 'Ambig'" 128 gdb_test "print am.CC::A<int>::i" \ 129 "base class 'A<int>' is ambiguous in type 'Ambig'" 130} 131