* lib/mi-support.exp (mi_gdb_test): Expect different formats
authorLuis Machado <lgustavo@codesourcery.com>
Fri, 15 Nov 2013 21:41:07 +0000 (19:41 -0200)
committerLuis Machado <lgustavo@codesourcery.com>
Fri, 15 Nov 2013 21:41:07 +0000 (19:41 -0200)
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.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-console.exp
gdb/testsuite/lib/mi-support.exp

index 5ab2656cd5a6650cb4d5f2850f043eb7978891c2..e592cec018a528077e6c9317be40cb4e54604b54 100644 (file)
@@ -1,3 +1,11 @@
+2013-11-15  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.
+
 2013-11-15  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.ada/info_exc.exp: Allow other global exceptions to be
index b7643e72d7618a0bcf0fa5da52c0ef273523d7c0..47b0677278ec3dbe0536767c05f4568ed1aa679f 100644 (file)
 # 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 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" \
-           "Hello \\\\\"!\[\r\n\]+"
+           $output
 
 mi_expect_stop "end-stepping-range" "main" "" ".*mi-console.c" "14" "" \
     "finished step over hello"
index 3d55609bd14592805c4bc3d16ab9561f62de725d..881e16e95f40db38ef327d237b76837fc0deaa7c 100644 (file)
@@ -765,20 +765,35 @@ proc mi_gdb_test { args } {
     if { $result == 0 } {
        if [ info exists ipattern ] {
            if { ![target_info exists gdb,noinferiorio] } {
-               global mi_inferior_spawn_id
-               expect {
-                   -i $mi_inferior_spawn_id -re "$ipattern" {
-                       pass "$message inferior output"
+               if { [target_info gdb_protocol] == "remote"
+                   || [target_info gdb_protocol] == "extended-remote"
+                   || [target_info protocol] == "sim"} {
+
+                   gdb_expect {
+                       -re "$ipattern" {
+                           pass "$message inferior output"
+                       }
+                       timeout {
+                           fail "$message inferior output (timeout)"
+                           set result 1
+                       }
                    }
-                   timeout {
-                       fail "$message inferior output (timeout)"
-                       set result 1
+               } else {
+                   global mi_inferior_spawn_id
+                   expect {
+                       -i $mi_inferior_spawn_id -re "$ipattern" {
+                           pass "$message inferior output"
+                       }
+                       timeout {
+                           fail "$message inferior output (timeout)"
+                           set result 1
+                       }
                    }
                }
            } else {
                unsupported "$message inferior output"
            }
-        }
+       }
     }
 
     return $result