dcd6f7d918769ea759177421d431902b57d783e9
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-sym-info.exp
1 # Copyright 2019-2021 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 # Test -symbol-info-functions, -symbol-info-variables, and
17 # -symbol-info-types.
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.
25
26 load_lib mi-support.exp
27 set MIFLAGS "-i=mi"
28
29 standard_testfile mi-sym-info-1.c mi-sym-info-2.c
30
31 if {[prepare_for_testing "failed to prepare" ${testfile} \
32 [list $srcfile $srcfile2] {debug}]} {
33 return -1
34 }
35
36 mi_clean_restart $binfile
37
38 mi_runto_main
39
40 set qstr "\"\[^\"\]+\""
41 set fun_re "\{line=\"$decimal\",name=${qstr},type=${qstr},description=${qstr}\}"
42 set type_re "\{(?:line=\"$decimal\",)*name=${qstr}\}"
43 set sym_list "\\\[${fun_re}(?:,$fun_re)*\\\]"
44 set type_sym_list "\\\[${type_re}(?:,$type_re)*\\\]"
45 set symtab_re \
46 "\{filename=${qstr},fullname=${qstr},symbols=${sym_list}\}"
47 set symtab_type_re \
48 "\{filename=${qstr},fullname=${qstr},symbols=${type_sym_list}\}"
49 set debug_only_syms \
50 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\]\}"
51 set all_syms \
52 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[.*\\\]\}"
53 set 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.
58 with_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 }
76 }
77 }
78 }
79
80 with_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 }
98 }
99 }
100 }
101
102 set testname "List all types"
103 set cmd "113-symbol-info-types"
104 set state 0
105 gdb_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 }
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.
126 with_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 }
155 }
156 }
157 }
158
159 with_timeout_factor 4 {
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 }
189 }
190 }
191
192 # Filter functions by name and type.
193 set lineno [gdb_get_line_number "f3 (another_int_t arg)" ${srcfile2}]
194 mi_gdb_test "116-symbol-info-functions --name ^f3$" \
195 "116\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
196 "List all functions matching pattern f3"
197
198 set lineno [gdb_get_line_number "f4 (int *arg)" ${srcfile}]
199 mi_gdb_test "117-symbol-info-functions --type void --name ^f4$" \
200 "117\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"36\",name=\"f4\",type=\"void \\(int \\*\\)\",description=\"void f4\\(int \\*\\);\"\}\\\]\}\\\]\}" \
201 "List all functions matching type void"
202
203 # Filter variables by name and type.
204 set lineno [gdb_get_line_number "int global_f2;" ${srcfile2}]
205 mi_gdb_test "118-symbol-info-variables --name global_f2" \
206 "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}\\\]\}\\\]\}" \
207 "List all variables matching pattern global_f2"
208
209 set lineno1 [gdb_get_line_number "static float __attribute__ ((used)) global_f1;" ${srcfile}]
210 set lineno2 [gdb_get_line_number "static float __attribute__ ((used)) global_f1;" ${srcfile2}]
211 mi_gdb_test "119-symbol-info-variables --type float --name ^global_" \
212 "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;\"\}\\\]\}\\\]\}" \
213 "List all variables matching type float"
214
215 # Fetch types, filtering by name.
216 set lineno1 [gdb_get_line_number "typedef int my_int_t;" ${srcfile}]
217 set lineno2 [gdb_get_line_number "typedef int another_int_t;" ${srcfile2}]
218 mi_gdb_test "120-symbol-info-types --name _int_" \
219 "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\"\}\\\]\}\\\]\}" \
220 "List all types matching _int_"
221
222 # Test the --max-results parameter.
223 mi_gdb_test "121-symbol-info-functions --max-results 0" \
224 "121\\^done,symbols=\{\}" \
225 "-symbol-info-functions --max-results 0"
226
227 mi_gdb_test "122-symbol-info-functions --max-results 1 --name ^\[^_\]" \
228 "122\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
229 "-symbol-info-functions --max-results 1"
230
231 mi_gdb_test "123-symbol-info-functions --max-results 2 --name ^\[^_\]" \
232 "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\\);\"\}\\\]\}\\\]\}" \
233 "-symbol-info-functions --max-results 2"
234
235 mi_gdb_test "124-symbol-info-variables --max-results 3 --name ^\[^_\]" \
236 "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;\"\}\\\]\}\\\]\}" \
237
238 set s1 "\{line=\"44\",name=\"another_char_t\"\}"
239 set s2 "\{line=\"24\",name=\"another_float_t\"\}"
240 set s3 "\{line=\"23\",name=\"another_int_t\"\}"
241 set s4 "\{line=\"45\",name=\"another_short_t\"\}"
242 mi_gdb_test "125-symbol-info-types --max-results 4 --name another_" \
243 "125\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$s1,$s2,$s3,$s4\\\]\}\\\]\}" \
244 "-symbol-info-types --max-results 4"
This page took 0.034384 seconds and 3 git commands to generate.