]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-console.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-console.exp
1 # Copyright 1999-2016 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 inferior console output, with MI.
17
18 load_lib mi-support.exp
19 set MIFLAGS "-i=mi"
20
21 #
22 # Given STRING, return the semihosted version of that string.
23 #
24 proc 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
49 gdb_exit
50 if [mi_gdb_start separate-inferior-tty] {
51 continue
52 }
53
54 standard_testfile
55
56 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
57 untested mi-console.exp
58 return -1
59 }
60
61 mi_run_to_main
62
63 # The output we get from the target depends on how it is hosted. If
64 # we are semihosted (e.g., the sim or a remote target that supports
65 # the File I/O remote protocol extension), we see the target I/O
66 # encapsulated in MI target output stream records. If debugging with
67 # a native target, the inferior's I/O streams are connected directly
68 # to a PTY we create for the inferior (notice separate-inferior-tty
69 # above), and we just see the program's output unadorned. If
70 # debugging with a remote target that doesn't support semihosting,
71 # we'll see nothing.
72
73 # The program's real output string.
74 set program_output "Hello \\\"!\r\n"
75
76 # Prepare the pattern for the PTY output of a native target.
77 set native_output [string map {"\r\n" "\[\r\n\]+"} $program_output]
78 set native_output [string map {"\\" "\\\\"} $native_output]
79
80 # Prepare the pattern for the semihosted output.
81 set semihosted_output [semihosted_string $program_output]
82
83 # Combine both outputs in a single pattern.
84 set output "($semihosted_output|$native_output)"
85
86 # Next over the hello() call which will produce lots of output
87 mi_gdb_test "220-exec-next" \
88 "220\\^running(\r\n\\*running,thread-id=\"all\")?" \
89 "Testing console output" \
90 $output
91
92 set line [gdb_get_line_number "after-hello"]
93 mi_expect_stop "end-stepping-range" "main" "" ".*mi-console.c" $line "" \
94 "finished step over hello"
95
96 mi_gdb_exit
97 return 0