| 1 | # Copyright 2008-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 | # Test that when multiple variables have the same |
| 17 | # name the one from the correct scope is printed. |
| 18 | |
| 19 | |
| 20 | standard_testfile .cc |
| 21 | |
| 22 | if [get_compiler_info] { |
| 23 | return -1 |
| 24 | } |
| 25 | |
| 26 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { |
| 27 | return -1 |
| 28 | } |
| 29 | |
| 30 | if ![runto_main] then { |
| 31 | perror "couldn't run to breakpoint main" |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | ############################################ |
| 36 | # Test printing of class variable is not shadowed |
| 37 | # by global variable |
| 38 | |
| 39 | gdb_breakpoint [gdb_get_line_number "marker1"] |
| 40 | gdb_continue_to_breakpoint "marker1" |
| 41 | |
| 42 | gdb_test "print x" "= 33" "Print class x shadowing global x" |
| 43 | |
| 44 | |
| 45 | ############################################ |
| 46 | # Test printing local variable is not shadowed |
| 47 | # by class variable |
| 48 | |
| 49 | gdb_breakpoint [gdb_get_line_number "marker2"] |
| 50 | gdb_continue_to_breakpoint "marker2" |
| 51 | |
| 52 | gdb_test "print x" "= 44" "Print local x shadowing class x" |
| 53 | |
| 54 | ############################################ |
| 55 | # Test inner scope x is printed not outer scope |
| 56 | |
| 57 | gdb_breakpoint [gdb_get_line_number "marker3"] |
| 58 | gdb_continue_to_breakpoint "marker3" |
| 59 | |
| 60 | gdb_test "print x" "= 55" "Print inner scope x" |
| 61 | |
| 62 | ############################################ |
| 63 | # Test printing local variable is not shadowed |
| 64 | # by namespace variable |
| 65 | |
| 66 | gdb_breakpoint [gdb_get_line_number "marker4"] |
| 67 | gdb_continue_to_breakpoint "marker4" |
| 68 | |
| 69 | gdb_test "print x" "= 55" "Print local x not namespace x" |
| 70 | |
| 71 | ############################################ |
| 72 | # Test imported namespace element is printed |
| 73 | |
| 74 | gdb_breakpoint [gdb_get_line_number "marker5"] |
| 75 | gdb_continue_to_breakpoint "marker5" |
| 76 | |
| 77 | if { [test_compiler_info {gcc-[0-3]-*}] || |
| 78 | [test_compiler_info {gcc-4-[0-3]-*}]} { |
| 79 | setup_xfail *-*-* |
| 80 | } |
| 81 | |
| 82 | gdb_test "print x" "= 11" "Print imported namespace x" |