Add mi/ and testsuite/gdb.mi/ subdirectories.
[platform/upstream/binutils.git] / gdb / testsuite / gdb.mi / mi-simplerun.exp
1 #   Copyright (C) 1999, 2000 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 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 #
21 # Test essential Machine interface (MI) operations
22 #
23 # Verify that, using the MI, we can run a simple program and perform basic
24 # debugging activities like: insert breakpoints, run the program,
25 # step, next, continue until it ends and, last but not least, quit.
26 #
27 # The goal is not to test gdb functionality, which is done by other tests,
28 # but to verify the correct output response to MI operations.
29 #
30
31 load_lib mi-support.exp
32
33 gdb_exit
34 if [mi_gdb_start] {
35     continue
36 }
37
38 set testfile "basics"
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
41 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
42      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
43 }
44
45 mi_delete_breakpoints
46 mi_gdb_reinitialize_dir $srcdir/$subdir
47 mi_gdb_reinitialize_dir $srcdir/$subdir
48 mi_gdb_load ${binfile}
49
50 proc test_breakpoints_creation_and_listing {} {
51     global mi_gdb_prompt
52     global srcfile
53     global hex
54
55     # Insert some breakpoints and list them
56     # Also, disable some so they do not interfere with other tests
57     # Tests:
58     # -break-insert
59     # -break-list
60     # -break-disable
61     # -break-info
62
63     mi_gdb_test "200-break-insert main" \
64              "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"32\",times=\"0\"\}" \
65              "break-insert operation"
66
67     mi_gdb_test "201-break-insert basics.c:callee2" \
68              "201\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee2\",file=\".*basics.c\",line=\"22\",times=\"0\"\}" \
69              "insert breakpoint at basics.c:callee2"
70
71     mi_gdb_test "202-break-insert basics.c:15" \
72              "202\\^done,bkpt=\{number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee3\",file=\".*basics.c\",line=\"15\",times=\"0\"\}" \
73              "insert breakpoint at basics.c:15 (callee3)"
74
75     mi_gdb_test "203-break-insert \"\\\"${srcfile}\\\":6\"" \
76              "203\\^done,bkpt=\{number=\"4\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"6\",times=\"0\"\}" \
77              "insert breakpoint at \"<fullfilename>\":6 (callee4)"
78
79     mi_gdb_test "204-break-list" \
80                 "204\\^done,BreakpointTable=\{hdr=\{.*\},bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"32\",times=\"0\"\},.*\}\}" \
81                 "list of breakpoints"
82
83     mi_gdb_test "205-break-disable 2 3 4" \
84                 "205\\^done.*" \
85                 "disabling of breakpoints"
86
87     mi_gdb_test "206-break-info 2" \
88                 "206\\^done,BreakpointTable=\{hdr=\{.*\},bkpt=\{number=\"2\",.*,enabled=\"n\",.*\}\}" \
89                 "list of breakpoints, 16 disabled"
90 }
91
92 proc test_running_the_program {} {
93     global mi_gdb_prompt
94     global hex
95
96     # Run the program without args, then specify srgs and rerun the program
97     # Tests:
98     # -exec-run
99     # -gdb-set
100
101     # mi_gdb_test cannot be used for asynchronous commands because there are
102     # two prompts involved and this can lead to a race condition.
103     # The following is equivalent to a send_gdb "000-exec-run\n"
104     mi_run_cmd
105     gdb_expect {
106         -re "000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"main\",args=\{\},file=\".*basics.c\",line=\"32\"\}\r\n$mi_gdb_prompt$" {
107             pass "run to main"
108         }
109         timeout {
110             fail "run to main (timeout)"
111         }
112     }
113 }
114
115 proc test_controlled_execution {} {
116     global mi_gdb_prompt
117     global hex
118
119     # Continue execution until a breakpoint is reached, step into calls, verifying
120     # if the arguments are correctly shown, continue to the end of a called
121     # function, step over a call (next).
122     # Tests:
123     # -exec-continue
124     # -exec-next
125     # -exec-step
126     # -exec-finish
127
128     # mi_gdb_test cannot be used for asynchronous commands because there are
129     # two prompts involved and this can lead to a race condition.
130     send_gdb "220-exec-next\n"
131     gdb_expect {
132         -re "220\\^running\r\n${mi_gdb_prompt}220\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"main\",args=\{\},file=\".*basics.c\",line=\"33\"\}\r\n$mi_gdb_prompt$" {
133             pass "next at main"
134         }
135         timeout {
136             fail "next at main (timeout)"
137         }
138     }
139
140     # FIXME: A string argument is not printed right; should be fixed and
141     #        we should look for the right thing here.
142     # NOTE: The ``\\\\\"'' is for \".
143     send_gdb "221-exec-step\n"
144     gdb_expect {
145         -re "221\\^running\r\n${mi_gdb_prompt}221\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"callee1\",args=\{\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\},file=\".*basics.c\",line=\"27\"\}\r\n$mi_gdb_prompt$" {
146             pass "step at main"
147         }
148         timeout {
149             fail "step at main (timeout)"
150         }
151     }
152
153     # FIXME: A string argument is not printed right; should be fixed and
154     #        we should look for the right thing here.
155     send_gdb "222-exec-step 3\n"
156     gdb_expect 30 {
157         -re "222\\^running\r\n${mi_gdb_prompt}222\\*stopped,reason=\"end-stepping-range\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"callee4\",args=\{\},file=\".*basics.c\",line=\"8\"\}\r\n$mi_gdb_prompt$" {
158             pass "step to callee4"
159         }
160         timeout {
161             fail "step to callee4 (timeout)"
162         }
163     }
164
165     # FIXME: A string argument is not printed right; should be fixed and
166     #        we should look for the right thing here.
167     # NOTE: The ``.'' is part of ``gdb-result-var="$1"''
168     send_gdb "223-exec-finish\n"
169     gdb_expect 30 {
170         -re "223\\^running\r\n${mi_gdb_prompt}223\\*stopped,reason=\"function-finished\",thread-id=\"0\",frame=\{addr=\"$hex\",func=\"callee3\",args=\{.*\},file=\".*basics.c\",line=\"18\"\},gdb-result-var=\".1\",return-value=\"0\"\r\n$mi_gdb_prompt$" {
171             pass "exec-finish"
172         }
173         timeout {
174             fail "exec-finish (timeout)"
175         }
176     }
177 }
178
179 proc test_controlling_breakpoints {} {
180     global mi_gdb_prompt
181
182     # Enable, delete, set ignore counts in breakpoints
183     # (disable was already tested above)
184     # Tests:
185     # -break-delete
186     # -break-enable
187     # -break-after
188     # -break-condition
189
190 }
191
192 proc test_program_termination {} {
193     global mi_gdb_prompt
194
195     # Run to completion: normal and forced
196     # Tests:
197     # -exec-abort
198     # (normal termination of inferior)
199
200     # FIXME: "stopped" doesn't seem appropriate.
201     # mi_gdb_test cannot be used for asynchronous commands because there are
202     # two prompts involved and this can lead to a race condition.
203     send_gdb "999-exec-continue\n"
204     gdb_expect {
205       -re "999\\^running\r\n$mi_gdb_prompt" {
206         gdb_expect {
207           -re "999\\*stopped,reason=\"exited-normally\"\r\n$mi_gdb_prompt$" {
208             pass "continue to end"
209           }
210           -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"}
211           timeout {fail "continue to end (timeout 2)"}
212         }
213       }
214       -re ".*$mi_gdb_prompt$" {fail "continue to end (1)"}
215       timeout {fail "continue to end (timeout 1)"}
216     }
217 }
218
219 test_breakpoints_creation_and_listing
220 test_running_the_program
221 test_controlled_execution
222 test_controlling_breakpoints
223 test_program_termination
224
225 mi_gdb_exit
226 return 0
227
228 # Local variables: 
229 # change-log-default-name: "ChangeLog-mi"
230 # End: 
231
232