Handle "p S::method()::static_var" in the C++ parser
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / local-static.exp
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
20 standard_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
28 set 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
41 set 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
52 set 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
58 proc 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
98
99 foreach scope_line $scopes_list {
100 set scope [lindex $scope_line 0]
101 set var_prefix [lindex $scope_line 1]
102 foreach var_line $vars_list {
103 set var [lindex $var_line 0]
104 set print_re [lindex $var_line 1]
105
106 gdb_test "print '${scope}'::${var_prefix}_${var}" $print_re
107 gdb_test "print ${scope}::${var_prefix}_${var}" $print_re
108 }
109 }
110
111 # Now run to each function, and print its variables using the
112 # localy-visible name.
113 foreach scope_line $scopes_list {
114 set scope [lindex $scope_line 0]
115 set var_prefix [lindex $scope_line 1]
116
117 with_test_prefix "$scope" {
118 delete_breakpoints
119 gdb_breakpoint "$scope"
120 gdb_continue_to_breakpoint "$scope"
121
122 foreach var_line $vars_list {
123 set var [lindex $var_line 0]
124 set print_re [lindex $var_line 1]
125
126 gdb_test "print ${var_prefix}_${var}" $print_re
127 }
128 }
129 }
130 }
131
132 foreach lang {"c" "c++"} {
133 with_test_prefix $lang {
134 do_test $lang
135 }
136 }
This page took 0.034136 seconds and 5 git commands to generate.