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