1# Copyright 1999-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# Test that annotations support doesn't leave GDB's terminal settings 17# into effect when we run a foreground command. 18 19standard_testfile 20 21if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug] == -1} { 22 return -1 23} 24 25# Because runto_main doesn't know how to handle the prompt with annotations, 26# run to main before we set the annotation level. 27if ![runto_main] then { 28 fail "can't run to main" 29 return 1 30} 31 32# NOTE: this prompt is OK only when the annotation level is > 1 33# NOTE: When this prompt is in use the gdb_test procedure cannot be 34# used because it assumes that the last char after the gdb_prompt is a 35# white space. This is not true with this annotated prompt. So we 36# must use the gdb_annota_test replacement below, or 37# gdb_test_multiple. 38 39set old_gdb_prompt $gdb_prompt 40set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" 41 42# Like gdb_test, but cope with the annotation prompt. 43proc gdb_annota_test {command pattern message} { 44 global gdb_prompt 45 46 gdb_test_multiple $command $message { 47 -re "$pattern$gdb_prompt$" { 48 pass "$message" 49 } 50 -re "$gdb_prompt$" { 51 fail "$message" 52 } 53 } 54} 55 56# Set the annotation level to 2. 57gdb_annota_test "set annotate 2" ".*" "annotation set at level 2" 58 59set test "delete breakpoints" 60gdb_test_multiple "delete" $test { 61 -re "Delete all breakpoints. .y or n." { 62 send_gdb "y\n" 63 exp_continue 64 } 65 -re "$gdb_prompt$" { 66 pass $test 67 } 68} 69 70# Set the target running, and then type something. GDB used to have a 71# bug where it'd be accepting input even though the target was 72# supposedly resumed in the foreground. This ultimately resulted in 73# readline aborting. 74 75set linenum [gdb_get_line_number "set break here"] 76 77gdb_annota_test "break $linenum" \ 78 "Breakpoint .*$srcfile, line .*" \ 79 "break after sleep" 80 81# Continue, and wait a bit to make sure the inferior really starts 82# running. Wait less than much the program sleeps, which is 5 83# seconds, though. 84set saw_continuing 0 85set test "continue" 86gdb_test_multiple $test $test { 87 -timeout 2 88 -re "Continuing\\." { 89 set saw_continuing 1 90 exp_continue 91 } 92 timeout { 93 gdb_assert $saw_continuing $test 94 } 95} 96 97# Type something. 98send_gdb "print 1\n" 99 100# Poor buggy GDB would crash before the breakpoint was hit. 101set test "breakpoint hit" 102gdb_test_multiple "" $test { 103 -re "stopped\r\n$gdb_prompt" { 104 pass $test 105 } 106} 107 108set test "print command result" 109gdb_test_multiple "" $test { 110 -re "\r\n1\r\n\r\n\032\032value-history-end\r\n$gdb_prompt" { 111 pass $test 112 } 113} 114 115# Restore the original prompt for the rest of the testsuite. 116 117set gdb_prompt $old_gdb_prompt 118