1 # Copyright 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 # Test -symbol-info-functions, -symbol-info-variables, and
19 load_lib mi-support.exp
22 standard_testfile mi-sym-info-1.c mi-sym-info-2.c
24 if {[prepare_for_testing "failed to prepare" ${testfile} \
25 [list $srcfile $srcfile2] {debug}]} {
36 set qstr "\"\[^\"\]+\""
37 set fun_re "\{line=\"$decimal\",name=${qstr},type=${qstr},description=${qstr}\}"
38 set type_re "\{(?:line=\"$decimal\",)*name=${qstr}\}"
39 set sym_list "\\\[${fun_re}(?:,$fun_re)*\\\]"
40 set type_sym_list "\\\[${type_re}(?:,$type_re)*\\\]"
42 "\{filename=${qstr},fullname=${qstr},symbols=${sym_list}\}"
44 "\{filename=${qstr},fullname=${qstr},symbols=${type_sym_list}\}"
46 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\]\}"
48 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[.*\\\]\}"
50 "symbols=\{debug=\\\[${symtab_type_re}(?:,${symtab_type_re})*\\\]\}"
52 # Fetch all functions, variables and types without any non-debug
54 mi_gdb_test "111-symbol-info-functions" \
55 "111\\^done,${debug_only_syms}" \
56 "List all functions from debug information only"
58 mi_gdb_test "112-symbol-info-variables" \
59 "112\\^done,${debug_only_syms}" \
60 "List all variables from debug information only"
62 mi_gdb_test "113-symbol-info-types" \
63 "113\\^done,${type_syms}" \
66 # Fetch functions and variables but also grab the non-debug symbols
67 # (from the symbol table). There's often so much output output from
68 # this command that we overflow expect's buffers, avoid this by
69 # fetching the output piece by piece.
70 set testname "List all functions"
71 gdb_test_multiple "114-symbol-info-functions --include-nondebug" ${testname} {
72 -re "114\\^done,symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[" {
76 -re "\{address=${qstr},name=${qstr}\}," {
80 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
85 set testname "List all variables"
86 gdb_test_multiple "115-symbol-info-variables --include-nondebug" ${testname} {
87 -re "115\\^done,symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[" {
88 verbose -log "Got the first part of the input"
92 -re "\{address=${qstr},name=${qstr}\}," {
96 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
101 # Filter functions by name and type.
102 set lineno [gdb_get_line_number "f3 (another_int_t arg)" ${srcfile2}]
103 mi_gdb_test "116-symbol-info-functions --name f3" \
104 "116\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
105 "List all functions matching pattern f3"
107 set lineno [gdb_get_line_number "f4 (int *arg)" ${srcfile}]
108 mi_gdb_test "117-symbol-info-functions --type void" \
109 "117\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"36\",name=\"f4\",type=\"void \\(int \\*\\)\",description=\"void f4\\(int \\*\\);\"\}\\\]\}\\\]\}" \
110 "List all functions matching type void"
112 # Filter variables by name and type.
113 set lineno [gdb_get_line_number "int global_f2;" ${srcfile2}]
114 mi_gdb_test "118-symbol-info-variables --name global_f2" \
115 "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}\\\]\}\\\]\}" \
116 "List all variables matching pattern global_f2"
118 set lineno1 [gdb_get_line_number "static float global_f1;" ${srcfile}]
119 set lineno2 [gdb_get_line_number "static float global_f1;" ${srcfile2}]
120 mi_gdb_test "119-symbol-info-variables --type float" \
121 "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;\"\}\\\]\}\\\]\}" \
122 "List all variables matching type float"
124 # Fetch types, filtering by name.
125 set lineno1 [gdb_get_line_number "typedef int my_int_t;" ${srcfile}]
126 set lineno2 [gdb_get_line_number "typedef int another_int_t;" ${srcfile2}]
127 mi_gdb_test "120-symbol-info-types --name _int_" \
128 "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\"\}\\\]\}\\\]\}" \
129 "List all types matching _int_"