]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 2002-2023 Free Software Foundation, Inc. |
2fcf52f0 AC |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
2fcf52f0 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
2fcf52f0 AC |
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. | |
e22f8b7c | 12 | # |
2fcf52f0 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2fcf52f0 | 15 | |
2fcf52f0 AC |
16 | # This file tests that GDB's console can be accessed via the MI. |
17 | # Specifically, we are testing the "interpreter-exec" command and that | |
18 | # the commands that are executed via this command are properly executed. | |
19 | # Console commands executed via MI should use MI output wrappers, MI event | |
20 | # handlers, etc. | |
21 | ||
22 | load_lib mi-support.exp | |
91567807 | 23 | set MIFLAGS "-i=mi" |
2fcf52f0 | 24 | |
298a9cf0 TT |
25 | standard_testfile basics.c |
26 | ||
9357e021 | 27 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
5b362f04 | 28 | untested "failed to compile" |
b60f0898 | 29 | return -1 |
2fcf52f0 AC |
30 | } |
31 | ||
b75d55d4 PA |
32 | mi_clean_restart $binfile |
33 | ||
2fcf52f0 | 34 | mi_gdb_test "-interpreter-exec" \ |
1b05df00 | 35 | {\^error,msg="-interpreter-exec: Usage: -interpreter-exec interp command"} \ |
2fcf52f0 AC |
36 | "-interpreter-exec with no arguments" |
37 | ||
38 | mi_gdb_test "-interpreter-exec console" \ | |
1b05df00 | 39 | {\^error,msg="-interpreter-exec: Usage: -interpreter-exec interp command"} \ |
2fcf52f0 AC |
40 | "-interpreter-exec with one argument" |
41 | ||
42 | mi_gdb_test "-interpreter-exec bogus command" \ | |
1b05df00 | 43 | {\^error,msg="-interpreter-exec: could not find interpreter \\\"bogus\\\""} \ |
2fcf52f0 AC |
44 | "-interpreter-exec with bogus interpreter" |
45 | ||
46 | set msg {Undefined command: \\\"bogus\\\"\. Try \\\"help\\\"\.} | |
47 | mi_gdb_test "-interpreter-exec console bogus" \ | |
48 | "&\\\"$msg\\\\n\\\".*\\^error,msg=\\\"$msg\\\".*" \ | |
49 | "-interpreter-exec console bogus" | |
50 | ||
51 | # NOTE: cagney/2003-02-03: Not yet. | |
52 | # mi_gdb_test "-interpreter-exec console \"file $binfile\"" \ | |
53 | # {(=.*)+\^done} \ | |
54 | # "-interpreter-exec console \"file \$binfile\"" | |
55 | mi_gdb_test "-interpreter-exec console \"file $binfile\"" \ | |
3453e7e4 | 56 | {~"Reading symbols from .*mi-cli...\\n".*} \ |
2fcf52f0 AC |
57 | "-interpreter-exec console \"file \$binfile\"" |
58 | ||
b75d55d4 | 59 | mi_runto_main |
2fcf52f0 | 60 | |
dd322c54 JK |
61 | set line_main_head [gdb_get_line_number "main ("] |
62 | set line_main_body [expr $line_main_head + 2] | |
63 | set line_main_hello [gdb_get_line_number "Hello, World!"] | |
64 | set line_main_return [expr $line_main_hello + 2] | |
5166082f | 65 | set line_main_callme_2 [expr $line_main_return + 1] |
dd322c54 JK |
66 | set line_callee4_head [gdb_get_line_number "callee4 ("] |
67 | set line_callee4_body [expr $line_callee4_head + 2] | |
a065d7af | 68 | set line_callee4_next [expr $line_callee4_body + 1] |
17b2616c | 69 | set line_callee4_next_step [expr $line_callee4_next + 3] |
45f07fef | 70 | |
2fcf52f0 | 71 | mi_gdb_test "-interpreter-exec console \"set args foobar\"" \ |
5b9afe8a | 72 | ".*=cmd-param-changed,param=\"args\",value=\"foobar\".*\\^done" \ |
2fcf52f0 AC |
73 | "-interpreter-exec console \"set args foobar\"" |
74 | ||
75 | mi_gdb_test "-interpreter-exec console \"show args\"" \ | |
76 | {\~"Argument list to give program being debugged when it is started is \\\"foobar\\\"\.\\n".*\^done} \ | |
77 | "-interpreter-exec console \"show args\"" | |
78 | ||
2fcf52f0 | 79 | mi_gdb_test "-interpreter-exec console \"break callee4\"" \ |
a1e5fd69 YQ |
80 | {(&.*)*.*~"Breakpoint 2 at.*\\n".*=breakpoint-created,bkpt=\{number="2",type="breakpoint".*\}.*\n\^done} \ |
81 | "-interpreter-exec console \"break callee4\"" | |
2fcf52f0 AC |
82 | |
83 | mi_gdb_test "-interpreter-exec console \"info break\"" \ | |
84 | {\~"Num[ \t]*Type[ \t]*Disp[ \t]*Enb[ \t]*Address[ \t]*What\\n".*~"2[ \t]*breakpoint[ \t]*keep[ \t]*y[ \t]*0x[0-9A-Fa-f]+[ \t]*in callee4 at .*basics.c:[0-9]+\\n".*\^done} \ | |
85 | "-interpreter-exec console \"info break\"" | |
86 | ||
87 | mi_gdb_test "-interpreter-exec console \"set listsize 1\"" \ | |
5b9afe8a | 88 | ".*=cmd-param-changed,param=\"listsize\",value=\"1\".*\\^done" \ |
2fcf52f0 AC |
89 | "-interpreter-exec console \"set listsize 1\"" |
90 | ||
45f07fef | 91 | # {.*\~"32[ \t(\\t)]*callee1.*\\n".*\^done } |
2fcf52f0 | 92 | mi_gdb_test "-interpreter-exec console \"list\"" \ |
45f07fef | 93 | ".*\~\"$line_main_body\[\\\\t \]*callee1.*;\\\\n\".*\\^done" \ |
2fcf52f0 AC |
94 | "-interpreter-exec console \"list\"" |
95 | ||
dd322c54 | 96 | mi_execute_to "exec-continue" "breakpoint-hit" "callee4" "" ".*basics.c" $line_callee4_body \ |
18ac113b | 97 | { "" "disp=\"keep\"" } \ |
bb378428 | 98 | "continue to callee4" |
2fcf52f0 | 99 | |
2fcf52f0 | 100 | mi_gdb_test "100-interpreter-exec console \"delete 2\"" \ |
a1e5fd69 YQ |
101 | {.*=breakpoint-deleted,id=\"2\".*\^done} \ |
102 | "-interpreter-exec console \"delete 2\"" | |
2fcf52f0 AC |
103 | |
104 | # NOTE: cagney/2003-02-03: Not yet. | |
105 | # mi_gdb_test "200-interpreter-exec console \"up\"" \ | |
106 | # {.*=selected-frame-level-changed,level="1".*\^done} \ | |
107 | # "-interpreter-exec console \"up\"" | |
108 | mi_gdb_test "200-interpreter-exec console \"up\"" \ | |
39fb8e9e | 109 | {~"#.*".*200\^done} \ |
2fcf52f0 AC |
110 | "-interpreter-exec console \"up\"" |
111 | ||
112 | # NOTE: cagney/2003-02-03: Not yet. | |
113 | # mi_gdb_test "300-interpreter-exec console \"down\"" \ | |
114 | # {.*=selected-frame-level-changed,level="0".*\^done} \ | |
115 | # "-interpreter-exec console \"down\"" | |
116 | mi_gdb_test "300-interpreter-exec console \"down\"" \ | |
39fb8e9e | 117 | {~"#.*".*300\^done} \ |
2fcf52f0 AC |
118 | "-interpreter-exec console \"down\"" |
119 | ||
120 | # NOTE: cagney/2003-02-03: Not yet. | |
121 | # mi_gdb_test "-interpreter-exec console \"frame 2\"" \ | |
122 | # {.*=selected-frame-level-changed,level="2".*\^done} \ | |
123 | # "-interpreter-exec console \"frame 2\"" | |
124 | mi_gdb_test "400-interpreter-exec console \"frame 2\"" \ | |
39fb8e9e | 125 | {~"#.*".*400\^done} \ |
2fcf52f0 AC |
126 | "-interpreter-exec console \"frame 2\"" |
127 | ||
128 | # NOTE: cagney/2003-02-03: Not yet. | |
129 | # mi_gdb_test "-stack-select-frame 0" \ | |
130 | # {.*=selected-frame-level-changed,level="0".*\^done} \ | |
131 | # "-stack-select-frame 0" | |
132 | mi_gdb_test "500-stack-select-frame 0" \ | |
133 | {500\^done} \ | |
134 | "-stack-select-frame 0" | |
135 | ||
fd664c91 | 136 | mi_execute_to "interpreter-exec console step" "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_next \ |
a065d7af YQ |
137 | "" "check *stopped from CLI command" |
138 | ||
17b2616c PA |
139 | mi_send_resuming_command "exec-step" "-exec-step to line \$line_callee4_next_step" |
140 | ||
141 | # Test that the new current source line is _not_ output, given we | |
142 | # executed MI's -exec-next, not CLI's 'next' command. | |
143 | ||
144 | set output [mi_gdb_expect_cli_output "\\*stopped" "collect CLI output for -exec-step"] | |
145 | ||
146 | set test "-exec-step does not produce CLI step output" | |
147 | if {[regexp "A + B" "$output"]} { | |
148 | fail $test | |
149 | } else { | |
150 | pass $test | |
151 | } | |
152 | ||
153 | mi_expect_stop "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_next_step \ | |
154 | "" "check *stopped from CLI command 2" | |
155 | ||
243a9253 PA |
156 | # Test that CLI's "finish" command prints the function's return value |
157 | # to both the CLI and MI streams, and that the same result variable is | |
158 | # printed to both streams. | |
159 | with_test_prefix "CLI finish" { | |
160 | mi_send_resuming_command "interpreter-exec console finish" "send CLI command" | |
161 | ||
162 | set output [mi_gdb_expect_cli_output "\\*stopped" "collect CLI output"] | |
163 | gdb_assert {[regexp \ | |
164 | "callee3 .* at .*basics.c:.*.*Value returned is .1 = 0\\\\n" \ | |
165 | $output]} \ | |
166 | "check CLI output" | |
167 | ||
168 | mi_expect_stop "function-finished" "callee3" ".*" \ | |
169 | ".*basics.c" ".*" \ | |
170 | ",gdb-result-var=\".1\",return-value=\"0\"" \ | |
171 | "check MI output" | |
172 | } | |
173 | ||
45f07fef | 174 | mi_gdb_test "600-break-insert -t basics.c:$line_main_hello" \ |
2fcf52f0 | 175 | {600\^done,bkpt=.number="3",type="breakpoint".*\}} \ |
8ae551cf | 176 | "-break-insert -t basics.c:\$line_main_hello" |
2fcf52f0 | 177 | |
17b2616c PA |
178 | # Test that breakpoint events are always mirrored to the CLI output |
179 | # stream (both sync and async modes). | |
180 | mi_send_resuming_command "exec-continue" "-exec-continue to line \$line_main_hello" | |
181 | ||
182 | set output [mi_gdb_expect_cli_output "\\*stopped" "collect CLI output for breakpoint hit"] | |
183 | set test "breakpoint hit produces CLI output" | |
f57929f2 | 184 | set pattern "\\\\nTemporary breakpoint 3, main \\(\\) at \[^\n\]*basics.c:$line_main_hello\\\\n\[^\n\]+Hello" |
17b2616c PA |
185 | |
186 | if {[regexp $pattern $output]} { | |
187 | pass $test | |
188 | } else { | |
189 | fail $test | |
190 | } | |
191 | ||
192 | # Test the MI output. | |
193 | mi_expect_stop "breakpoint-hit" "main" "" ".*basics.c" \ | |
194 | $line_main_hello { "" "disp=\"del\"" } "temporary breakpoint output hit in MI" | |
2fcf52f0 | 195 | |
a065d7af YQ |
196 | # Test that the token is output even for CLI commands |
197 | # Also test that *stopped includes frame information. | |
198 | mi_gdb_test "34 next" \ | |
199 | ".*34\\\^running.*\\*running,thread-id=\"all\"" \ | |
200 | "34 next: run" | |
201 | ||
17b2616c PA |
202 | # Test that the new current source line is output to the console |
203 | # stream, given we executed the console 'next' command, not | |
204 | # -exec-next. | |
205 | set test "34 next: CLI output" | |
206 | gdb_expect { | |
207 | -re "~\"$line_main_return\[^\r\n\]+\r\n" { | |
208 | pass $test | |
209 | } | |
210 | timeout { | |
211 | fail "$test (timeout)" | |
a065d7af YQ |
212 | } |
213 | } | |
214 | ||
fd664c91 | 215 | mi_expect_stop "end-stepping-range" "main" "" ".*basics.c" $line_main_return "" \ |
a065d7af | 216 | "34 next: stop" |
2fcf52f0 AC |
217 | |
218 | mi_gdb_test "-interpreter-exec console \"list\"" \ | |
60c46647 | 219 | "\~\"$line_main_return\[\\\\t ]*callme \\(1\\);\\\\n\".*\\^done" \ |
45f07fef | 220 | "-interpreter-exec console \"list\" at basics.c:\$line_main_return" |
2fcf52f0 | 221 | |
5166082f PA |
222 | mi_gdb_test "600-break-insert -t basics.c:$line_main_callme_2" \ |
223 | {600\^done,bkpt=.number="4",type="breakpoint".*\}} \ | |
224 | "-break-insert -t basics.c:\$line_main_callme_2" | |
225 | ||
226 | mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*basics.c" \ | |
227 | $line_main_callme_2 { "" "disp=\"del\"" } \ | |
228 | "-exec-continue to line \$line_main_callme_2" | |
229 | ||
230 | # Restore the listsize back to the default. | |
231 | mi_gdb_test "-interpreter-exec console \"set listsize 10\"" \ | |
232 | ".*=cmd-param-changed,param=\"listsize\",value=\"10\".*\\^done" \ | |
233 | "-interpreter-exec console \"set listsize 10\"" | |
234 | ||
235 | # "list" should show 10 lines centered on where the program stopped. | |
236 | set first_list_line [expr $line_main_callme_2 - 5] | |
237 | mi_gdb_test "-interpreter-exec console \"list\"" \ | |
238 | ".*\~\"$first_list_line.*\\^done" \ | |
239 | "-interpreter-exec console \"list\" at basics.c:\$line_main_callme_2" | |
240 | ||
2fcf52f0 AC |
241 | mi_gdb_test "-interpreter-exec console \"help set args\"" \ |
242 | {\~"Set argument list to give program being debugged when it is started\.\\nFollow this command with any number of args, to be passed to the program\.".*\^done} \ | |
243 | "-interpreter-exec console \"help set args\"" | |
244 | ||
245 | # NOTE: cagney/2003-02-03: Not yet. | |
246 | # mi_gdb_test "-interpreter-exec console \"set \$pc=0x0\"" \ | |
247 | # {.*=target-changed.*\^done} \ | |
248 | # "-interpreter-exec console \"set \$pc=0x0\"" | |
249 | mi_gdb_test "888-interpreter-exec console \"set \$pc=0x0\"" \ | |
250 | {888\^done} \ | |
251 | "-interpreter-exec console \"set \$pc=0x0\"" | |
252 | ||
253 | #mi_gdb_test "-interpreter-exec console \"\"" \ | |
254 | {} \ | |
255 | "-interpreter-exec console \"\"" | |
256 | ||
257 | mi_gdb_exit | |
258 | return 0 |