]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-simplerun.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-simplerun.exp
1 # Copyright 1999, 2000, 2001, 2002, 2004, 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 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 #
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=mi"
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 mi-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_callee3_head [gdb_get_line_number "callee3 ("]
56 set line_callee2_head [gdb_get_line_number "callee2 ("]
57 set line_callee2_body [expr $line_callee2_head + 2]
58 set line_main_head [gdb_get_line_number "main ("]
59 set line_main_body [expr $line_main_head + 2]
60
61 # Insert some breakpoints and list them
62 # Also, disable some so they do not interfere with other tests
63 # Tests:
64 # -break-insert
65 # -break-list
66 # -break-disable
67 # -break-info
68
69 mi_gdb_test "200-break-insert main" \
70 "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"$line_main_body\",times=\"0\"\}" \
71 "break-insert operation"
72
73 mi_gdb_test "201-break-insert basics.c:callee2" \
74 "201\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee2\",file=\".*basics.c\",line=\"$line_callee2_body\",times=\"0\"\}" \
75 "insert breakpoint at basics.c:callee2"
76
77 mi_gdb_test "202-break-insert basics.c:$line_callee3_head" \
78 "202\\^done,bkpt=\{number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee3\",file=\".*basics.c\",line=\"$line_callee3_head\",times=\"0\"\}" \
79 "insert breakpoint at basics.c:\$line_callee3_head"
80
81 mi_gdb_test "203-break-insert \"\\\"${srcfile}\\\":$line_callee4_head\"" \
82 "203\\^done,bkpt=\{number=\"4\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"$line_callee4_head\",times=\"0\"\}" \
83 "insert breakpoint at \"<fullfilename>\":\$line_callee4_head"
84
85 mi_gdb_test "204-break-list" \
86 "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\"\},.*\}\\\]\}" \
87 "list of breakpoints"
88
89 mi_gdb_test "205-break-disable 2 3 4" \
90 "205\\^done.*" \
91 "disabling of breakpoints"
92
93 mi_gdb_test "206-break-info 2" \
94 "206\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"2\",.*,enabled=\"n\",.*\}\\\]\}" \
95 "list of breakpoints, 16 disabled"
96 }
97
98 proc test_running_the_program {} {
99 global mi_gdb_prompt
100 global hex
101
102 set line_main_head [gdb_get_line_number "main ("]
103 set line_main_body [expr $line_main_head + 2]
104
105 # Run the program without args, then specify srgs and rerun the program
106 # Tests:
107 # -exec-run
108 # -gdb-set
109
110 # mi_gdb_test cannot be used for asynchronous commands because there are
111 # two prompts involved and this can lead to a race condition.
112 # The following is equivalent to a send_gdb "000-exec-run\n"
113 mi_run_cmd
114 gdb_expect {
115 -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$" {
116 pass "run to main"
117 }
118 -re ".*$mi_gdb_prompt$" {
119 fail "run to main (2)"
120 }
121 timeout {
122 fail "run to main (timeout)"
123 }
124 }
125 }
126
127 proc test_controlled_execution {} {
128 global mi_gdb_prompt
129 global hex
130
131 set line_callee4_head [gdb_get_line_number "callee4 ("]
132 set line_callee4_body [expr $line_callee4_head + 2]
133 set line_callee3_head [gdb_get_line_number "callee3 ("]
134 set line_callee3_close_brace [expr $line_callee3_head + 3]
135 set line_callee1_head [gdb_get_line_number "callee1 ("]
136 set line_callee1_body [expr $line_callee1_head + 2]
137 set line_main_head [gdb_get_line_number "main ("]
138 set line_main_body [expr $line_main_head + 2]
139
140 # Continue execution until a breakpoint is reached, step into calls, verifying
141 # if the arguments are correctly shown, continue to the end of a called
142 # function, step over a call (next).
143 # Tests:
144 # -exec-continue
145 # -exec-next
146 # -exec-step
147 # -exec-finish
148
149 mi_next_to "main" "" "basics.c" [expr $line_main_body + 1] "next at main"
150
151 # FIXME: A string argument is not printed right; should be fixed and
152 # we should look for the right thing here.
153 # NOTE: The ``\\\\\"'' is for \".
154 mi_step_to "callee1" \
155 "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}" \
156 "basics.c" "$line_callee1_body" "step at main"
157
158 # FIXME: A string argument is not printed right; should be fixed and
159 # we should look for the right thing here.
160 mi_execute_to "exec-step 3" "end-stepping-range" "callee4" "" \
161 "basics.c" $line_callee4_body "" "step to callee4"
162
163 # FIXME: A string argument is not printed right; should be fixed and
164 # we should look for the right thing here.
165 # NOTE: The ``.'' is part of ``gdb-result-var="$1"''
166 mi_finish_to "callee3" ".*" "basics.c" $line_callee3_close_brace ".1" "0" "exec-finish"
167 }
168
169 proc test_controlling_breakpoints {} {
170 global mi_gdb_prompt
171
172 # Enable, delete, set ignore counts in breakpoints
173 # (disable was already tested above)
174 # Tests:
175 # -break-delete
176 # -break-enable
177 # -break-after
178 # -break-condition
179
180 }
181
182 proc test_program_termination {} {
183 global mi_gdb_prompt
184
185 # Run to completion: normal and forced
186 # Tests:
187 # -exec-abort
188 # (normal termination of inferior)
189
190 # FIXME: "stopped" doesn't seem appropriate.
191 # mi_gdb_test cannot be used for asynchronous commands because there are
192 # two prompts involved and this can lead to a race condition.
193 send_gdb "999-exec-continue\n"
194 gdb_expect {
195 -re "999\\^running\r\n$mi_gdb_prompt" {
196 gdb_expect {
197 -re "999\\*stopped,reason=\"exited-normally\"\r\n$mi_gdb_prompt$" {
198 pass "continue to end"
199 }
200 -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"}
201 timeout {fail "continue to end (timeout 2)"}
202 }
203 }
204 -re ".*$mi_gdb_prompt$" {fail "continue to end (1)"}
205 timeout {fail "continue to end (timeout 1)"}
206 }
207 }
208
209 test_breakpoints_creation_and_listing
210 test_running_the_program
211 test_controlled_execution
212 test_controlling_breakpoints
213 test_program_termination
214
215 mi_gdb_exit
216 return 0