]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/double-prompt-target-event-error.exp
84c6c45a1d886a2f3fdb0d9524653eda7fb152e9
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / double-prompt-target-event-error.exp
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
16 standard_testfile
17
18 if {[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
29 proc 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 }
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
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.
97 set test "no double prompt"
98 gdb_test_multiple "" $test {
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.
103 fail $test
104 }
105 -re " = 1\r\n$gdb_prompt $" {
106 pass $test
107 }
108 }
109
110 # In case the board file wants to send further commands.
111 gdb_test_no_output "set height unlimited"
112 }
113 }
114
115 foreach variant { "continue" "wrapcont" } {
116 cancel_pagination_in_target_event $variant
117 }