1 # Copyright 2019-2020 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 # Test -symbol-info-functions, -symbol-info-variables, and
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.
26 load_lib mi-support.exp
29 standard_testfile mi-sym-info-1.c mi-sym-info-2.c
31 if {[prepare_for_testing "failed to prepare" ${testfile} \
32 [list $srcfile $srcfile2] {debug}]} {
43 set qstr "\"\[^\"\]+\""
44 set fun_re "\{line=\"$decimal\",name=${qstr},type=${qstr},description=${qstr}\}"
45 set type_re "\{(?:line=\"$decimal\",)*name=${qstr}\}"
46 set sym_list "\\\[${fun_re}(?:,$fun_re)*\\\]"
47 set type_sym_list "\\\[${type_re}(?:,$type_re)*\\\]"
49 "\{filename=${qstr},fullname=${qstr},symbols=${sym_list}\}"
51 "\{filename=${qstr},fullname=${qstr},symbols=${type_sym_list}\}"
53 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\]\}"
55 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[.*\\\]\}"
57 "symbols=\{debug=\\\[${symtab_type_re}(?:,${symtab_type_re})*\\\]\}"
59 # Fetch all functions, variables and types without any non-debug
61 set testname "List all functions from debug information only"
62 set cmd "111-symbol-info-functions"
64 gdb_test_multiple $cmd $testname -prompt "${mi_gdb_prompt}$" {
65 -re "111\\^done,symbols=\{debug=\\\[${symtab_re}" {
66 if { $state == 0 } { incr state }
72 -re "\\\]\}\r\n${mi_gdb_prompt}$" {
81 set testname "List all variables from debug information only"
82 set cmd "112-symbol-info-variables"
84 gdb_test_multiple $cmd $testname -prompt "${mi_gdb_prompt}$" {
85 -re "112\\^done,symbols=\{debug=\\\[${symtab_re}" {
86 if { $state == 0 } { incr state }
92 -re "\\\]\}\r\n${mi_gdb_prompt}$" {
101 set testname "List all types"
102 set cmd "113-symbol-info-types"
104 gdb_test_multiple $cmd $testname -prompt "${mi_gdb_prompt}$" {
105 -re "113\\^done,symbols=\{debug=\\\[${symtab_type_re}" {
106 if { $state == 0 } { incr state }
109 -re ",${symtab_type_re}" {
112 -re "\\\]\}\r\n${mi_gdb_prompt}$" {
121 # Fetch functions and variables but also grab the non-debug symbols
122 # (from the symbol table). There's often so much output output from
123 # this command that we overflow expect's buffers, avoid this by
124 # fetching the output piece by piece.
125 set testname "List all functions"
126 set cmd "114-symbol-info-functions --include-nondebug"
128 gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" {
129 -re "114\\^done,symbols=\{" {
130 if { $state == 0 } { set state 1 }
133 -re "debug=\\\[${symtab_re}" {
134 if { $state == 1 } { set state 2 }
137 -re ",${symtab_re}" {
140 -re "\\\],nondebug=\\\[" {
141 if { $state == 2 } { set state 3 }
144 -re "\{address=${qstr},name=${qstr}\}," {
147 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
156 with_timeout_factor 2 {
157 set testname "List all variables"
158 set cmd "115-symbol-info-variables --include-nondebug"
160 gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" {
161 -re "115\\^done,symbols=\{" {
162 if { $state == 0 } { set state 1 }
165 -re "debug=\\\[${symtab_re}" {
166 if { $state == 1 } { set state 2 }
169 -re ",${symtab_re}" {
172 -re "\\\],nondebug=\\\[" {
173 if { $state == 2 } { set state 3 }
176 -re "\{address=${qstr},name=${qstr}\}," {
179 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
189 with_timeout_factor 2 {
190 set testname "List all variables"
191 set cmd "115-symbol-info-variables --include-nondebug"
193 gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" {
194 -re "115\\^done,symbols=\{" {
195 if { $state == 0 } { incr state }
198 -re "debug=\\\[${symtab_re}" {
199 if { $state == 1 } { incr state }
202 -re ",${symtab_re}" {
205 -re "\\\],nondebug=\\\[" {
206 if { $state == 2 } { incr state }
209 -re "\{address=${qstr},name=${qstr}\}," {
212 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
222 # Filter functions by name and type.
223 set lineno [gdb_get_line_number "f3 (another_int_t arg)" ${srcfile2}]
224 mi_gdb_test "116-symbol-info-functions --name ^f3$" \
225 "116\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
226 "List all functions matching pattern f3"
228 set lineno [gdb_get_line_number "f4 (int *arg)" ${srcfile}]
229 mi_gdb_test "117-symbol-info-functions --type void --name ^f4$" \
230 "117\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"36\",name=\"f4\",type=\"void \\(int \\*\\)\",description=\"void f4\\(int \\*\\);\"\}\\\]\}\\\]\}" \
231 "List all functions matching type void"
233 # Filter variables by name and type.
234 set lineno [gdb_get_line_number "int global_f2;" ${srcfile2}]
235 mi_gdb_test "118-symbol-info-variables --name global_f2" \
236 "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}\\\]\}\\\]\}" \
237 "List all variables matching pattern global_f2"
239 set lineno1 [gdb_get_line_number "static float global_f1;" ${srcfile}]
240 set lineno2 [gdb_get_line_number "static float global_f1;" ${srcfile2}]
241 mi_gdb_test "119-symbol-info-variables --type float --name ^global_" \
242 "119\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"25\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"19\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\}\\\]\}" \
243 "List all variables matching type float"
245 # Fetch types, filtering by name.
246 set lineno1 [gdb_get_line_number "typedef int my_int_t;" ${srcfile}]
247 set lineno2 [gdb_get_line_number "typedef int another_int_t;" ${srcfile2}]
248 mi_gdb_test "120-symbol-info-types --name _int_" \
249 "120\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"27\",name=\"my_int_t\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"23\",name=\"another_int_t\"\}\\\]\}\\\]\}" \
250 "List all types matching _int_"
252 # Test the --max-results parameter.
253 mi_gdb_test "121-symbol-info-functions --max-results 0" \
254 "121\\^done,symbols=\{\}" \
255 "-symbol-info-functions --max-results 0"
257 mi_gdb_test "122-symbol-info-functions --max-results 1 --name ^\[^_\]" \
258 "122\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
259 "-symbol-info-functions --max-results 1"
261 mi_gdb_test "123-symbol-info-functions --max-results 2 --name ^\[^_\]" \
262 "123\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"33\",name=\"f2\",type=\"float \\(another_float_t\\)\",description=\"float f2\\(another_float_t\\);\"\},\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
263 "-symbol-info-functions --max-results 2"
265 mi_gdb_test "124-symbol-info-variables --max-results 3 --name ^\[^_\]" \
266 "124\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\},\{line=\"20\",name=\"global_i2\",type=\"int\",description=\"int global_i2;\"\},\{line=\"19\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\}\\\]\}" \
268 set s1 "\{line=\"44\",name=\"another_char_t\"\}"
269 set s2 "\{line=\"24\",name=\"another_float_t\"\}"
270 set s3 "\{line=\"23\",name=\"another_int_t\"\}"
271 set s4 "\{line=\"45\",name=\"another_short_t\"\}"
272 mi_gdb_test "125-symbol-info-types --max-results 4 --name another_" \
273 "125\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$s1,$s2,$s3,$s4\\\]\}\\\]\}" \
274 "-symbol-info-types --max-results 4"