Fix double prompt
[external/binutils.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             -notransfer -re "<return>" {
79                 # Otherwise gdb_test_multiple considers this an error.
80                 exp_continue
81             }
82         }
83
84         # We're now stopped in a pagination query while handling a
85         # target event (printing where the program stopped).  Quitting
86         # the pagination should result in only one prompt being
87         # output.
88         send_gdb "\003p 1\n"
89
90         set test "no double prompt"
91         gdb_test_multiple "" $test {
92             -re "$gdb_prompt.*$gdb_prompt.*$gdb_prompt $" {
93                 fail $test
94             }
95             -re "$gdb_prompt .* = 1\r\n$gdb_prompt $" {
96                 pass $test
97             }
98             -notransfer -re "<return>" {
99                 # Otherwise gdb_test_multiple considers this an error.
100                 exp_continue
101             }
102         }
103
104         # In case the board file wants to send further commands.
105         gdb_test_no_output "set height unlimited"
106     }
107 }
108
109 foreach variant { "continue" "wrapcont" } {
110     cancel_pagination_in_target_event $variant
111 }