]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-cli.exp
PR gdb/13860: make -interpreter-exec console "list" behave more like "list".
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-cli.exp
1 # Copyright 2002-2014 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 # 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
23 set MIFLAGS "-i=mi"
24
25 gdb_exit
26 if [mi_gdb_start] {
27 continue
28 }
29
30 standard_testfile basics.c
31
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 untested mi-cli.exp
34 return -1
35 }
36
37 mi_gdb_test "-interpreter-exec" \
38 {\^error,msg="-interpreter-exec: Usage: -interpreter-exec interp command"} \
39 "-interpreter-exec with no arguments"
40
41 mi_gdb_test "-interpreter-exec console" \
42 {\^error,msg="-interpreter-exec: Usage: -interpreter-exec interp command"} \
43 "-interpreter-exec with one argument"
44
45 mi_gdb_test "-interpreter-exec bogus command" \
46 {\^error,msg="-interpreter-exec: could not find interpreter \\\"bogus\\\""} \
47 "-interpreter-exec with bogus interpreter"
48
49 set msg {Undefined command: \\\"bogus\\\"\. Try \\\"help\\\"\.}
50 mi_gdb_test "-interpreter-exec console bogus" \
51 "&\\\"$msg\\\\n\\\".*\\^error,msg=\\\"$msg\\\".*" \
52 "-interpreter-exec console bogus"
53
54 # NOTE: cagney/2003-02-03: Not yet.
55 # mi_gdb_test "-interpreter-exec console \"file $binfile\"" \
56 # {(=.*)+\^done} \
57 # "-interpreter-exec console \"file \$binfile\""
58 mi_gdb_test "-interpreter-exec console \"file $binfile\"" \
59 {~"Reading symbols from .*mi-cli...".*\^done} \
60 "-interpreter-exec console \"file \$binfile\""
61
62 mi_run_to_main
63
64 set line_main_head [gdb_get_line_number "main ("]
65 set line_main_body [expr $line_main_head + 2]
66 set line_main_hello [gdb_get_line_number "Hello, World!"]
67 set line_main_return [expr $line_main_hello + 2]
68 set line_main_callme_2 [expr $line_main_return + 1]
69 set line_callee4_head [gdb_get_line_number "callee4 ("]
70 set line_callee4_body [expr $line_callee4_head + 2]
71 set line_callee4_next [expr $line_callee4_body + 1]
72
73 mi_gdb_test "-interpreter-exec console \"set args foobar\"" \
74 ".*=cmd-param-changed,param=\"args\",value=\"foobar\".*\\^done" \
75 "-interpreter-exec console \"set args foobar\""
76
77 mi_gdb_test "-interpreter-exec console \"show args\"" \
78 {\~"Argument list to give program being debugged when it is started is \\\"foobar\\\"\.\\n".*\^done} \
79 "-interpreter-exec console \"show args\""
80
81 mi_gdb_test "-interpreter-exec console \"break callee4\"" \
82 {(&.*)*.*~"Breakpoint 2 at.*\\n".*=breakpoint-created,bkpt=\{number="2",type="breakpoint".*\}.*\n\^done} \
83 "-interpreter-exec console \"break callee4\""
84
85 mi_gdb_test "-interpreter-exec console \"info break\"" \
86 {\~"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} \
87 "-interpreter-exec console \"info break\""
88
89 mi_gdb_test "-interpreter-exec console \"set listsize 1\"" \
90 ".*=cmd-param-changed,param=\"listsize\",value=\"1\".*\\^done" \
91 "-interpreter-exec console \"set listsize 1\""
92
93 # {.*\~"32[ \t(\\t)]*callee1.*\\n".*\^done }
94 mi_gdb_test "-interpreter-exec console \"list\"" \
95 ".*\~\"$line_main_body\[\\\\t \]*callee1.*;\\\\n\".*\\^done" \
96 "-interpreter-exec console \"list\""
97
98 mi_execute_to "exec-continue" "breakpoint-hit" "callee4" "" ".*basics.c" $line_callee4_body \
99 { "" "disp=\"keep\"" } \
100 "continue to callee4"
101
102 mi_gdb_test "100-interpreter-exec console \"delete 2\"" \
103 {.*=breakpoint-deleted,id=\"2\".*\^done} \
104 "-interpreter-exec console \"delete 2\""
105
106 # NOTE: cagney/2003-02-03: Not yet.
107 # mi_gdb_test "200-interpreter-exec console \"up\"" \
108 # {.*=selected-frame-level-changed,level="1".*\^done} \
109 # "-interpreter-exec console \"up\""
110 mi_gdb_test "200-interpreter-exec console \"up\"" \
111 {~"#.*".*200\^done} \
112 "-interpreter-exec console \"up\""
113
114 # NOTE: cagney/2003-02-03: Not yet.
115 # mi_gdb_test "300-interpreter-exec console \"down\"" \
116 # {.*=selected-frame-level-changed,level="0".*\^done} \
117 # "-interpreter-exec console \"down\""
118 mi_gdb_test "300-interpreter-exec console \"down\"" \
119 {~"#.*".*300\^done} \
120 "-interpreter-exec console \"down\""
121
122 # NOTE: cagney/2003-02-03: Not yet.
123 # mi_gdb_test "-interpreter-exec console \"frame 2\"" \
124 # {.*=selected-frame-level-changed,level="2".*\^done} \
125 # "-interpreter-exec console \"frame 2\""
126 mi_gdb_test "400-interpreter-exec console \"frame 2\"" \
127 {~"#.*".*400\^done} \
128 "-interpreter-exec console \"frame 2\""
129
130 # NOTE: cagney/2003-02-03: Not yet.
131 # mi_gdb_test "-stack-select-frame 0" \
132 # {.*=selected-frame-level-changed,level="0".*\^done} \
133 # "-stack-select-frame 0"
134 mi_gdb_test "500-stack-select-frame 0" \
135 {500\^done} \
136 "-stack-select-frame 0"
137
138 # When a CLI command is entered in MI session, the respose is different in
139 # sync and async modes. In sync mode normal_stop is called when current
140 # interpreter is CLI. So:
141 # - print_stop_reason prints stop reason in CLI uiout, and we don't show it
142 # in MI
143 # - The stop position is printed, and appears in MI 'console' channel.
144 #
145 # In async mode the stop event is processed when we're back to MI interpreter,
146 # so the stop reason is printed into MI uiout an.
147 if {$async} {
148 set reason "end-stepping-range"
149 } else {
150 set reason ""
151 }
152
153 mi_execute_to "interpreter-exec console step" $reason "callee4" "" ".*basics.c" $line_callee4_next \
154 "" "check *stopped from CLI command"
155
156 mi_gdb_test "600-break-insert -t basics.c:$line_main_hello" \
157 {600\^done,bkpt=.number="3",type="breakpoint".*\}} \
158 "-break-insert -t basics.c:\$line_main_hello"
159
160 mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*basics.c" \
161 $line_main_hello { "" "disp=\"del\"" } \
162 "-exec-continue to line \$line_main_hello"
163
164 # Test that the token is output even for CLI commands
165 # Also test that *stopped includes frame information.
166 mi_gdb_test "34 next" \
167 ".*34\\\^running.*\\*running,thread-id=\"all\"" \
168 "34 next: run"
169
170 if {!$async} {
171 gdb_expect {
172 -re "~\[^\r\n\]+\r\n" {
173 }
174 }
175 }
176
177 # Note that the output does not include stop reason. This is fine.
178 # The purpose of *stopped notification for CLI command is to make
179 # sure that frontend knows that inferior is stopped, and knows where.
180 # Supplementary information is not necessary.
181 mi_expect_stop "$reason" "main" "" ".*basics.c" $line_main_return "" \
182 "34 next: stop"
183
184 mi_gdb_test "-interpreter-exec console \"list\"" \
185 "\~\"$line_main_return\[\\\\t ]*callme \\(1\\);\\\\n\".*\\^done" \
186 "-interpreter-exec console \"list\" at basics.c:\$line_main_return"
187
188 mi_gdb_test "600-break-insert -t basics.c:$line_main_callme_2" \
189 {600\^done,bkpt=.number="4",type="breakpoint".*\}} \
190 "-break-insert -t basics.c:\$line_main_callme_2"
191
192 mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*basics.c" \
193 $line_main_callme_2 { "" "disp=\"del\"" } \
194 "-exec-continue to line \$line_main_callme_2"
195
196 # Restore the listsize back to the default.
197 mi_gdb_test "-interpreter-exec console \"set listsize 10\"" \
198 ".*=cmd-param-changed,param=\"listsize\",value=\"10\".*\\^done" \
199 "-interpreter-exec console \"set listsize 10\""
200
201 # "list" should show 10 lines centered on where the program stopped.
202 set first_list_line [expr $line_main_callme_2 - 5]
203 mi_gdb_test "-interpreter-exec console \"list\"" \
204 ".*\~\"$first_list_line.*\\^done" \
205 "-interpreter-exec console \"list\" at basics.c:\$line_main_callme_2"
206
207 mi_gdb_test "-interpreter-exec console \"help set args\"" \
208 {\~"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} \
209 "-interpreter-exec console \"help set args\""
210
211 # NOTE: cagney/2003-02-03: Not yet.
212 # mi_gdb_test "-interpreter-exec console \"set \$pc=0x0\"" \
213 # {.*=target-changed.*\^done} \
214 # "-interpreter-exec console \"set \$pc=0x0\""
215 mi_gdb_test "888-interpreter-exec console \"set \$pc=0x0\"" \
216 {888\^done} \
217 "-interpreter-exec console \"set \$pc=0x0\""
218
219 #mi_gdb_test "-interpreter-exec console \"\"" \
220 {} \
221 "-interpreter-exec console \"\""
222
223 mi_gdb_exit
224 return 0