1 # Copyright 2017 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 # Tests for function local static variables, both C and C++.
18 # This file is part of the gdb testsuite.
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.)
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"}
38 {"free_inline_func()" "FIF"}
43 {"free_inline_func" "FIF"}
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
54 {"s_var_float" " = 3.14.*"}
55 {"s_var_aggregate" " = \\{i1 = 1, i2 = 2, i3 = 3\\}"}
60 global cxx_scopes_list
62 global srcfile testfile
67 if { [skip_cplus_tests] } {
76 if {[prepare_for_testing "failed to prepare" $testfile-$lang \
77 [list $src] $options]} {
81 if ![runto_main] then {
82 fail "couldn't run to breakpoint"
86 gdb_test "show language" " currently [string_to_regexp $lang]\"\\."
89 set scopes_list $c_scopes_list
91 set scopes_list $cxx_scopes_list
94 # Print each variable using these syntaxes:
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]
106 gdb_test "print '${scope}'::${var_prefix}_${var}" $print_re
107 gdb_test "print ${scope}::${var_prefix}_${var}" $print_re
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]
117 with_test_prefix "$scope" {
119 gdb_breakpoint "$scope"
120 gdb_continue_to_breakpoint "$scope"
122 foreach var_line $vars_list {
123 set var [lindex $var_line 0]
124 set print_re [lindex $var_line 1]
126 gdb_test "print ${var_prefix}_${var}" $print_re
132 foreach lang {"c" "c++"} {
133 with_test_prefix $lang {