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