1 # Copyright 2018-2019 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Make sure printing virtual base class data member works correctly (PR16841)
18 if { [skip_cplus_tests] } { continue }
22 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
26 if {![runto_main]} then {
27 perror "couldn't run to main"
31 # From a list of nested scopes, generate all possible ways of accessing something
32 # in those scopes. For example, with the argument {foo bar baz}, this proc will
43 proc make_scope_list { scopes } {
44 if { [llength $scopes] == 1 } {
45 return [list "" "${scopes}::"]
48 # Pop the first element, save the first scope.
49 set this_scope [lindex $scopes 0]
50 set scopes [lreplace $scopes 0 0]
52 set child_result [make_scope_list $scopes]
54 # Add a copy of the child's result without this scope...
55 set result $child_result
57 # ... and a copy of the child's result with this scope.
58 foreach r $child_result {
59 lappend result "${this_scope}::$r"
65 proc test_variables_in_base { scopes } {
66 foreach scope [make_scope_list $scopes] {
67 gdb_test "print ${scope}i" " = 55"
68 gdb_test "print ${scope}d" " = 6.25"
69 gdb_test "print ${scope}x" " = 22"
73 proc test_variables_in_superbase { scopes } {
74 foreach scope [make_scope_list $scopes] {
75 gdb_test "print ${scope}x" " = 22"
79 proc test_variables_in_super { scopes } {
80 foreach scope [make_scope_list $scopes] {
81 gdb_test "print ${scope}w" " = 17"
85 with_test_prefix "derived::func_d" {
86 gdb_breakpoint "derived::func_d"
87 gdb_continue_to_breakpoint "continue to derived::func_d"
88 test_variables_in_base {derived base}
89 test_variables_in_superbase {derived base superbase}
90 test_variables_in_superbase {base superbase}
91 test_variables_in_superbase {derived superbase}
92 test_variables_in_superbase {superbase}
93 test_variables_in_superbase {base}
94 test_variables_in_super {super}
95 test_variables_in_super {derived super}
98 with_test_prefix "foo::func_f" {
99 gdb_breakpoint "foo::func_f"
100 gdb_continue_to_breakpoint "continue to foo::func_f"
101 test_variables_in_base {foo derived base}
102 test_variables_in_base {foo base}
103 test_variables_in_base {base}
104 test_variables_in_superbase {superbase}
105 test_variables_in_superbase {foo superbase}
106 test_variables_in_superbase {foo derived superbase}
107 test_variables_in_superbase {foo derived base superbase}
108 test_variables_in_super {super}
109 test_variables_in_super {foo super}
110 test_variables_in_super {foo derived super}