4a65bd6ee5dc833eee575133655a910a5a70bb09
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-sym-info.exp
1 # Copyright 2019 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 load_lib mi-support.exp
20 set MIFLAGS "-i=mi"
21
22 standard_testfile mi-sym-info-1.c mi-sym-info-2.c
23
24 if {[prepare_for_testing "failed to prepare" ${testfile} \
25 [list $srcfile $srcfile2] {debug}]} {
26 return -1
27 }
28
29 gdb_exit
30 if {[mi_gdb_start]} {
31 continue
32 }
33
34 mi_run_to_main
35
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)*\\\]"
41 set symtab_re \
42 "\{filename=${qstr},fullname=${qstr},symbols=${sym_list}\}"
43 set symtab_type_re \
44 "\{filename=${qstr},fullname=${qstr},symbols=${type_sym_list}\}"
45 set debug_only_syms \
46 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\]\}"
47 set all_syms \
48 "symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[.*\\\]\}"
49 set type_syms \
50 "symbols=\{debug=\\\[${symtab_type_re}(?:,${symtab_type_re})*\\\]\}"
51
52 # Fetch all functions, variables and types without any non-debug
53 # symbols.
54 mi_gdb_test "111-symbol-info-functions" \
55 "111\\^done,${debug_only_syms}" \
56 "List all functions from debug information only"
57
58 mi_gdb_test "112-symbol-info-variables" \
59 "112\\^done,${debug_only_syms}" \
60 "List all variables from debug information only"
61
62 mi_gdb_test "113-symbol-info-types" \
63 "113\\^done,${type_syms}" \
64 "List all types"
65
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=\\\[" {
73 exp_continue
74 }
75
76 -re "\{address=${qstr},name=${qstr}\}," {
77 exp_continue
78 }
79
80 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
81 pass ${testname}
82 }
83 }
84
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"
89 exp_continue
90 }
91
92 -re "\{address=${qstr},name=${qstr}\}," {
93 exp_continue
94 }
95
96 -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" {
97 pass ${testname}
98 }
99 }
100
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"
106
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"
111
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"
117
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"
123
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_"
130
131 # Test the --max-results parameter.
132 mi_gdb_test "121-symbol-info-functions --max-results 0" \
133 "121\\^done,symbols=\{\}" \
134 "-symbol-info-functions --max-results 0"
135
136 mi_gdb_test "122-symbol-info-functions --max-results 1" \
137 "122\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \
138 "-symbol-info-functions --max-results 1"
139
140 mi_gdb_test "123-symbol-info-functions --max-results 2" \
141 "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\\);\"\}\\\]\}\\\]\}" \
142 "-symbol-info-functions --max-results 2"
143
144 mi_gdb_test "124-symbol-info-variables --max-results 3" \
145 "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;\"\}\\\]\}\\\]\}" \
146 "-symbol-info-variables --max-results 3"
147
148 mi_gdb_test "125-symbol-info-types --max-results 4" \
149 "125\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"24\",name=\"another_float_t\"\},\{line=\"23\",name=\"another_int_t\"\},\{name=\"float\"\},\{name=\"int\"\}\\\]\}\\\]\}" \
150 "-symbol-info-types --max-results 4"
This page took 0.038514 seconds and 4 git commands to generate.