mi-console.exp revision 1.1 1 1.1 christos # Copyright 1999-2014 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # Test inferior console output, with MI.
17 1.1 christos
18 1.1 christos load_lib mi-support.exp
19 1.1 christos set MIFLAGS "-i=mi"
20 1.1 christos
21 1.1 christos #
22 1.1 christos # Given STRING, return the semihosted version of that string.
23 1.1 christos #
24 1.1 christos proc semihosted_string { string } {
25 1.1 christos set semihosted_list {}
26 1.1 christos set leading_markers "@\""
27 1.1 christos set trailing_markers "\"\r\n"
28 1.1 christos
29 1.1 christos if {$string != "" } {
30 1.1 christos set split_string [split $string ""]
31 1.1 christos
32 1.1 christos foreach char $split_string {
33 1.1 christos # Escape special characters.
34 1.1 christos if {$char == "\\"} {
35 1.1 christos set char "\\\\\\\\"
36 1.1 christos } elseif {$char == "\r"} {
37 1.1 christos set char "\\\\r"
38 1.1 christos } elseif {$char == "\n"} {
39 1.1 christos set char "\\\\n"
40 1.1 christos } elseif {$char == "\""} {
41 1.1 christos set char "\\\\\""
42 1.1 christos }
43 1.1 christos lappend semihosted_list $leading_markers $char $trailing_markers
44 1.1 christos }
45 1.1 christos }
46 1.1 christos return [join $semihosted_list ""]
47 1.1 christos }
48 1.1 christos
49 1.1 christos gdb_exit
50 1.1 christos if [mi_gdb_start separate-inferior-tty] {
51 1.1 christos continue
52 1.1 christos }
53 1.1 christos
54 1.1 christos standard_testfile
55 1.1 christos
56 1.1 christos if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
57 1.1 christos untested mi-console.exp
58 1.1 christos return -1
59 1.1 christos }
60 1.1 christos
61 1.1 christos mi_run_to_main
62 1.1 christos
63 1.1 christos # The output we get from the target depends on how it is hosted. If
64 1.1 christos # we are semihosted (e.g., the sim or a remote target that supports
65 1.1 christos # the File I/O remote protocol extension), we see the target I/O
66 1.1 christos # encapsulated in MI target output stream records. If debugging with
67 1.1 christos # a native target, the inferior's I/O streams are connected directly
68 1.1 christos # to a PTY we create for the inferior (notice separate-inferior-tty
69 1.1 christos # above), and we just see the program's output unadorned. If
70 1.1 christos # debugging with a remote target that doesn't support semihosting,
71 1.1 christos # we'll see nothing.
72 1.1 christos
73 1.1 christos # The program's real output string.
74 1.1 christos set program_output "Hello \\\"!\r\n"
75 1.1 christos
76 1.1 christos # Prepare the pattern for the PTY output of a native target.
77 1.1 christos set native_output [string map {"\r\n" "\[\r\n\]+"} $program_output]
78 1.1 christos set native_output [string map {"\\" "\\\\"} $native_output]
79 1.1 christos
80 1.1 christos # Prepare the pattern for the semihosted output.
81 1.1 christos set semihosted_output [semihosted_string $program_output]
82 1.1 christos
83 1.1 christos # Combine both outputs in a single pattern.
84 1.1 christos set output "($semihosted_output|$native_output)"
85 1.1 christos
86 1.1 christos # Next over the hello() call which will produce lots of output
87 1.1 christos mi_gdb_test "220-exec-next" \
88 1.1 christos "220\\^running(\r\n\\*running,thread-id=\"all\")?" \
89 1.1 christos "Testing console output" \
90 1.1 christos $output
91 1.1 christos
92 1.1 christos mi_expect_stop "end-stepping-range" "main" "" ".*mi-console.c" "14" "" \
93 1.1 christos "finished step over hello"
94 1.1 christos
95 1.1 christos mi_gdb_exit
96 1.1 christos return 0
97