Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.cp / virtbase2.exp
blob6e7336d8d04244dbd2550c507fca02c70d979b3b
1 # Copyright 2018-2024 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 require allow_cplus_tests
20 standard_testfile .cc
22 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
23     return -1
26 if {![runto_main]} {
27     return
30 # From a list of nested scopes, generate all possible ways of accessing something
31 # in those scopes.  For example, with the argument {foo bar baz}, this proc will
32 # return:
33 #  - {} (empty string)
34 #  - baz::
35 #  - bar::
36 #  - bar::baz::
37 #  - foo::
38 #  - foo::baz::
39 #  - foo::bar::
40 #  - foo::bar::baz::
42 proc make_scope_list { scopes } {
43     if { [llength $scopes] == 1 } {
44         return [list "" "${scopes}::"]
45     }
47     # Pop the first element, save the first scope.
48     set this_scope [lindex $scopes 0]
49     set scopes [lreplace $scopes 0 0]
51     set child_result [make_scope_list $scopes]
53     # Add a copy of the child's result without this scope...
54     set result $child_result
56     # ... and a copy of the child's result with this scope.
57     foreach r $child_result {
58         lappend result "${this_scope}::$r"
59     }
61     return $result
64 proc test_variables_in_base { scopes } {
65   with_test_prefix "$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"
70       }
71   }
74 proc test_variables_in_superbase { scopes } {
75   with_test_prefix "$scopes" {
76       foreach scope [make_scope_list $scopes] {
77           gdb_test "print ${scope}x" " = 22"
78       }
79   }
82 proc test_variables_in_super { scopes } {
83   with_test_prefix "$scopes" {
84       foreach scope [make_scope_list $scopes] {
85           gdb_test "print ${scope}w" " = 17"
86       }
87   }
90 with_test_prefix "derived::func_d" {
91     gdb_breakpoint "derived::func_d"
92     gdb_continue_to_breakpoint "continue to derived::func_d"
93     test_variables_in_base {derived base}
94     test_variables_in_superbase {derived base superbase}
95     test_variables_in_superbase {base superbase}
96     test_variables_in_superbase {derived superbase}
97     test_variables_in_superbase {superbase}
98     test_variables_in_superbase {base}
99     test_variables_in_super {super}
100     test_variables_in_super {derived super}
103 with_test_prefix "foo::func_f" {
104     gdb_breakpoint "foo::func_f"
105     gdb_continue_to_breakpoint "continue to foo::func_f"
106     test_variables_in_base {foo derived base}
107     test_variables_in_base {foo base}
108     test_variables_in_base {base}
109     test_variables_in_superbase {superbase}
110     test_variables_in_superbase {foo superbase}
111     test_variables_in_superbase {foo derived superbase}
112     test_variables_in_superbase {foo derived base superbase}
113     test_variables_in_super {super}
114     test_variables_in_super {foo super}
115     test_variables_in_super {foo derived super}