aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/annota-input-while-running.exp
blob: 0aa0aa2ce075795e4b57abd65353a8e2aeb65227 (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
107
108
109
110
111
112
113
114
115
116
117
# Copyright 1999-2019 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/>.

# Test that annotations support doesn't leave GDB's terminal settings
# into effect when we run a foreground command.

standard_testfile

if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug] == -1} {
    return -1
}

# Because runto_main doesn't know how to handle the prompt with annotations,
# run to main before we set the annotation level.
if ![runto_main] then {
   fail "can't run to main"
   return 1
}

# NOTE: this prompt is OK only when the annotation level is > 1
# NOTE: When this prompt is in use the gdb_test procedure cannot be
# used because it assumes that the last char after the gdb_prompt is a
# white space.  This is not true with this annotated prompt.  So we
# must use the gdb_annota_test replacement below, or
# gdb_test_multiple.

set old_gdb_prompt $gdb_prompt
set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n"

# Like gdb_test, but cope with the annotation prompt.
proc gdb_annota_test {command pattern message} {
    global gdb_prompt

    gdb_test_multiple $command $message {
	-re "$pattern$gdb_prompt$" {
	    pass "$message"
	}
	-re "$gdb_prompt$" {
	    fail "$message"
	}
    }
}

# Set the annotation level to 2.
gdb_annota_test "set annotate 2" ".*" "annotation set at level 2"

set test "delete breakpoints"
gdb_test_multiple "delete" $test {
    -re "Delete all breakpoints. .y or n." {
	send_gdb "y\n"
	exp_continue
    }
    -re "$gdb_prompt$" {
	pass $test
    }
}

# Set the target running, and then type something.  GDB used to have a
# bug where it'd be accepting input even though the target was
# supposedly resumed in the foreground.  This ultimately resulted in
# readline aborting.

set linenum [gdb_get_line_number "set break here"]

gdb_annota_test "break $linenum" \
    "Breakpoint .*$srcfile, line .*" \
    "break after sleep"

# Continue, and wait a bit to make sure the inferior really starts
# running.  Wait less than much the program sleeps, which is 5
# seconds, though.
set saw_continuing 0
set test "continue"
gdb_test_multiple $test $test {
    -timeout 2
    -re "Continuing\\." {
	set saw_continuing 1
	exp_continue
    }
    timeout {
	gdb_assert $saw_continuing $test
    }
}

# Type something.
send_gdb "print 1\n"

# Poor buggy GDB would crash before the breakpoint was hit.
set test "breakpoint hit"
gdb_test_multiple "" $test {
    -re "stopped\r\n$gdb_prompt" {
	pass $test
    }
}

set test "print command result"
gdb_test_multiple "" $test {
    -re "\r\n1\r\n\r\n\032\032value-history-end\r\n$gdb_prompt" {
	pass $test
    }
}

# Restore the original prompt for the rest of the testsuite.

set gdb_prompt $old_gdb_prompt