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
|
# 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 inferior console output, with MI.
load_lib mi-support.exp
set MIFLAGS "-i=mi"
#
# Given STRING, return the semihosted version of that string.
#
proc semihosted_string { string } {
set semihosted_list {}
set leading_markers "@\""
set trailing_markers "\"\r\n"
if {$string != "" } {
set split_string [split $string ""]
foreach char $split_string {
# Escape special characters.
if {$char == "\\"} {
set char "\\\\\\\\"
} elseif {$char == "\r"} {
set char "\\\\r"
} elseif {$char == "\n"} {
set char "\\\\n"
} elseif {$char == "\""} {
set char "\\\\\""
}
lappend semihosted_list $leading_markers $char $trailing_markers
}
}
return [join $semihosted_list ""]
}
gdb_exit
if [mi_gdb_start separate-inferior-tty] {
continue
}
standard_testfile
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
untested "failed to compile"
return -1
}
mi_run_to_main
# The output we get from the target depends on how it is hosted. If
# we are semihosted (e.g., the sim or a remote target that supports
# the File I/O remote protocol extension), we see the target I/O
# encapsulated in MI target output stream records. If debugging with
# a native target, the inferior's I/O streams are connected directly
# to a PTY we create for the inferior (notice separate-inferior-tty
# above), and we just see the program's output unadorned. If
# debugging with a remote target that doesn't support semihosting,
# we'll see nothing.
# The program's real output string.
set program_output "Hello \\\"!\r\n"
# Prepare the pattern for the PTY output of a native target.
set native_output [string map {"\r\n" "\[\r\n\]+"} $program_output]
set native_output [string map {"\\" "\\\\"} $native_output]
# Prepare the pattern for the semihosted output.
set semihosted_output [semihosted_string $program_output]
# Combine both outputs in a single pattern.
set output "($semihosted_output|$native_output)"
# Next over the hello() call which will produce lots of output
mi_gdb_test "220-exec-next" \
"220\\^running(\r\n\\*running,thread-id=\"all\")?" \
"Testing console output" \
$output
set line [gdb_get_line_number "after-hello"]
mi_expect_stop "end-stepping-range" "main" "" ".*mi-console.c" $line "" \
"finished step over hello"
mi_gdb_exit
return 0
|