1# Copyright 2002, 2003, 2004, 2005, 2007 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
22load_lib mi-support.exp
23set MIFLAGS "-i=mi"
24
25gdb_exit
26if [mi_gdb_start] {
27    continue
28}
29
30set testfile "basics"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
34     untested mi-cli.exp
35     return -1
36}
37
38mi_gdb_test "-interpreter-exec" \
39  {\^error,msg="mi_cmd_interpreter_exec: Usage: -interpreter-exec interp command"} \
40  "-interpreter-exec with no arguments"
41
42mi_gdb_test "-interpreter-exec console" \
43  {\^error,msg="mi_cmd_interpreter_exec: Usage: -interpreter-exec interp command"} \
44  "-interpreter-exec with one argument"
45
46mi_gdb_test "-interpreter-exec bogus command" \
47  {\^error,msg="mi_cmd_interpreter_exec: could not find interpreter \\\"bogus\\\""} \
48  "-interpreter-exec with bogus interpreter"
49
50set msg {Undefined command: \\\"bogus\\\"\.  Try \\\"help\\\"\.}
51mi_gdb_test "-interpreter-exec console bogus" \
52    "&\\\"$msg\\\\n\\\".*\\^error,msg=\\\"$msg\\\".*" \
53  "-interpreter-exec console bogus"
54
55# NOTE: cagney/2003-02-03: Not yet.
56# mi_gdb_test "-interpreter-exec console \"file $binfile\"" \
57#   {(=.*)+\^done} \
58#   "-interpreter-exec console \"file \$binfile\""
59mi_gdb_test "-interpreter-exec console \"file $binfile\"" \
60  {~"Reading symbols from .*basics...".*done} \
61  "-interpreter-exec console \"file \$binfile\""
62
63mi_run_to_main
64
65set line_main_head   [gdb_get_line_number "main ("]
66set line_main_body   [expr $line_main_head + 2]
67set line_main_hello  [gdb_get_line_number "Hello, World!"]
68set line_main_return [expr $line_main_hello + 2]
69
70mi_gdb_test "-interpreter-exec console \"set args foobar\"" \
71  {\^done} \
72  "-interpreter-exec console \"set args foobar\""
73
74mi_gdb_test "-interpreter-exec console \"show args\"" \
75  {\~"Argument list to give program being debugged when it is started is \\\"foobar\\\"\.\\n".*\^done} \
76  "-interpreter-exec console \"show args\""
77
78# NOTE: cagney/2003-02-03: Not yet.
79# mi_gdb_test "-interpreter-exec console \"break callee4\"" \
80#   {(&.*)*.*~"Breakpoint 2 at.*\\n".*=breakpoint-create,number="2".*\^done} \
81#   "-interpreter-exec console \"break callee4\""
82mi_gdb_test "-interpreter-exec console \"break callee4\"" \
83  {(&.*)*.*~"Breakpoint 2 at.*\\n".*\^done} \
84  "-interpreter-exec console \"break callee4\""
85
86mi_gdb_test "-interpreter-exec console \"info break\"" \
87  {\~"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} \
88  "-interpreter-exec console \"info break\""
89
90mi_gdb_test "-interpreter-exec console \"set listsize 1\"" \
91  {\^done} \
92  "-interpreter-exec console \"set listsize 1\""
93
94# {.*\~"32[ \t(\\t)]*callee1.*\\n".*\^done }
95mi_gdb_test "-interpreter-exec console \"list\"" \
96  ".*\~\"$line_main_body\[\\\\t \]*callee1.*;\\\\n\".*\\^done" \
97  "-interpreter-exec console \"list\""
98
99# # NOTE: cagney/2003-02-03: Not yet.
100# mi_gdb_test "-exec-continue" \
101#    {.*\*stopped,reason="breakpoint-hit",.*func="callee4".*file=".*basics.c",fullname="${fullname_syntax}${srcfile}",line="8"\}} \
102#    "-interpreter-exec console \"continue to callee4\""
103send_gdb "999-exec-continue\n"
104gdb_expect {
105    -re "999\\^running\[\r\n\]+$mi_gdb_prompt.*999\\*stopped,reason=.breakpoint-hit.*$mi_gdb_prompt$" {
106	pass "continue to callee4"
107    }
108    timeout {
109	fail "continue to callee4 (timeout)"
110    }
111}
112
113# NOTE: cagney/2003-02-03: Not yet.
114# mi_gdb_test "100-interpreter-exec console \"delete 2\"" \
115#   {.*=breakpoint-delete,number=\"2\".*\^done} \
116#   "-interpreter-exec console \"delete 2\""
117mi_gdb_test "100-interpreter-exec console \"delete 2\"" \
118  {100\^done} \
119  "-interpreter-exec console \"delete 2\""
120
121# NOTE: cagney/2003-02-03: Not yet.
122# mi_gdb_test "200-interpreter-exec console \"up\"" \
123#   {.*=selected-frame-level-changed,level="1".*\^done} \
124#   "-interpreter-exec console \"up\""
125mi_gdb_test "200-interpreter-exec console \"up\"" \
126  {~"#.*".*200\^done} \
127  "-interpreter-exec console \"up\""
128
129# NOTE: cagney/2003-02-03: Not yet.
130# mi_gdb_test "300-interpreter-exec console \"down\"" \
131#   {.*=selected-frame-level-changed,level="0".*\^done} \
132#   "-interpreter-exec console \"down\""
133mi_gdb_test "300-interpreter-exec console \"down\"" \
134  {~"#.*".*300\^done} \
135  "-interpreter-exec console \"down\""
136
137# NOTE: cagney/2003-02-03: Not yet.
138# mi_gdb_test "-interpreter-exec console \"frame 2\"" \
139#   {.*=selected-frame-level-changed,level="2".*\^done} \
140#   "-interpreter-exec console \"frame 2\""
141mi_gdb_test "400-interpreter-exec console \"frame 2\"" \
142  {~"#.*".*400\^done} \
143  "-interpreter-exec console \"frame 2\""
144
145# NOTE: cagney/2003-02-03: Not yet.
146# mi_gdb_test "-stack-select-frame 0" \
147#   {.*=selected-frame-level-changed,level="0".*\^done} \
148#   "-stack-select-frame 0"
149mi_gdb_test "500-stack-select-frame 0" \
150  {500\^done} \
151  "-stack-select-frame 0"
152
153# NOTE: cagney/2003-02-03: Not yet.
154# mi_gdb_test "-break-insert -t basics.c:$line_main_hello" \
155#   {.*=breakpoint-create,number="3".*\^done} \
156#   "-break-insert -t basics.c:\$line_main_hello"
157mi_gdb_test "600-break-insert -t basics.c:$line_main_hello" \
158	{600\^done,bkpt=.number="3",type="breakpoint".*\}} \
159	"-break-insert -t basics.c:\$line_main_hello"
160
161# mi_gdb_test "-exec-continue" \
162#   {.*\*stopped.*,file=".*basics.c",fullname="${fullname_syntax}${srcfile}",line="$line_main_hello"\}} \
163#   "-exec-continue to line \$line_main_hello"
164send_gdb "700-exec-continue\n"
165gdb_expect {
166    -re "700\\^running\[\r\n\]+$mi_gdb_prompt.*\\*stopped.*,file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=.$line_main_hello.*$mi_gdb_prompt$" {
167	pass "-exec-continue to line \$line_main_hello"
168    }
169    timeout {
170	fail "-exec-continue to line \$line_main_hello"
171    }
172}
173
174# NOTE: cagney/2003-02-03: Not yet.
175# mi_gdb_test "-exec-next" \
176#   {.*\*stopped,reason="end-stepping-range",.*,file=".*basics.c",fullname="${fullname_syntax}${srcfile}",line="$line_main_return"\}} \
177#   "-exec-next to line \$line_main_return"
178send_gdb "800-exec-next\n"
179gdb_expect {
180    -re "800\\^running\[\r\n\]+$mi_gdb_prompt.*\\*stopped,reason=.end-stepping-range.*,file=\".*basics.c\",fullname=\"${fullname_syntax}${srcfile}\",line=.$line_main_return.*$mi_gdb_prompt$" {
181	pass "-exec-next to line \$line_main_return"
182    }
183    timeout {
184	fail "-exec-next to line \$line_main_return"
185    }
186}
187
188mi_gdb_test "-interpreter-exec console \"list\"" \
189  "\~\"$line_main_return\[\\\\t ]*return 0;\\\\n\".*\\^done" \
190  "-interpreter-exec console \"list\" at basics.c:\$line_main_return"
191
192mi_gdb_test "-interpreter-exec console \"help set args\"" \
193  {\~"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} \
194  "-interpreter-exec console \"help set args\""
195
196# NOTE: cagney/2003-02-03: Not yet.
197# mi_gdb_test "-interpreter-exec console \"set \$pc=0x0\"" \
198#   {.*=target-changed.*\^done} \
199#   "-interpreter-exec console \"set \$pc=0x0\""
200mi_gdb_test "888-interpreter-exec console \"set \$pc=0x0\"" \
201  {888\^done} \
202  "-interpreter-exec console \"set \$pc=0x0\""
203
204#mi_gdb_test "-interpreter-exec console \"\"" \
205  {} \
206  "-interpreter-exec console \"\""
207
208mi_gdb_exit
209return 0
210