Handle \r\n in gdbreplay

Message ID 20190221140513.29508-1-tromey@adacore.com
State New, archived
Headers

Commit Message

Tom Tromey Feb. 21, 2019, 2:05 p.m. UTC
  I tried gdbreplay yesterday, but the remotelogfile I received was made
on Windows, so the lines were terminated with \r\n rather than plain
\n.

This patch changes gdbreplay to allow \r or \r\n line termination when
reading the log file.

gdb/gdbserver/ChangeLog
2019-02-21  Tom Tromey  <tromey@adacore.com>

	* gdbreplay.c (logchar): Handle \r and \r\n.
---
 gdb/gdbserver/ChangeLog   |  4 ++++
 gdb/gdbserver/gdbreplay.c | 15 +++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)
  

Comments

Eli Zaretskii Feb. 21, 2019, 3:14 p.m. UTC | #1
> From: Tom Tromey <tromey@adacore.com>
> Cc: Tom Tromey <tromey@adacore.com>
> Date: Thu, 21 Feb 2019 07:05:13 -0700
> 
> I tried gdbreplay yesterday, but the remotelogfile I received was made
> on Windows, so the lines were terminated with \r\n rather than plain
> \n.
> 
> This patch changes gdbreplay to allow \r or \r\n line termination when
> reading the log file.

I'm okay with treating \r\n as a single \n, but do we really want to
treat a single \r as if it were \n?  I thought systems which used that
EOL convention are not really widespread, to say the least.

Thanks.
  

Patch

diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index 26a55533ff6..b1a9401909c 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -316,10 +316,21 @@  logchar (FILE *fp)
   int ch2;
 
   ch = fgetc (fp);
-  fputc (ch, stdout);
-  fflush (stdout);
+  if (ch != '\r')
+    {
+      fputc (ch, stdout);
+      fflush (stdout);
+    }
   switch (ch)
     {
+      /* Treat all of \r, \n, and \r\n as a newline.  */
+    case '\r':
+      ch = fgetc (fp);
+      if (ch != '\n')
+	ungetc (ch, fp);
+      fputc ('\n', stdout);
+      fflush (stdout);
+      /* Fall through.  */
     case '\n':
       ch = EOL;
       break;