xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/paginate-bg-execution.exp (revision 1580a27b92f58fcdcb23fdfbc04a7c2b54a0b7c8)
1# Copyright (C) 2014-2015 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# A collection of tests related to running execution commands directly
17# from the command line, with "-ex".
18
19standard_testfile
20
21if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
22    return -1
23}
24
25# Check that we handle pagination correctly when it triggers due to an
26# background execution command entered directly on the command line.
27
28proc test_bg_execution_pagination_return {} {
29    global binfile
30    global pagination_prompt
31
32    with_test_prefix "paginate" {
33	clean_restart $binfile
34
35	if ![runto_main] then {
36	    fail "Can't run to main"
37	    return 0
38	}
39
40	gdb_test "b after_sleep"
41
42	gdb_test_no_output "set height 2"
43
44	gdb_test "continue&" "Continuing\."
45
46	set test "pagination handled, breakpoint hit"
47	set saw_pagination_prompt 0
48	gdb_test_multiple "" $test {
49	    -re "$pagination_prompt$" {
50		set saw_pagination_prompt 1
51		send_gdb "\n"
52		exp_continue
53	    }
54	    -re "after sleep\[^\r\n\]+\r\n$" {
55		gdb_assert $saw_pagination_prompt $test
56	    }
57	}
58
59	# GDB used to crash here.
60	gdb_test "p 1" " = 1" "GDB accepts further input"
61
62	# In case the board file wants to send further commands.
63	gdb_test_no_output "set height unlimited"
64    }
65}
66
67# Check that we handle canceling pagination correctly when it triggers
68# due to a background execution command entered directly on the
69# command line.
70
71proc test_bg_execution_pagination_cancel { how } {
72    global binfile
73    global gdb_prompt pagination_prompt
74
75    with_test_prefix "cancel with $how" {
76	clean_restart $binfile
77
78	if ![runto_main] then {
79	    fail "Can't run to main"
80	    return 0
81	}
82
83	gdb_test "b after_sleep"
84
85	gdb_test_no_output "set height 2"
86
87	gdb_test "continue&" "Continuing\."
88
89	set test "continue& paginates"
90	gdb_test_multiple "" $test {
91	    -re "$pagination_prompt$" {
92		pass $test
93	    }
94	}
95
96	set test "cancel pagination"
97	if { $how == "ctrl-c" } {
98	    send_gdb "\003"
99	} else {
100	    send_gdb "q\n"
101
102	}
103	gdb_test_multiple "" $test {
104	    -re "Quit\r\n$gdb_prompt $" {
105		pass $test
106	    }
107	}
108
109	gdb_test "p 1" " = 1" "GDB accepts further input"
110
111	# In case the board file wants to send further commands.
112	gdb_test_no_output "set height unlimited"
113    }
114}
115
116test_bg_execution_pagination_return
117test_bg_execution_pagination_cancel "ctrl-c"
118test_bg_execution_pagination_cancel "quit"
119