Fix paginate-*.exp races
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / double-prompt-target-event-error.exp
CommitLineData
1e973570
PA
1# Copyright (C) 2014 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 3 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, see <http://www.gnu.org/licenses/>.
15
16standard_testfile
17
18if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug] == -1} {
19 return -1
20}
21
22# Test throwing an error while GDB is handling a target event. We use
23# a ctrl-c/quit in a pagination prompt to emulate an error. COMMAND
24# is either "continue" or "wrapcont". The latter is a continue issued
25# from a user-defined command. That exercises the case of the
26# interpreter forced sync, which was the case that originally had a
27# bug.
28
29proc cancel_pagination_in_target_event { command } {
30 global binfile srcfile
31 global gdb_prompt pagination_prompt
32
33 set testline [gdb_get_line_number "after sleep"]
34
35 with_test_prefix "ctrlc target event: $command" {
36 clean_restart $binfile
37
38 if ![runto_main] then {
39 fail "Can't run to main"
40 return 0
41 }
42
43 gdb_test "b $srcfile:$testline" \
44 "Breakpoint .*$srcfile, line $testline.*" \
45 "set breakpoint"
46
47 gdb_test_no_output "set height 2"
48
49 if { $command == "wrapcont" } {
50 gdb_test_multiple "define wrapcont" "define user command: wrapcont" {
51 -re "Type commands for definition of \"wrapcont\".\r\nEnd with a line saying just \"end\".\r\n>$" {
52 # Note that "Continuing." is ommitted when
53 # "continue" is issued from a user-defined
54 # command. Issue it ourselves.
55 gdb_test "echo Continuing\.\ncontinue\nend" "" \
56 "define user command: wrapcont"
57 }
58 }
59 }
60
61 # Wait for pagination prompt after the "Continuing" line,
62 # indicating the program was running and then stopped.
63 set saw_continuing 0
64 set test "continue to pagination"
65 gdb_test_multiple "$command" $test {
66 -re "$pagination_prompt$" {
67 if {$saw_continuing} {
68 pass $test
69 } else {
70 send_gdb "\n"
71 exp_continue
72 }
73 }
74 -re "Continuing" {
75 set saw_continuing 1
76 exp_continue
77 }
1e973570
PA
78 }
79
80 # We're now stopped in a pagination query while handling a
81 # target event (printing where the program stopped). Quitting
82 # the pagination should result in only one prompt being
83 # output.
84 send_gdb "\003p 1\n"
85
c3f814a1
PA
86 # Note gdb_test_multiple has a default match for the prompt,
87 # which issues a FAIL. Consume the first prompt.
88 set test "first prompt"
89 gdb_test_multiple "" $test {
90 -re "$gdb_prompt" {
91 pass "first prompt"
92 }
93 }
94
95 # We should only see one prompt more, and it should be
96 # preceeded by print's output.
1e973570
PA
97 set test "no double prompt"
98 gdb_test_multiple "" $test {
c3f814a1
PA
99 -re "$gdb_prompt.*$gdb_prompt $" {
100 # The bug is present, and expect managed to read
101 # enough characters into the buffer to fill it with
102 # both prompts.
1e973570
PA
103 fail $test
104 }
c3f814a1 105 -re " = 1\r\n$gdb_prompt $" {
1e973570
PA
106 pass $test
107 }
1e973570
PA
108 }
109
110 # In case the board file wants to send further commands.
111 gdb_test_no_output "set height unlimited"
112 }
113}
114
115foreach variant { "continue" "wrapcont" } {
116 cancel_pagination_in_target_event $variant
117}
This page took 0.03049 seconds and 4 git commands to generate.