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