Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-sym-info.exp
CommitLineData
88b9d363 1# Copyright 2019-2022 Free Software Foundation, Inc.
7dc42066
AB
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# Test -symbol-info-functions, -symbol-info-variables, and
17# -symbol-info-types.
2d61316c
TV
18#
19# These tests can generate large amounts of output, which can cause gdb to be
20# slow in two different ways:
21# - it takes long before the command starts producing output
22# - it takes long to print all the output
23# We can prevent timeouts due to the latter using exp_continue, but for
24# the former that doesn't work. There we use with_timeout_factor instead.
7dc42066
AB
25
26load_lib mi-support.exp
27set MIFLAGS "-i=mi"
28
29standard_testfile mi-sym-info-1.c mi-sym-info-2.c
30
31if {[prepare_for_testing "failed to prepare" ${testfile} \
32 [list $srcfile $srcfile2] {debug}]} {
33 return -1
34}
35
b75d55d4 36mi_clean_restart $binfile
7dc42066 37
b75d55d4 38mi_runto_main
7dc42066
AB
39
40set qstr "\"\[^\"\]+\""
41set fun_re "\{line=\"$decimal\",name=${qstr},type=${qstr},description=${qstr}\}"
42set type_re "\{(?:line=\"$decimal\",)*name=${qstr}\}"
43set sym_list "\\\[${fun_re}(?:,$fun_re)*\\\]"
44set type_sym_list "\\\[${type_re}(?:,$type_re)*\\\]"
45set symtab_re \
46 "\{filename=${qstr},fullname=${qstr},symbols=${sym_list}\}"
47set symtab_type_re \
48 "\{filename=${qstr},fullname=${qstr},symbols=${type_sym_list}\}"
49set debug_only_syms \
50 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\]\}"
51set all_syms \
52 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[.*\\\]\}"
53set type_syms \
54 "symbols=\{debug=\\\[${symtab_type_re}(?:,${symtab_type_re})*\\\]\}"
55
56# Fetch all functions, variables and types without any non-debug
57# symbols.
5536f0cc
TV
58with_timeout_factor 2 {
59 set testname "List all functions from debug information only"
60 set cmd "111-symbol-info-functions"
61 set state 0
62 gdb_test_multiple $cmd $testname -prompt "${mi_gdb_prompt}$" {
63 -re "111\\^done,symbols=\{debug=\\\[${symtab_re}" {
64 if { $state == 0 } { incr state }
65 exp_continue
66 }
67 -re ",${symtab_re}" {
68 exp_continue
69 }
70 -re "\\\]\}\r\n${mi_gdb_prompt}$" {
71 if { $state == 1 } {
72 pass $gdb_test_name
73 } else {
74 fail $gdb_test_name
75 }
2d61316c
TV
76 }
77 }
78}
7dc42066 79
5536f0cc
TV
80with_timeout_factor 2 {
81 set testname "List all variables from debug information only"
82 set cmd "112-symbol-info-variables"
83 set state 0
84 gdb_test_multiple $cmd $testname -prompt "${mi_gdb_prompt}$" {
85 -re "112\\^done,symbols=\{debug=\\\[${symtab_re}" {
86 if { $state == 0 } { incr state }
87 exp_continue
88 }
89 -re ",${symtab_re}" {
90 exp_continue
91 }
92 -re "\\\]\}\r\n${mi_gdb_prompt}$" {
93 if { $state == 1 } {
94 pass $gdb_test_name
95 } else {
96 fail $gdb_test_name
97 }
2d61316c
TV
98 }
99 }
100}
7dc42066 101
2d61316c
TV
102set testname "List all types"
103set cmd "113-symbol-info-types"
104set state 0
105gdb_test_multiple $cmd $testname -prompt "${mi_gdb_prompt}$" {
106 -re "113\\^done,symbols=\{debug=\\\[${symtab_type_re}" {
107 if { $state == 0 } { incr state }
108 exp_continue
109 }
110 -re ",${symtab_type_re}" {
111 exp_continue
112 }
113 -re "\\\]\}\r\n${mi_gdb_prompt}$" {
114 if { $state == 1 } {
115 pass $gdb_test_name
116 } else {
117 fail $gdb_test_name
118 }
119 }
120}
7dc42066
AB
121
122# Fetch functions and variables but also grab the non-debug symbols
123# (from the symbol table). There's often so much output output from
124# this command that we overflow expect's buffers, avoid this by
125# fetching the output piece by piece.
b8bd29a1
KB
126with_timeout_factor 4 {
127 set testname "List all functions"
128 set cmd "114-symbol-info-functions --include-nondebug"
129 set state 0
130 gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" {
131 -re "114\\^done,symbols=\{" {
132 if { $state == 0 } { set state 1 }
133 exp_continue
134 }
135 -re "debug=\\\[${symtab_re}" {
136 if { $state == 1 } { set state 2 }
137 exp_continue
138 }
139 -re ",${symtab_re}" {
140 exp_continue
141 }
142 -re "\\\],nondebug=\\\[" {
143 if { $state == 2 } { set state 3 }
144 exp_continue
145 }
146 -re "\{address=${qstr},name=${qstr}\}," {
147 exp_continue
148 }
149 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
150 if { $state == 3 } {
151 pass $gdb_test_name
152 } else {
153 fail $gdb_test_name
154 }
2d61316c
TV
155 }
156 }
157}
158
5536f0cc 159with_timeout_factor 4 {
2d61316c
TV
160 set testname "List all variables"
161 set cmd "115-symbol-info-variables --include-nondebug"
162 set state 0
163 gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" {
164 -re "115\\^done,symbols=\{" {
165 if { $state == 0 } { incr state }
166 exp_continue
167 }
168 -re "debug=\\\[${symtab_re}" {
169 if { $state == 1 } { incr state }
170 exp_continue
171 }
172 -re ",${symtab_re}" {
173 exp_continue
174 }
175 -re "\\\],nondebug=\\\[" {
176 if { $state == 2 } { incr state }
177 exp_continue
178 }
179 -re "\{address=${qstr},name=${qstr}\}," {
180 exp_continue
181 }
182 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
183 if { $state == 3 } {
184 pass $gdb_test_name
185 } else {
186 fail $gdb_test_name
187 }
188 }
7dc42066
AB
189 }
190}
191
127e9f85
TV
192set f2_re \
193 "\{line=\"33\",name=\"f2\",type=\"float \\(another_float_t\\)\",description=\"float f2\\(another_float_t\\);\"\}"
194set f3_re \
195 "\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}"
196set f4_re \
197 "\{line=\"36\",name=\"f4\",type=\"void \\(int \\*\\)\",description=\"void f4\\(int \\*\\);\"\}"
198
199set global_i1_re \
200 "\{line=\"18\",name=\"global_i1\",type=\"int\",description=\"static int global_i1;\"\}"
201set global_f2_re \
202 "\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}"
203set global_i2_re \
204 "\{line=\"20\",name=\"global_i2\",type=\"int\",description=\"int global_i2;\"\}"
205set global_f1_s1_re \
206 "\{line=\"25\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}"
207set global_f1_s2_re \
208 "\{line=\"19\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}"
209
210set another_int_re "\{line=\"23\",name=\"another_int_t\"\}"
211set my_int_re "\{line=\"27\",name=\"my_int_t\"\}"
212set another_char_re "\{line=\"44\",name=\"another_char_t\"\}"
213set another_float_re "\{line=\"24\",name=\"another_float_t\"\}"
214set another_short_re "\{line=\"45\",name=\"another_short_t\"\}"
215
7dc42066
AB
216# Filter functions by name and type.
217set lineno [gdb_get_line_number "f3 (another_int_t arg)" ${srcfile2}]
2e9145ac 218mi_gdb_test "116-symbol-info-functions --name ^f3$" \
127e9f85 219 "116\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$f3_re\\\]\}\\\]\}" \
7dc42066
AB
220 "List all functions matching pattern f3"
221
222set lineno [gdb_get_line_number "f4 (int *arg)" ${srcfile}]
2e9145ac 223mi_gdb_test "117-symbol-info-functions --type void --name ^f4$" \
127e9f85 224 "117\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[$f4_re\\\]\}\\\]\}" \
7dc42066
AB
225 "List all functions matching type void"
226
227# Filter variables by name and type.
228set lineno [gdb_get_line_number "int global_f2;" ${srcfile2}]
229mi_gdb_test "118-symbol-info-variables --name global_f2" \
127e9f85 230 "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$global_f2_re\\\]\}\\\]\}" \
7dc42066
AB
231 "List all variables matching pattern global_f2"
232
71e1b6b0
GB
233set lineno1 [gdb_get_line_number "static float __attribute__ ((used)) global_f1;" ${srcfile}]
234set lineno2 [gdb_get_line_number "static float __attribute__ ((used)) global_f1;" ${srcfile2}]
2e9145ac 235mi_gdb_test "119-symbol-info-variables --type float --name ^global_" \
127e9f85 236 "119\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[$global_f1_s1_re\\\]\},\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$global_f1_s2_re\\\]\}\\\]\}" \
7dc42066
AB
237 "List all variables matching type float"
238
239# Fetch types, filtering by name.
240set lineno1 [gdb_get_line_number "typedef int my_int_t;" ${srcfile}]
241set lineno2 [gdb_get_line_number "typedef int another_int_t;" ${srcfile2}]
242mi_gdb_test "120-symbol-info-types --name _int_" \
127e9f85 243 "120\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[$my_int_re\\\]\},\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$another_int_re\\\]\}\\\]\}" \
7dc42066 244 "List all types matching _int_"
c2512106
AB
245
246# Test the --max-results parameter.
247mi_gdb_test "121-symbol-info-functions --max-results 0" \
248 "121\\^done,symbols=\{\}" \
249 "-symbol-info-functions --max-results 0"
250
2e9145ac 251mi_gdb_test "122-symbol-info-functions --max-results 1 --name ^\[^_\]" \
127e9f85 252 "122\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[(?:$f2_re|$f3_re)\\\]\}\\\]\}" \
c2512106
AB
253 "-symbol-info-functions --max-results 1"
254
2e9145ac 255mi_gdb_test "123-symbol-info-functions --max-results 2 --name ^\[^_\]" \
127e9f85 256 "123\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$f2_re,$f3_re\\\]\}\\\]\}" \
c2512106
AB
257 "-symbol-info-functions --max-results 2"
258
49ba92c0 259mi_gdb_test "124-symbol-info-variables --max-results 3 --name ^\[^_\]" \
127e9f85
TV
260 "124\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$global_f2_re,$global_i2_re,(?:$global_i1_re|$global_f1_s2_re)\\\]\}\\\]\}" \
261 "-symbol-info-types --max-results 3"
c2512106 262
49ba92c0 263mi_gdb_test "125-symbol-info-types --max-results 4 --name another_" \
127e9f85 264 "125\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$another_char_re,$another_float_re,$another_int_re,$another_short_re\\\]\}\\\]\}" \
c2512106 265 "-symbol-info-types --max-results 4"
This page took 0.27704 seconds and 4 git commands to generate.