[PATCH 7/57][Arm][GAS] Add support for MVE instructions: vstr/vldr
[binutils-gdb.git] / gdb / testsuite / gdb.cp / local-static.exp
blobfe0e2dc0f3a2b5e37d80a8cc7963b7a079a70b19
1 # Copyright 2017-2019 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.
20 standard_testfile .c
22 # A few expected errors.
23 set syntax_re "A syntax error in expression, near.*"
24 set cannot_resolve_re "Cannot resolve method S::method to any overloaded instance"
26 # Build an "Cannot resolve method ..." expected error string for
27 # method METH.
29 proc cannot_resolve {meth} {
30     return "Cannot resolve method $meth to any overloaded instance"
33 # A list of scopes that have the static variables that we want to
34 # print.  Each entry has, in order, the scope/function name, and the
35 # prefix used by the static variables.  The prefix exists both to make
36 # it easier to debug the test if something goes wrong, and, to make
37 # sure that printing the static local of one method overload doesn't
38 # find the variables of the wrong overload.
40 # While at it, we also try printing each scope without the static
41 # local, to check that the parse copes with cv overloads without
42 # quoting.  That's what the third and forth columns are for.  Note
43 # that printing "func()" is different from "func(void)".  The former
44 # is an inferior function call, while the latter is a reference to the
45 # function.
47      #SCOPE                             #PREFIX         #PRINT-SCOPE-QUOTED
48                                                         #PRINT-SCOPE-UNQUOTED (opt)
49 set cxx_scopes_list {
50     {"S::method()"                      "S_M"           {= \\{void \\(S \\* const\\)\\} $hex <S::method\\(\\)>}
51                                                         {[cannot_resolve "S::method"]}}
53     {"S::method() const"                "S_M_C"         {= \\{void \\(const S \\* const\\)\\} $hex <S::method\\(\\) const>}
54                                                         $syntax_re}
56     {"S::method() volatile"             "S_M_V"         {= \\{void \\(volatile S \\* const\\)\\} $hex <S::method\\(\\) volatile>}
57                                                         $syntax_re}
59     {"S::method() const volatile"       "S_M_CV"        {= \\{void \\(const volatile S \\* const\\)\\} $hex <S::method\\(\\) const volatile>}
60                                                         $syntax_re}
62     {"S::method() volatile const"       "S_M_CV"        {= \\{void \\(const volatile S \\* const\\)\\} $hex <S::method\\(\\) const volatile>}
63                                                         $syntax_re}
65     {"S::method(void)"                  "S_M"           {= \\{void \\(S \\* const\\)\\} $hex <S::method\\(\\)>}}
66     {"S::method(void) const"            "S_M_C"         {= \\{void \\(const S \\* const\\)\\} $hex <S::method\\(\\) const>}}
67     {"S::method(void) volatile"         "S_M_V"         {= \\{void \\(volatile S \\* const\\)\\} $hex <S::method\\(\\) volatile>}}
68     {"S::method(void) const volatile"   "S_M_CV"        {= \\{void \\(const volatile S \\* const\\)\\} $hex <S::method\\(\\) const volatile>}}
69     {"S::method(void) volatile const"   "S_M_CV"        {= \\{void \\(const volatile S \\* const\\)\\} $hex <S::method\\(\\) const volatile>}}
71     {"S::static_method()"               "S_SM"          {= \\{void \\(void\\)\\} $hex <S::static_method\\(\\)>}
72                                                         "void"}
74     {"S::static_method(void)"           "S_SM"          {= \\{void \\(void\\)\\} $hex <S::static_method\\(\\)>}}
76     {"S::inline_method()"               "S_IM"          {= \\{void \\(S \\* const\\)\\} $hex <S::inline_method\\(\\)>}
77                                                         {[cannot_resolve "S::inline_method"]}}
79     {"S::inline_method(void)"           "S_IM"          {= \\{void \\(S \\* const\\)\\} $hex <S::inline_method\\(\\)>}}
81     {"S::static_inline_method()"        "S_SIM"         {= \\{void \\(void\\)\\} $hex <S::static_inline_method\\(\\)>}
82                                                         "void"}
84     {"S::static_inline_method(void)"    "S_SIM"         {= \\{void \\(void\\)\\} $hex <S::static_inline_method\\(\\)>}}
86     {"S2<int>::method()"                "S2_M"          {= \\{void \\(S2<int> \\* const\\)\\} $hex <S2<int>::method\\(\\)>}
87                                                         {[cannot_resolve "S2<int>::method"]}}
89     {"S2<int>::static_method()"         "S2_SM"         {= \\{void \\(void\\)\\} $hex <S2<int>::static_method\\(\\)>}
90                                                         "void"}
92     {"S2<int>::inline_method()"         "S2_IM"         {= \\{void \\(S2<int> \\* const\\)\\} $hex <S2<int>::inline_method\\(\\)>}
93                                                         {[cannot_resolve "S2<int>::inline_method"]}}
95     {"S2<int>::static_inline_method()"  "S2_SIM"        {= \\{void \\(void\\)\\} $hex <S2<int>::static_inline_method\\(\\)>}
96                                                         "void"}
98     {"free_func"                        "FF"            {= \\{void \\(void\\)\\} $hex <free_func\\(\\)>}}
100     {"free_func()"                      "FF"            {= \\{void \\(void\\)\\} $hex <free_func\\(\\)>}
101                                                         "void"}
103     {"free_func(void)"                  "FF"            {= \\{void \\(void\\)\\} $hex <free_func\\(\\)>}}
105     {"free_inline_func()"               "FIF"           {= \\{void \\(void\\)\\} $hex <free_inline_func\\(\\)>}
106                                                         "void"}
108     {"free_inline_func(void)"           "FIF"           {= \\{void \\(void\\)\\} $hex <free_inline_func\\(\\)>}}
111 set c_scopes_list {
112     {"free_func"                        "FF"            {= \\{void \\(void\\)\\} $hex <free_func>}}
113     {"free_inline_func"                 "FIF"           {= \\{void \\(void\\)\\} $hex <free_inline_func>}}
116 # A list of all the static varibles defined in each scope.  The first
117 # column is the name of the variable, without the prefix, and the
118 # second column is a regex matching what printing the variable should
119 # output.
121      #VAR               #PRINT
122 set vars_list {
123     {"s_var_int"        " = 4"}
124     {"s_var_float"      " = 3.14.*"}
125     {"s_var_aggregate"  " = \\{i1 = 1, i2 = 2, i3 = 3\\}"}
128 proc do_test {lang} {
129     global c_scopes_list
130     global cxx_scopes_list
131     global vars_list
132     global srcfile testfile
134     set options {debug}
136     if {$lang == "c++"} {
137         if { [skip_cplus_tests] } {
138             return
139         }
140         lappend options $lang
141         set src ${srcfile}c
142     } else {
143         set src ${srcfile}
144     }
146     if {[prepare_for_testing "failed to prepare" $testfile-$lang \
147              [list $src] $options]} {
148         return -1
149     }
151     if ![runto_main] then {
152         fail "couldn't run to breakpoint"
153         return
154     }
156     gdb_test "show language" " currently [string_to_regexp $lang]\"\\."
158     if {$lang == "c"} {
159         set scopes_list $c_scopes_list
160     } else {
161         set scopes_list $cxx_scopes_list
162     }
164     # Print each scope/function using these syntaxes:
165     #
166     #  "(gdb) p 'S::method() const'"    # quoted
167     #  "(gdb) p S::method() const"      # unquoted
168     #
169     foreach scope_line $scopes_list  {
170         set scope [lindex $scope_line 0]
172         set print_quoted_re [lindex $scope_line 2]
173         set print_quoted_re [uplevel 1 "subst -nobackslashes -nocommands \"$print_quoted_re\""]
175         set print_unquoted_re [lindex $scope_line 3]
176         set print_unquoted_re [uplevel 1 "subst -nobackslashes -nocommands \"$print_unquoted_re\""]
178         gdb_test "print '${scope}'" $print_quoted_re
180         if {$print_unquoted_re != ""} {
181             gdb_test "print ${scope}" $print_unquoted_re
182         } else {
183             gdb_test "print ${scope}" $print_quoted_re
184         }
185     }
187     # Print each variable using these syntaxes:
188     #
189     #  'func()'::var
190     #  func()::var
191     #  'func()::var'
192     #
193     # In C++, the latter case makes sure that symbol lookup finds the
194     # debug symbol instead of the minimal symbol with that exact same
195     # name.
197     foreach scope_line $scopes_list  {
198         set scope [lindex $scope_line 0]
199         set var_prefix [lindex $scope_line 1]
200         foreach var_line $vars_list {
201             set var [lindex $var_line 0]
202             set print_re [lindex $var_line 1]
204             gdb_test "print '${scope}'::${var_prefix}_${var}" $print_re
205             gdb_test "print ${scope}::${var_prefix}_${var}" $print_re
207             set sym "${scope}::${var_prefix}_${var}"
208             if {$lang == "c++"} {
209                 gdb_test "print '${sym}'" $print_re
210             } else {
211                 gdb_test "print '${sym}'" "No symbol \"$sym\" in current context\\."
212             }
213         }
214     }
216     # Now run to each function, and print its variables using the
217     # localy-visible name.
218     foreach scope_line $scopes_list {
219         set scope [lindex $scope_line 0]
220         set var_prefix [lindex $scope_line 1]
222         with_test_prefix "$scope" {
223             delete_breakpoints
224             gdb_breakpoint "$scope"
225             gdb_continue_to_breakpoint "$scope"
227             foreach var_line $vars_list {
228                 set var [lindex $var_line 0]
229                 set print_re [lindex $var_line 1]
231                 gdb_test "print ${var_prefix}_${var}" $print_re
232             }
233         }
234     }
237 foreach lang {"c" "c++"} {
238     with_test_prefix $lang {
239         do_test $lang
240     }