summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/eof-exit.exp
blob: e04c38bf8d78b6f6be0cd49c7ea4b06674f4f67e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (C) 2022 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This test script checks how GDB handles exiting with ctrl-d.

# Start GDB, and then close it by sendig ctrl-d.  Check that the
# string 'quit' appears where we expect it too.
proc run_test {} {
    clean_restart

    # The gdb_start call above swallows the GDB prompt, and we want
    # the prompt for the test below.
    #
    # Send a newline character, which will cause GDB to redisplay the
    # prompt.
    #
    # We then consume the newline characters, and then make use of
    # expect's -notransfer option to ensure that the prompt has been
    # displayed, but to leave the prompt in expect's internal buffer.
    # This is important as the following test wants to check how GDB
    # displays the 'quit' message relative to the prompt, this is much
    # easier to do if the prompt is still in expect's buffers.
    #
    # The other special thing we do here is avoid printing a 'PASS'
    # result.  The reason for this is so that the GDB output in the
    # log file will match what a user should see, this makes it much
    # easier to debug issues.  Obviously we could print a 'PASS' here
    # as the text printed by expect is not considered part of GDB's
    # output, so the pattern matching will work just fine... but, the
    # log file becomes much harder to read.
    send_gdb "\n"
    gdb_test_multiple "" "discard newline" {
	-re "^\r\n" {
	    exp_continue
	}
	-notransfer -re "^\[^\n\]*$::gdb_prompt $" {
	}
    }

    # Send GDB a ctrl-d.  Check that we see the 'quit' string in the
    # expected place.
    send_gdb "\004"
    gdb_test_multiple "" "close GDB with eof" {
	-re "$::gdb_prompt \[^\n\]*\r\[^\n\]*quit" {
	    fail "$gdb_test_name (misplaced \\r)"
	}
	-re "$::gdb_prompt (?:\[^\n\]*\r)?\[^\n\]*\r\nquit\r\n" {
	    # For versions of readline that don't include the
	    # RL_STATE_EOF patch, then the 'quit' is printed on the
	    # subsequent line.
	    kfail gdb/28833 "$gdb_test_name (older version of readline)"
	}
	-re "$::gdb_prompt quit\[^\n\]*\r\n\[^\n\]*\r\n$" {
	    # There was a bug where GDB would print an extra blank
	    # line after the 'quit', this catches that case.
	    fail $gdb_test_name
	}
       -re "$::gdb_prompt \[^\n\r\]*quit\[^\n\]*\r\n\[^\n\]*$" {
	    pass $gdb_test_name
	}
	eof {
	    fail "$gdb_test_name (missed the prompt)"
	}
    }
}

with_test_prefix "default" {
    run_test
}

save_vars { env(TERM) } {
    setenv TERM ansi

    with_test_prefix "with non-dump terminal" {
	run_test

	save_vars { env(INPUTRC) } {

	    # Create an inputrc file that turns bracketed paste mode
	    # on.  This is usually turned off (see lib/gdb.exp), but
	    # for the next test we want to see what happens with this
	    # on.
	    set inputrc [standard_output_file inputrc]
	    set fd [open "$inputrc" w]
	    puts $fd "set enable-bracketed-paste on"
	    close $fd

	    setenv INPUTRC "$inputrc"
	    with_test_prefix "with bracketed-paste-mode on" {
		run_test
	    }
	}
    }
}