]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-console.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-console.exp
CommitLineData
1d506c26 1# Copyright 1999-2024 Free Software Foundation, Inc.
fb40c209
AC
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
fb40c209 6# (at your option) any later version.
e22f8b7c 7#
fb40c209
AC
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.
e22f8b7c 12#
fb40c209 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
fb40c209 15
17282693 16# Test inferior console output, with MI.
fb40c209
AC
17
18load_lib mi-support.exp
b30bf9ee 19set MIFLAGS "-i=mi"
fb40c209 20
6ec41e1e
LM
21#
22# Given STRING, return the semihosted version of that string.
23#
24proc semihosted_string { string } {
25 set semihosted_list {}
26 set leading_markers "@\""
27 set trailing_markers "\"\r\n"
28
29 if {$string != "" } {
30 set split_string [split $string ""]
31
32 foreach char $split_string {
33 # Escape special characters.
34 if {$char == "\\"} {
35 set char "\\\\\\\\"
36 } elseif {$char == "\r"} {
37 set char "\\\\r"
38 } elseif {$char == "\n"} {
39 set char "\\\\n"
40 } elseif {$char == "\""} {
41 set char "\\\\\""
42 }
43 lappend semihosted_list $leading_markers $char $trailing_markers
44 }
45 }
46 return [join $semihosted_list ""]
47}
48
298a9cf0
TT
49standard_testfile
50
9357e021 51if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
5b362f04 52 untested "failed to compile"
b60f0898 53 return -1
fb40c209
AC
54}
55
3ad2b4af
TT
56if {[mi_clean_restart $binfile]} {
57 return
58}
59
b75d55d4 60mi_runto_main
fb40c209 61
6ec41e1e
LM
62# The output we get from the target depends on how it is hosted. If
63# we are semihosted (e.g., the sim or a remote target that supports
64# the File I/O remote protocol extension), we see the target I/O
65# encapsulated in MI target output stream records. If debugging with
66# a native target, the inferior's I/O streams are connected directly
67# to a PTY we create for the inferior (notice separate-inferior-tty
68# above), and we just see the program's output unadorned. If
69# debugging with a remote target that doesn't support semihosting,
70# we'll see nothing.
71
72# The program's real output string.
73set program_output "Hello \\\"!\r\n"
74
75# Prepare the pattern for the PTY output of a native target.
76set native_output [string map {"\r\n" "\[\r\n\]+"} $program_output]
77set native_output [string map {"\\" "\\\\"} $native_output]
78
79# Prepare the pattern for the semihosted output.
80set semihosted_output [semihosted_string $program_output]
81
82# Combine both outputs in a single pattern.
83set output "($semihosted_output|$native_output)"
84
fb40c209 85# Next over the hello() call which will produce lots of output
bb378428 86mi_gdb_test "220-exec-next" \
e1ac3328 87 "220\\^running(\r\n\\*running,thread-id=\"all\")?" \
ecd3fd0f 88 "Testing console output" \
6ec41e1e 89 $output
fb40c209 90
d1fbcd56
AA
91set line [gdb_get_line_number "after-hello"]
92mi_expect_stop "end-stepping-range" "main" "" ".*mi-console.c" $line "" \
bb378428 93 "finished step over hello"
40e55bef 94
fb40c209 95mi_gdb_exit