Commit | Line | Data |
---|---|---|
b6ba6518 | 1 | # Copyright 1999, 2000 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 | |
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 | |
b30bf9ee | 32 | set MIFLAGS "-i=mi" |
fb40c209 AC |
33 | |
34 | gdb_exit | |
35 | if [mi_gdb_start] { | |
36 | continue | |
37 | } | |
38 | ||
39 | set testfile "basics" | |
40 | set srcfile ${testfile}.c | |
41 | set binfile ${objdir}/${subdir}/${testfile} | |
42 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } { | |
43 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
44 | } | |
45 | ||
46 | mi_delete_breakpoints | |
47 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
48 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
49 | mi_gdb_load ${binfile} | |
50 | ||
51 | proc test_breakpoints_creation_and_listing {} { | |
52 | global mi_gdb_prompt | |
53 | global srcfile | |
54 | global hex | |
55 | ||
56 | # Insert some breakpoints and list them | |
57 | # Also, disable some so they do not interfere with other tests | |
58 | # Tests: | |
59 | # -break-insert | |
60 | # -break-list | |
61 | # -break-disable | |
62 | # -break-info | |
63 | ||
64 | mi_gdb_test "200-break-insert main" \ | |
65 | "200\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"32\",times=\"0\"\}" \ | |
66 | "break-insert operation" | |
67 | ||
68 | mi_gdb_test "201-break-insert basics.c:callee2" \ | |
69 | "201\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee2\",file=\".*basics.c\",line=\"22\",times=\"0\"\}" \ | |
70 | "insert breakpoint at basics.c:callee2" | |
71 | ||
72 | mi_gdb_test "202-break-insert basics.c:15" \ | |
73 | "202\\^done,bkpt=\{number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee3\",file=\".*basics.c\",line=\"15\",times=\"0\"\}" \ | |
74 | "insert breakpoint at basics.c:15 (callee3)" | |
75 | ||
76 | mi_gdb_test "203-break-insert \"\\\"${srcfile}\\\":6\"" \ | |
77 | "203\\^done,bkpt=\{number=\"4\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"callee4\",file=\".*basics.c\",line=\"6\",times=\"0\"\}" \ | |
78 | "insert breakpoint at \"<fullfilename>\":6 (callee4)" | |
79 | ||
80 | mi_gdb_test "204-break-list" \ | |
cff22675 | 81 | "204\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"$hex\",func=\"main\",file=\".*basics.c\",line=\"32\",times=\"0\"\},.*\}\\\]\}" \ |
fb40c209 AC |
82 | "list of breakpoints" |
83 | ||
84 | mi_gdb_test "205-break-disable 2 3 4" \ | |
85 | "205\\^done.*" \ | |
86 | "disabling of breakpoints" | |
87 | ||
88 | mi_gdb_test "206-break-info 2" \ | |
cff22675 | 89 | "206\\^done,BreakpointTable=\{.*,hdr=\\\[.*\\\],body=\\\[bkpt=\{number=\"2\",.*,enabled=\"n\",.*\}\\\]\}" \ |
fb40c209 AC |
90 | "list of breakpoints, 16 disabled" |
91 | } | |
92 | ||
93 | proc test_running_the_program {} { | |
94 | global mi_gdb_prompt | |
95 | global hex | |
96 | ||
97 | # Run the program without args, then specify srgs and rerun the program | |
98 | # Tests: | |
99 | # -exec-run | |
100 | # -gdb-set | |
101 | ||
102 | # mi_gdb_test cannot be used for asynchronous commands because there are | |
103 | # two prompts involved and this can lead to a race condition. | |
104 | # The following is equivalent to a send_gdb "000-exec-run\n" | |
105 | mi_run_cmd | |
106 | gdb_expect { | |
fe766f11 | 107 | -re "000\\*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"\[01\]\",frame=\{addr=\"$hex\",func=\"main\",args=\\\[\\\],file=\".*basics.c\",line=\"32\"\}\r\n$mi_gdb_prompt$" { |
fb40c209 AC |
108 | pass "run to main" |
109 | } | |
e866d0e8 AC |
110 | -re ".*$mi_gdb_prompt$" { |
111 | fail "run to main (2)" | |
112 | } | |
fb40c209 AC |
113 | timeout { |
114 | fail "run to main (timeout)" | |
115 | } | |
116 | } | |
117 | } | |
118 | ||
119 | proc test_controlled_execution {} { | |
120 | global mi_gdb_prompt | |
121 | global hex | |
122 | ||
123 | # Continue execution until a breakpoint is reached, step into calls, verifying | |
124 | # if the arguments are correctly shown, continue to the end of a called | |
125 | # function, step over a call (next). | |
126 | # Tests: | |
127 | # -exec-continue | |
128 | # -exec-next | |
129 | # -exec-step | |
130 | # -exec-finish | |
131 | ||
dcf95b47 | 132 | mi_next_to "main" "" "basics.c" "33" "next at main" |
fb40c209 AC |
133 | |
134 | # FIXME: A string argument is not printed right; should be fixed and | |
135 | # we should look for the right thing here. | |
136 | # NOTE: The ``\\\\\"'' is for \". | |
dcf95b47 DJ |
137 | mi_step_to "callee1" \ |
138 | "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}" \ | |
139 | "basics.c" "27" "step at main" | |
fb40c209 AC |
140 | |
141 | # FIXME: A string argument is not printed right; should be fixed and | |
142 | # we should look for the right thing here. | |
fc5cfef4 | 143 | mi_execute_to "exec-step 3" "end-stepping-range" "callee4" "" \ |
dcf95b47 | 144 | "basics.c" "8" "" "step to callee4" |
fb40c209 AC |
145 | |
146 | # FIXME: A string argument is not printed right; should be fixed and | |
147 | # we should look for the right thing here. | |
148 | # NOTE: The ``.'' is part of ``gdb-result-var="$1"'' | |
dcf95b47 | 149 | mi_finish_to "callee3" ".*" "basics.c" "18" ".1" "0" "exec-finish" |
fb40c209 AC |
150 | } |
151 | ||
152 | proc test_controlling_breakpoints {} { | |
153 | global mi_gdb_prompt | |
154 | ||
155 | # Enable, delete, set ignore counts in breakpoints | |
156 | # (disable was already tested above) | |
157 | # Tests: | |
158 | # -break-delete | |
159 | # -break-enable | |
160 | # -break-after | |
161 | # -break-condition | |
162 | ||
163 | } | |
164 | ||
165 | proc test_program_termination {} { | |
166 | global mi_gdb_prompt | |
167 | ||
168 | # Run to completion: normal and forced | |
169 | # Tests: | |
170 | # -exec-abort | |
171 | # (normal termination of inferior) | |
172 | ||
173 | # FIXME: "stopped" doesn't seem appropriate. | |
174 | # mi_gdb_test cannot be used for asynchronous commands because there are | |
175 | # two prompts involved and this can lead to a race condition. | |
176 | send_gdb "999-exec-continue\n" | |
177 | gdb_expect { | |
178 | -re "999\\^running\r\n$mi_gdb_prompt" { | |
179 | gdb_expect { | |
180 | -re "999\\*stopped,reason=\"exited-normally\"\r\n$mi_gdb_prompt$" { | |
181 | pass "continue to end" | |
182 | } | |
183 | -re ".*$mi_gdb_prompt$" {fail "continue to end (2)"} | |
184 | timeout {fail "continue to end (timeout 2)"} | |
185 | } | |
186 | } | |
187 | -re ".*$mi_gdb_prompt$" {fail "continue to end (1)"} | |
188 | timeout {fail "continue to end (timeout 1)"} | |
189 | } | |
190 | } | |
191 | ||
192 | test_breakpoints_creation_and_listing | |
193 | test_running_the_program | |
194 | test_controlled_execution | |
195 | test_controlling_breakpoints | |
196 | test_program_termination | |
197 | ||
198 | mi_gdb_exit | |
199 | return 0 |