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