1# Copyright 2017-2020 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# When debugging with "target remote |", the inferior's output is
17# connected to a pipe, and if GDB doesn't flush the pipe while the
18# inferior is running and the pipe becomes full, then the inferior
19# deadlocks:
20#
21#  1. User sets breakpoint, and types "continue"
22#
23#  2. Inferior prints to stdout/stderr before reaching breakpoint
24#     location.
25#
26#  3. The output pipe becomes full, so the inferior blocks forever in
27#     the printf/write call.
28#
29#  4. The breakpoint is never reached.
30
31if [target_info exists gdb,noinferiorio] {
32    verbose "Skipping because of noinferiorio."
33    return
34}
35
36standard_testfile
37
38if [prepare_for_testing "failed to prepare" $testfile {} {debug}] {
39    return -1
40}
41
42if { ![runto_main] } then {
43    fail "run to main"
44    return
45}
46
47set printing_done_line [gdb_get_line_number "printing done"]
48gdb_test "break $printing_done_line" ".*" "set breakpoint after printing"
49
50send_gdb "continue\n"
51
52set expected_lines 3000
53set more 1
54set i 0
55while {$more} {
56    set more 0
57    gdb_expect {
58	-i $inferior_spawn_id
59	-ex "this is line number $i" {
60	    incr i
61           if {$i != $expected_lines} {
62		set more 1
63	    }
64	}
65    }
66}
67
68gdb_assert {$i == $expected_lines} "saw all lines"
69
70set test "breakpoint reached"
71gdb_test_multiple "" $test {
72    -re "Breakpoint .* main .*$srcfile:$printing_done_line.*$gdb_prompt $" {
73	pass $test
74    }
75}
76