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