1 # Copyright 2002, 2003, 2004, 2005, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file tests that GDB's console can be accessed via the MI.
18 # Specifically, we are testing the "interpreter-exec" command and that
19 # the commands that are executed via this command are properly executed.
20 # Console commands executed via MI should use MI output wrappers, MI event
23 load_lib mi-support.exp
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/${testfile}
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
39 mi_gdb_test "-interpreter-exec" \
40 {\^error,msg="mi_cmd_interpreter_exec: Usage: -interpreter-exec interp command"} \
41 "-interpreter-exec with no arguments"
43 mi_gdb_test "-interpreter-exec console" \
44 {\^error,msg="mi_cmd_interpreter_exec: Usage: -interpreter-exec interp command"} \
45 "-interpreter-exec with one argument"
47 mi_gdb_test "-interpreter-exec bogus command" \
48 {\^error,msg="mi_cmd_interpreter_exec: could not find interpreter \\\"bogus\\\""} \
49 "-interpreter-exec with bogus interpreter"
51 set msg {Undefined command: \\\"bogus\\\"\. Try \\\"help\\\"\.}
52 mi_gdb_test "-interpreter-exec console bogus" \
53 "&\\\"$msg\\\\n\\\".*\\^error,msg=\\\"$msg\\\".*" \
54 "-interpreter-exec console bogus"
56 # NOTE: cagney/2003-02-03: Not yet.
57 # mi_gdb_test "-interpreter-exec console \"file $binfile\"" \
59 # "-interpreter-exec console \"file \$binfile\""
60 mi_gdb_test "-interpreter-exec console \"file $binfile\"" \
61 {~"Reading symbols from .*basics...".*done} \
62 "-interpreter-exec console \"file \$binfile\""
66 set line_main_head [gdb_get_line_number "main ("]
67 set line_main_body [expr $line_main_head + 2]
68 set line_main_hello [gdb_get_line_number "Hello, World!"]
69 set line_main_return [expr $line_main_hello + 2]
71 mi_gdb_test "-interpreter-exec console \"set args foobar\"" \
73 "-interpreter-exec console \"set args foobar\""
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\""
79 # NOTE: cagney/2003-02-03: Not yet.
80 # mi_gdb_test "-interpreter-exec console \"break callee4\"" \
81 # {(&.*)*.*~"Breakpoint 2 at.*\\n".*=breakpoint-create,number="2".*\^done} \
82 # "-interpreter-exec console \"break callee4\""
83 mi_gdb_test "-interpreter-exec console \"break callee4\"" \
84 {(&.*)*.*~"Breakpoint 2 at.*\\n".*\^done} \
85 "-interpreter-exec console \"break callee4\""
87 mi_gdb_test "-interpreter-exec console \"info break\"" \
88 {\~"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} \
89 "-interpreter-exec console \"info break\""
91 mi_gdb_test "-interpreter-exec console \"set listsize 1\"" \
93 "-interpreter-exec console \"set listsize 1\""
95 # {.*\~"32[ \t(\\t)]*callee1.*\\n".*\^done }
96 mi_gdb_test "-interpreter-exec console \"list\"" \
97 ".*\~\"$line_main_body\[\\\\t \]*callee1.*;\\\\n\".*\\^done" \
98 "-interpreter-exec console \"list\""
100 mi_execute_to "exec-continue" "breakpoint-hit" "callee4" "" ".*basics.c" "28" \
101 { "" "disp=\"keep\"" } "continue to callee4"
103 # NOTE: cagney/2003-02-03: Not yet.
104 # mi_gdb_test "100-interpreter-exec console \"delete 2\"" \
105 # {.*=breakpoint-delete,number=\"2\".*\^done} \
106 # "-interpreter-exec console \"delete 2\""
107 mi_gdb_test "100-interpreter-exec console \"delete 2\"" \
109 "-interpreter-exec console \"delete 2\""
111 # NOTE: cagney/2003-02-03: Not yet.
112 # mi_gdb_test "200-interpreter-exec console \"up\"" \
113 # {.*=selected-frame-level-changed,level="1".*\^done} \
114 # "-interpreter-exec console \"up\""
115 mi_gdb_test "200-interpreter-exec console \"up\"" \
116 {~"#.*".*200\^done} \
117 "-interpreter-exec console \"up\""
119 # NOTE: cagney/2003-02-03: Not yet.
120 # mi_gdb_test "300-interpreter-exec console \"down\"" \
121 # {.*=selected-frame-level-changed,level="0".*\^done} \
122 # "-interpreter-exec console \"down\""
123 mi_gdb_test "300-interpreter-exec console \"down\"" \
124 {~"#.*".*300\^done} \
125 "-interpreter-exec console \"down\""
127 # NOTE: cagney/2003-02-03: Not yet.
128 # mi_gdb_test "-interpreter-exec console \"frame 2\"" \
129 # {.*=selected-frame-level-changed,level="2".*\^done} \
130 # "-interpreter-exec console \"frame 2\""
131 mi_gdb_test "400-interpreter-exec console \"frame 2\"" \
132 {~"#.*".*400\^done} \
133 "-interpreter-exec console \"frame 2\""
135 # NOTE: cagney/2003-02-03: Not yet.
136 # mi_gdb_test "-stack-select-frame 0" \
137 # {.*=selected-frame-level-changed,level="0".*\^done} \
138 # "-stack-select-frame 0"
139 mi_gdb_test "500-stack-select-frame 0" \
141 "-stack-select-frame 0"
143 # When a CLI command is entered in MI session, the respose is different in
144 # sync and async modes. In sync mode normal_stop is called when current
145 # interpreter is CLI. So:
146 # - print_stop_reason prints stop reason in CLI uiout, and we don't show it
148 # - The stop position is printed, and appears in MI 'console' channel.
150 # In async mode the stop event is processed when we're back to MI interpreter,
151 # so the stop reason is printed into MI uiout an.
153 set reason "end-stepping-range"
158 mi_execute_to "interpreter-exec console step" $reason "callee4" "" ".*basics.c" "29" \
159 "" "check *stopped from CLI command"
161 # NOTE: cagney/2003-02-03: Not yet.
162 # mi_gdb_test "-break-insert -t basics.c:$line_main_hello" \
163 # {.*=breakpoint-create,number="3".*\^done} \
164 # "-break-insert -t basics.c:\$line_main_hello"
165 mi_gdb_test "600-break-insert -t basics.c:$line_main_hello" \
166 {600\^done,bkpt=.number="3",type="breakpoint".*\}} \
167 "-break-insert -t basics.c:\$line_main_hello"
169 mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*basics.c" \
170 $line_main_hello { "" "disp=\"del\"" } \
171 "-exec-continue to line $line_main_hello"
173 # Test that the token is output even for CLI commands
174 # Also test that *stopped includes frame information.
175 mi_gdb_test "34 next" \
176 ".*34\\\^running.*\\*running,thread-id=\"all\"" \
181 -re "~\[^\r\n\]+\r\n" {
186 # Note that the output does not include stop reason. This is fine.
187 # The purpose of *stopped notification for CLI command is to make
188 # sure that frontend knows that inferior is stopped, and knows where.
189 # Supplementary information is not necessary.
190 mi_expect_stop "$reason" "main" "" ".*basics.c" $line_main_return "" \
193 mi_gdb_test "-interpreter-exec console \"list\"" \
194 "\~\"$line_main_return\[\\\\t ]*callme \\(1\\);\\\\n\".*\\^done" \
195 "-interpreter-exec console \"list\" at basics.c:\$line_main_return"
197 mi_gdb_test "-interpreter-exec console \"help set args\"" \
198 {\~"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} \
199 "-interpreter-exec console \"help set args\""
201 # NOTE: cagney/2003-02-03: Not yet.
202 # mi_gdb_test "-interpreter-exec console \"set \$pc=0x0\"" \
203 # {.*=target-changed.*\^done} \
204 # "-interpreter-exec console \"set \$pc=0x0\""
205 mi_gdb_test "888-interpreter-exec console \"set \$pc=0x0\"" \
207 "-interpreter-exec console \"set \$pc=0x0\""
209 #mi_gdb_test "-interpreter-exec console \"\"" \
211 "-interpreter-exec console \"\""