This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Improve MI inferior output check / mi-console.exp
- From: Luis Machado <lgustavo at codesourcery dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: "'gdb-patches at sourceware dot org'" <gdb-patches at sourceware dot org>, iain at codesourcery dot com
- Date: Wed, 30 Oct 2013 10:30:09 -0200
- Subject: Re: [PATCH] Improve MI inferior output check / mi-console.exp
- Authentication-results: sourceware.org; auth=none
- References: <526DC9BB dot 6060100 at codesourcery dot com> <526E7DF2 dot 4050509 at redhat dot com> <526ECC81 dot 3000300 at codesourcery dot com> <526F974C dot 9030404 at redhat dot com>
- Reply-to: lgustavo at codesourcery dot com
On 10/29/2013 09:09 AM, Pedro Alves wrote:
On 10/28/2013 08:43 PM, Luis Machado wrote:
*sigh*, that is true. I think fiddling with these checks may not be ideal.
What about this simpler version that just checks for both patterns
without other changes?
2013-10-28 Iain Sandoe <iain@codesourcery.com>
Luis Machado <lgustavo@codesourcery.com>
gdb/testsuite
* gdb.mi/mi-console.exp: Check for an additional inferior
output pattern.
I suggest:
* gdb.mi/mi-console.exp: Check for semihosted inferior
output pattern.
Done.
diff --git a/gdb/testsuite/gdb.mi/mi-console.exp b/gdb/testsuite/gdb.mi/mi-console.exp
index b7643e7..c9a1a84 100644
--- a/gdb/testsuite/gdb.mi/mi-console.exp
+++ b/gdb/testsuite/gdb.mi/mi-console.exp
@@ -36,11 +36,20 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
mi_run_to_main
+# The output we get from the target depends on how it is hosted.
+# If we are local, we just see the executable's output.
+# If we are remote (and the configuration supports semihosting),
+# we see the target responses encapsulated by gdb's annotation.
+# Therefore we consider two patterns here.
Not only remote, but the sim, or any other semihosted configuration.
I think it'd be good to make the comment and variable names reflect
that, and be more precise, making it a easier for future
maintainers. So:
# 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.
set semihosted_output "@\"H\"\r\n@\"e\"\r\n@\"l\"\r\n@\"l\"\r\n@\"o\"\r\n@\" \"\r\n@\"\\\\\\\\\"\r\n@\"\\\\\"\"\r\n@\"!\"\r\n@\"\\\\r\"\r\n@\"\\\\n\"\r\n"
set output "Hello \\\\\"!\[\r\n\]+"
set both_patterns "($semihosted_output|$output)"
This is OK with that change, though I'd prefer if $semihosted_output
was computed from $output...
The following patch accomplishes that and tweaks things a little further.
First, i removed the misleading test description. It does not seem to be
aligned with what the test does nowadays. It is not restricted to
remote/sim targets anymore.
I've put back the mi-support.exp bit since that is required for remote
targets, otherwise we will try to read from the spawn id.
I'm explicitly checking for "remote" and "extended-remote" gdb_protocol
values here since neither "isremote" nor "use_gdb_stub" seem to have a
consistent meaning. Extended-remote should be both "use_gdb_stub" and
"isremote", but it isn't.
Hopefully this version also addresses the gdb-simulator vs rsp-simulator
confusion.
I regression tested this with native gdb (full passes), native-gdbserver
(4 passes and 1 unsupported), native-extended-gdbserver (4 passes and 1
unsupported) and also in our semihosted-enabled target (full passes).
WDYT?
2013-10-30 Luis Machado <lgustavo@codesourcery.com>
* lib/mi-support.exp (mi_gdb_test): Expect different formats
of inferior output for remote and native sessions.
* gdb.mi/mi-console.exp: Remove obsolete comment.
Check for semihosted inferior output pattern.
(semihosted_string): New function.
diff --git a/gdb/testsuite/gdb.mi/mi-console.exp b/gdb/testsuite/gdb.mi/mi-console.exp
index b7643e7..bce285d 100644
--- a/gdb/testsuite/gdb.mi/mi-console.exp
+++ b/gdb/testsuite/gdb.mi/mi-console.exp
@@ -14,14 +14,38 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test inferior console output, with MI.
-#
-# This test only works when talking to a target that routes its output
-# through GDB. Check that we're either talking to a simulator or a
-# remote target.
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
@@ -36,11 +60,34 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
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 output [string map {"\r\n" "\[\r\n\]+"} $program_output]
+set output [string map {"\\" "\\\\"} $output]
+
+# Prepare the pattern for the semihosted output.
+set semihosted_output [semihosted_string $program_output]
+
+# Combine both outputs in a single pattern.
+set both_patterns "($semihosted_output|$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" \
- "Hello \\\\\"!\[\r\n\]+"
+ $both_patterns
mi_expect_stop "end-stepping-range" "main" "" ".*mi-console.c" "14" "" \
"finished step over hello"
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 3d55609..2ca7d52 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -764,7 +764,22 @@ proc mi_gdb_test { args } {
# If the GDB output matched, compare the inferior output.
if { $result == 0 } {
if [ info exists ipattern ] {
- if { ![target_info exists gdb,noinferiorio] } {
+ if { [target_info gdb_protocol] == "remote"
+ || [target_info gdb_protocol] == "extended-remote"} {
+ if { [target_info exists gdb,noinferiorio] } {
+ unsupported "$message inferior output"
+ } else {
+ gdb_expect {
+ -re "$ipattern" {
+ pass "$message inferior output"
+ }
+ timeout {
+ fail "$message inferior output (timeout)"
+ set result 1
+ }
+ }
+ }
+ } else {
global mi_inferior_spawn_id
expect {
-i $mi_inferior_spawn_id -re "$ipattern" {
@@ -775,8 +790,6 @@ proc mi_gdb_test { args } {
set result 1
}
}
- } else {
- unsupported "$message inferior output"
}
}
}