]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/local-static.exp
Handle "p 'S::method()::static_var'" (quoted) in symbol lookup
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / local-static.exp
CommitLineData
858be34c
PA
1# Copyright 2017 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# Tests for function local static variables, both C and C++.
17
18# This file is part of the gdb testsuite.
19
20standard_testfile .c
21
22# A list of scopes that have the static variables that we want to
23# print. Each entry has, in order, the scope/function name, and the
24# prefix used by the static variables. (The prefix exists to make it
25# easier to debug the test if something goes wrong.)
26
27 #SCOPE #PREFIX
28set cxx_scopes_list {
29 {"S::method()" "S_M"}
30 {"S::static_method()" "S_SM"}
31 {"S::inline_method()" "S_IM"}
32 {"S::static_inline_method()" "S_SIM"}
33 {"S2<int>::method()" "S2_M"}
34 {"S2<int>::static_method()" "S2_SM"}
35 {"S2<int>::inline_method()" "S2_IM"}
36 {"S2<int>::static_inline_method()" "S2_SIM"}
37 {"free_func()" "FF"}
38 {"free_inline_func()" "FIF"}
39}
40
41set c_scopes_list {
42 {"free_func" "FF"}
43 {"free_inline_func" "FIF"}
44}
45
46# A list of all the static varibles defined in each scope. The first
47# column is the name of the variable, without the prefix, and the
48# second column is a regex matching what printing the variable should
49# output.
50
51 #VAR #PRINT
52set vars_list {
53 {"s_var_int" " = 4"}
54 {"s_var_float" " = 3.14.*"}
55 {"s_var_aggregate" " = \\{i1 = 1, i2 = 2, i3 = 3\\}"}
56}
57
58proc do_test {lang} {
59 global c_scopes_list
60 global cxx_scopes_list
61 global vars_list
62 global srcfile testfile
63
64 set options {debug}
65
66 if {$lang == "c++"} {
67 if { [skip_cplus_tests] } {
68 return
69 }
70 lappend options $lang
71 set src ${srcfile}c
72 } else {
73 set src ${srcfile}
74 }
75
76 if {[prepare_for_testing "failed to prepare" $testfile-$lang \
77 [list $src] $options]} {
78 return -1
79 }
80
81 if ![runto_main] then {
82 fail "couldn't run to breakpoint"
83 return
84 }
85
86 gdb_test "show language" " currently [string_to_regexp $lang]\"\\."
87
88 if {$lang == "c"} {
89 set scopes_list $c_scopes_list
90 } else {
91 set scopes_list $cxx_scopes_list
92 }
93
94 # Print each variable using these syntaxes:
95 #
96 # 'func()'::var
97 # func()::var
e68cb8e0
PA
98 # 'func()::var'
99 #
100 # In C++, the latter case makes sure that symbol lookup finds the
101 # debug symbol instead of the minimal symbol with that exact same
102 # name.
858be34c
PA
103
104 foreach scope_line $scopes_list {
105 set scope [lindex $scope_line 0]
106 set var_prefix [lindex $scope_line 1]
107 foreach var_line $vars_list {
108 set var [lindex $var_line 0]
109 set print_re [lindex $var_line 1]
110
111 gdb_test "print '${scope}'::${var_prefix}_${var}" $print_re
112 gdb_test "print ${scope}::${var_prefix}_${var}" $print_re
e68cb8e0
PA
113
114 set sym "${scope}::${var_prefix}_${var}"
115 if {$lang == "c++"} {
116 gdb_test "print '${sym}'" $print_re
117 } else {
118 gdb_test "print '${sym}'" "No symbol \"$sym\" in current context\\."
119 }
858be34c
PA
120 }
121 }
122
123 # Now run to each function, and print its variables using the
124 # localy-visible name.
125 foreach scope_line $scopes_list {
126 set scope [lindex $scope_line 0]
127 set var_prefix [lindex $scope_line 1]
128
129 with_test_prefix "$scope" {
130 delete_breakpoints
131 gdb_breakpoint "$scope"
132 gdb_continue_to_breakpoint "$scope"
133
134 foreach var_line $vars_list {
135 set var [lindex $var_line 0]
136 set print_re [lindex $var_line 1]
137
138 gdb_test "print ${var_prefix}_${var}" $print_re
139 }
140 }
141 }
142}
143
144foreach lang {"c" "c++"} {
145 with_test_prefix $lang {
146 do_test $lang
147 }
148}