1 # Copyright 1999-2024 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
20 # test running programs
23 require allow_cplus_tests
27 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
28 {debug c++ nowarnings}]} {
32 # This testcase cannot use runto_main because of the different prompt
33 # we get when using annotation level 2.
35 require target_can_use_run_cmd
37 set breakpoints_invalid "\r\n\032\032breakpoints-invalid\r\n"
38 set frames_invalid "\r\n\032\032frames-invalid\r\n"
41 # line number where we need to stop in main
45 # The commands we test here produce many lines of output; disable "press
46 # <return> to continue" prompts.
47 gdb_test_no_output "set height 0"
53 "Breakpoint.*at.* file .*$srcfile, line.*" \
58 # NOTE: this prompt is OK only when the annotation level is > 1
59 # NOTE: When this prompt is in use the gdb_test procedure cannot be used because
60 # it assumes that the last char of the gdb_prompt is a white space. This is not
61 # true with this annotated prompt. So we must use send_gdb and gdb_expect.
64 set old_gdb_prompt $gdb_prompt
65 set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"
67 send_gdb "set annotate 2\n"
69 -re "set annotate 2\r\n$gdb_prompt$" { pass "annotation set at level 2" }
70 -re ".*$gdb_prompt$" { fail "annotation set at level 2" }
71 timeout { fail "annotation set at level 2 (timeout)" }
74 gdb_test_multiple "run" "run until main breakpoint, first time" {
75 -re "$main_line.*$gdb_prompt$" {
81 # print class 'a' with public fields.
83 # annotate-field-begin
84 # annotate-field-name-end
85 # annotate-field-value
89 set pat [multi_line "" \
90 "\032\032post-prompt" \
92 "\032\032value-history-begin 1 -" \
94 "\032\032value-history-value" \
96 "\032\032field-begin -" \
98 "\032\032field-name-end" \
100 "\032\032field-value" \
102 "\032\032field-end" \
104 "\032\032field-begin -" \
106 "\032\032field-name-end" \
108 "\032\032field-value" \
110 "\032\032field-end" \
113 "\032\032value-history-end" \
116 gdb_test_multiple "print a" "print class" {
123 # continue until exit
126 # `a.x is 1' is asynchronous regarding to `frames-invalid'.
129 if { $gdb_spawn_id == $inferior_spawn_id } {
132 "\($frames_invalid\)*a.x is 1" \
133 "\($frames_invalid\)*"]
135 # Usually we'd handle this using gdb_test_stdio, but that looks too
136 # complicated in combination with annotations, so just ignore the inferior
138 set match_output "\($frames_invalid\)*"
141 set pat [multi_line "" \
142 "\032\032post-prompt" \
148 "$inferior_exited_re normally." \
150 "\032\032thread-exited,id=\"1\",group-id=\"i1\"" \
154 gdb_test_multiple "continue" "continue until exit" {
156 pass "continue until exit"
161 # delete all breakpoints, watchpoints, tracepoints, and catchpoints
165 -re ".*Delete all breakpoints, watchpoints, tracepoints, and catchpoints. \\(y or n\\) \r\n\032\032query.*$" {
168 -re "\r\n\032\032post-query\r\n${breakpoints_invalid}$gdb_prompt$" { pass "delete bps" }
169 -re ".*$gdb_prompt$" { fail "delete bps" }
170 timeout { fail "delete bps (timeout)" }
173 -re ".*$gdb_prompt$" { fail "delete bps" }
174 timeout { fail "delete bps (timeout)" }
178 # break at first line of main.
180 set pat [multi_line "" \
181 "\032\032post-prompt" \
182 "Breakpoint.*at $hex: file.*$srcfile, line.*" \
183 "\032\032breakpoints-invalid.*" \
186 gdb_test_multiple "break 22" "break at main" {
188 pass "breakpoint at main"
193 # change value of main_line
198 # run program up to breakpoint.
201 gdb_test_multiple "run" "run until main breakpoint, second time" {
202 -re "$main_line.*$gdb_prompt$" {
208 # set up a watch point on a.x
210 set pat [multi_line "" \
211 "\032\032post-prompt" \
212 ".*atchpoint 3: a.x" \
214 "\032\032breakpoints-invalid" \
216 gdb_test_multiple "watch a.x" "set watch on a.x" {
218 pass "set watch on a.x"
223 # do a next, so that the watchpoint triggers. This will test:
224 # annotate-watchpoint
226 set pat [multi_line "" \
227 "\032\032post-prompt" \
230 "\(${frames_invalid}\)*${breakpoints_invalid}\(${frames_invalid}\)*" \
231 "\032\032watchpoint 3" \
232 ".*atchpoint 3: a.x" \
237 "\032\032frame-begin 0 $hex" \
239 "\032\032frame-function-name" \
241 "\032\032frame-args" \
243 "\032\032frame-source-begin" \
245 "\032\032frame-source-file" \
247 "\032\032frame-source-file-end" \
249 "\032\032frame-source-line" \
251 "\032\032frame-source-end" \
254 "\032\032source .*$srcfile.*beg:$hex" \
256 "\032\032frame-end" \
261 gdb_test_multiple "next" "watch triggered on a.x" {
263 pass "watch triggered on a.x"
269 # send ^C to gdb, so that the quit() function gets called
270 # and annotate-quit is tested
274 if ![target_info exists gdb,nointerrupts] {
277 -re "\r\n\032\032error-begin\r\nQuit\r\n\r\n\032\032quit\r\n$gdb_prompt$" \
278 { pass "annotate-quit" }
279 -re ".*$gdb_prompt$" { fail "annotate-quit" }
280 timeout { fail "annotate-quit (timeout)" }
285 # FIXME: the testsuite does not currently have tests for
286 # annotate_catchpoints and annotate_function_call
287 # and a few variants of the annotations that are
288 # tested (marked by FIXME on the annot?.exp files)
291 # reinstall the old prompt for the rest of the testsuite.
293 set gdb_prompt $old_gdb_prompt