Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / virtbase2.exp
CommitLineData
88b9d363 1# Copyright 2018-2022 Free Software Foundation, Inc.
9f6b697b
WP
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# Make sure printing virtual base class data member works correctly (PR16841)
17
18if { [skip_cplus_tests] } { continue }
19
20standard_testfile .cc
21
22if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
23 return -1
24}
25
26if {![runto_main]} then {
27 perror "couldn't run to main"
28 continue
29}
30
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
33# return:
34# - {} (empty string)
35# - baz::
36# - bar::
37# - bar::baz::
38# - foo::
39# - foo::baz::
40# - foo::bar::
41# - foo::bar::baz::
42
43proc make_scope_list { scopes } {
44 if { [llength $scopes] == 1 } {
45 return [list "" "${scopes}::"]
46 }
47
48 # Pop the first element, save the first scope.
49 set this_scope [lindex $scopes 0]
50 set scopes [lreplace $scopes 0 0]
51
52 set child_result [make_scope_list $scopes]
53
54 # Add a copy of the child's result without this scope...
55 set result $child_result
56
57 # ... and a copy of the child's result with this scope.
58 foreach r $child_result {
59 lappend result "${this_scope}::$r"
60 }
61
62 return $result
63}
64
65proc test_variables_in_base { scopes } {
c2b75043
LM
66 with_test_prefix "$scopes" {
67 foreach scope [make_scope_list $scopes] {
68 gdb_test "print ${scope}i" " = 55"
69 gdb_test "print ${scope}d" " = 6.25"
70 gdb_test "print ${scope}x" " = 22"
71 }
72 }
9f6b697b
WP
73}
74
75proc test_variables_in_superbase { scopes } {
c2b75043
LM
76 with_test_prefix "$scopes" {
77 foreach scope [make_scope_list $scopes] {
78 gdb_test "print ${scope}x" " = 22"
79 }
80 }
9f6b697b
WP
81}
82
83proc test_variables_in_super { scopes } {
c2b75043
LM
84 with_test_prefix "$scopes" {
85 foreach scope [make_scope_list $scopes] {
86 gdb_test "print ${scope}w" " = 17"
87 }
88 }
9f6b697b
WP
89}
90
91with_test_prefix "derived::func_d" {
92 gdb_breakpoint "derived::func_d"
93 gdb_continue_to_breakpoint "continue to derived::func_d"
94 test_variables_in_base {derived base}
95 test_variables_in_superbase {derived base superbase}
96 test_variables_in_superbase {base superbase}
97 test_variables_in_superbase {derived superbase}
98 test_variables_in_superbase {superbase}
99 test_variables_in_superbase {base}
100 test_variables_in_super {super}
101 test_variables_in_super {derived super}
102}
103
104with_test_prefix "foo::func_f" {
105 gdb_breakpoint "foo::func_f"
106 gdb_continue_to_breakpoint "continue to foo::func_f"
107 test_variables_in_base {foo derived base}
108 test_variables_in_base {foo base}
109 test_variables_in_base {base}
110 test_variables_in_superbase {superbase}
111 test_variables_in_superbase {foo superbase}
112 test_variables_in_superbase {foo derived superbase}
113 test_variables_in_superbase {foo derived base superbase}
114 test_variables_in_super {super}
115 test_variables_in_super {foo super}
116 test_variables_in_super {foo derived super}
117}
This page took 0.442013 seconds and 4 git commands to generate.