Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2019-2020 Free Software Foundation, Inc. |
7dc42066 AB |
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" | |
b98cc2cf TV |
71 | set cmd "114-symbol-info-functions --include-nondebug" |
72 | gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" { | |
7dc42066 AB |
73 | -re "114\\^done,symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[" { |
74 | exp_continue | |
75 | } | |
76 | ||
77 | -re "\{address=${qstr},name=${qstr}\}," { | |
78 | exp_continue | |
79 | } | |
80 | ||
81 | -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" { | |
82 | pass ${testname} | |
83 | } | |
84 | } | |
85 | ||
86 | set testname "List all variables" | |
b98cc2cf TV |
87 | set cmd "115-symbol-info-variables --include-nondebug" |
88 | gdb_test_multiple $cmd ${testname} -prompt "${mi_gdb_prompt}$" { | |
7dc42066 AB |
89 | -re "115\\^done,symbols=\{debug=\\\[${symtab_re}(?:,${symtab_re})*\\\],nondebug=\\\[" { |
90 | verbose -log "Got the first part of the input" | |
91 | exp_continue | |
92 | } | |
93 | ||
94 | -re "\{address=${qstr},name=${qstr}\}," { | |
95 | exp_continue | |
96 | } | |
97 | ||
98 | -re "\{address=${qstr},name=${qstr}\}\\\]\}\r\n${mi_gdb_prompt}$" { | |
99 | pass ${testname} | |
100 | } | |
101 | } | |
102 | ||
103 | # Filter functions by name and type. | |
104 | set lineno [gdb_get_line_number "f3 (another_int_t arg)" ${srcfile2}] | |
105 | mi_gdb_test "116-symbol-info-functions --name f3" \ | |
106 | "116\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \ | |
107 | "List all functions matching pattern f3" | |
108 | ||
109 | set lineno [gdb_get_line_number "f4 (int *arg)" ${srcfile}] | |
49ba92c0 | 110 | mi_gdb_test "117-symbol-info-functions --type void --name ^\[^_\]" \ |
7dc42066 AB |
111 | "117\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"36\",name=\"f4\",type=\"void \\(int \\*\\)\",description=\"void f4\\(int \\*\\);\"\}\\\]\}\\\]\}" \ |
112 | "List all functions matching type void" | |
113 | ||
114 | # Filter variables by name and type. | |
115 | set lineno [gdb_get_line_number "int global_f2;" ${srcfile2}] | |
116 | mi_gdb_test "118-symbol-info-variables --name global_f2" \ | |
117 | "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}\\\]\}\\\]\}" \ | |
118 | "List all variables matching pattern global_f2" | |
119 | ||
120 | set lineno1 [gdb_get_line_number "static float global_f1;" ${srcfile}] | |
121 | set lineno2 [gdb_get_line_number "static float global_f1;" ${srcfile2}] | |
122 | mi_gdb_test "119-symbol-info-variables --type float" \ | |
123 | "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;\"\}\\\]\}\\\]\}" \ | |
124 | "List all variables matching type float" | |
125 | ||
126 | # Fetch types, filtering by name. | |
127 | set lineno1 [gdb_get_line_number "typedef int my_int_t;" ${srcfile}] | |
128 | set lineno2 [gdb_get_line_number "typedef int another_int_t;" ${srcfile2}] | |
129 | mi_gdb_test "120-symbol-info-types --name _int_" \ | |
130 | "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\"\}\\\]\}\\\]\}" \ | |
131 | "List all types matching _int_" | |
c2512106 AB |
132 | |
133 | # Test the --max-results parameter. | |
134 | mi_gdb_test "121-symbol-info-functions --max-results 0" \ | |
135 | "121\\^done,symbols=\{\}" \ | |
136 | "-symbol-info-functions --max-results 0" | |
137 | ||
138 | mi_gdb_test "122-symbol-info-functions --max-results 1" \ | |
139 | "122\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"39\",name=\"f3\",type=\"int \\(another_int_t\\)\",description=\"int f3\\(another_int_t\\);\"\}\\\]\}\\\]\}" \ | |
140 | "-symbol-info-functions --max-results 1" | |
141 | ||
142 | mi_gdb_test "123-symbol-info-functions --max-results 2" \ | |
143 | "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\\);\"\}\\\]\}\\\]\}" \ | |
144 | "-symbol-info-functions --max-results 2" | |
145 | ||
49ba92c0 | 146 | mi_gdb_test "124-symbol-info-variables --max-results 3 --name ^\[^_\]" \ |
c2512106 | 147 | "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;\"\}\\\]\}\\\]\}" \ |
c2512106 | 148 | |
49ba92c0 TV |
149 | set s1 "\{line=\"44\",name=\"another_char_t\"\}" |
150 | set s2 "\{line=\"24\",name=\"another_float_t\"\}" | |
151 | set s3 "\{line=\"23\",name=\"another_int_t\"\}" | |
152 | set s4 "\{line=\"45\",name=\"another_short_t\"\}" | |
153 | mi_gdb_test "125-symbol-info-types --max-results 4 --name another_" \ | |
154 | "125\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[$s1,$s2,$s3,$s4\\\]\}\\\]\}" \ | |
c2512106 | 155 | "-symbol-info-types --max-results 4" |