[PATCH 2/4] Transform "\r\n" in pattern to "\r+\n"

Yao Qi
2013-09-17T13:07:41Z

This patch transforms the "\r\n" in pattern to "\r+\n". Note that
"\r\n" in variable can't be transformed by this patch.

gdb/testsuite:

2013-09-17 Yao Qi <yao@codesourcery.com>

* lib/gdb.exp (gdb_transform_eol): New proc.
(gdb_expect): Invoke gdb_transform_eol.
* lib/mi-support.exp (mi_gdb_test): Likewise.
---
gdb/testsuite/lib/gdb.exp | 22 ++++++++++++++++++++++
gdb/testsuite/lib/mi-support.exp | 2 ++
2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 9b319e2..30d8755 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2903,6 +2903,26 @@ proc send_gdb { string } {
return [remote_send host "$string"]
}

+# Transform the end-of-line in PATTERN. In test cases, we assume
+# that end-of-line is "\r\n", but that is not true on some targets.
+# this proc transforms "\r\n" to the desired form.
+
+proc gdb_transform_eol { pattern } {
+
+ if [ishost "i?86-*-mingw*"] {
+ # On Windows, when a file is opened in text mode, a "\n" is
+ # always expanded to "\r\n", so gdb on Windows is outputting
+ # "\r\n", and when that goes through the PTY, the '\n' is
+ # being expanded to "\r\n", hence "\r\r\n".
+ # Expand "\r\n" in $expcode to "\r+\n" in order to match
+ # "\r\r\n".
+ regsub -all {\\r\\n} $pattern {\\r+\\n} pattern
+ regsub -all {\r\n} $pattern {\r+\n} pattern
+ }
+
+ return $pattern
+}
+
#
#

@@ -2914,6 +2934,8 @@ proc gdb_expect { args } {
set expcode $args
}

+ set expcode [gdb_transform_eol $expcode]
+
upvar timeout timeout

if [target_info exists gdb,timeout] {
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 86a0fd6..a9b22c2 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -597,6 +597,8 @@ proc mi_gdb_test { args } {
set question_string "^FOOBAR$"
}

+ set pattern [gdb_transform_eol $pattern]
+
if $verbose>2 then {
send_user "Sending \"$command\" to gdb\n"
send_user "Looking to match \"$pattern\"\n"
--
1.7.7.6