public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Handle \r\n in gdbreplay
@ 2019-02-21 14:05 Tom Tromey
  2019-02-21 15:14 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2019-02-21 14:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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(-)

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;
-- 
2.20.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle \r\n in gdbreplay
  2019-02-21 14:05 [PATCH] Handle \r\n in gdbreplay Tom Tromey
@ 2019-02-21 15:14 ` Eli Zaretskii
  2019-02-21 16:07   ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2019-02-21 15:14 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle \r\n in gdbreplay
  2019-02-21 15:14 ` Eli Zaretskii
@ 2019-02-21 16:07   ` Tom Tromey
  2019-02-21 16:12     ` Paul Koning
  2019-02-27 18:49     ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Tom Tromey @ 2019-02-21 16:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Tom Tromey, gdb-patches

>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

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

I normally handle \r this way out of habit I suppose.  It doesn't matter
that much to me, I guess \r isn't likely to be seen or made by accident.

Tom

commit eb7112d0f11809c25f415fa4f48aa6abe5fd84a4
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Feb 20 14:29:23 2019 -0700

    Handle \r\n in gdbreplay
    
    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\n line termination when
    reading the log file.
    
    gdb/gdbserver/ChangeLog
    2019-02-21  Tom Tromey  <tromey@adacore.com>
    
            * gdbreplay.c (logchar): Handle \r\n.

diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index e9fe5ab03f0..be0d0e293b2 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,7 @@
+2019-02-21  Tom Tromey  <tromey@adacore.com>
+
+	* gdbreplay.c (logchar): Handle \r\n.
+
 2019-02-07  Alan Hayward  <alan.hayward@arm.com>
 
 	* linux-low.c (linux_attach): Add process before lwp.
diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index 26a55533ff6..bda8095839c 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -316,10 +316,26 @@ logchar (FILE *fp)
   int ch2;
 
   ch = fgetc (fp);
-  fputc (ch, stdout);
-  fflush (stdout);
+  if (ch != '\r')
+    {
+      fputc (ch, stdout);
+      fflush (stdout);
+    }
   switch (ch)
     {
+      /* Treat \r\n as a newline.  */
+    case '\r':
+      ch = fgetc (fp);
+      if (ch == '\n')
+	ch = EOL;
+      else
+	{
+	  ungetc (ch, fp);
+	  ch = '\r';
+	}
+      fputc (ch == EOL ? '\n' : '\r', stdout);
+      fflush (stdout);
+      break;
     case '\n':
       ch = EOL;
       break;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle \r\n in gdbreplay
  2019-02-21 16:07   ` Tom Tromey
@ 2019-02-21 16:12     ` Paul Koning
  2019-02-27 18:49     ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Koning @ 2019-02-21 16:12 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Eli Zaretskii, gdb-patches



> On Feb 21, 2019, at 11:06 AM, Tom Tromey <tromey@adacore.com> wrote:
> 
>>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:
> 
> Eli> I'm okay with treating \r\n as a single \n, but do we really want to
> Eli> treat a single \r as if it were \n?  I thought systems which used that
> Eli> EOL convention are not really widespread, to say the least.
> 
> I normally handle \r this way out of habit I suppose.  It doesn't matter
> that much to me, I guess \r isn't likely to be seen or made by accident.

Supposedly \r alone is newline in Mac OS 9 and before, which at this point is sufficiently ancient history it may no longer be interesting.

	paul

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Handle \r\n in gdbreplay
  2019-02-21 16:07   ` Tom Tromey
  2019-02-21 16:12     ` Paul Koning
@ 2019-02-27 18:49     ` Tom Tromey
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2019-02-27 18:49 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Eli Zaretskii, gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> commit eb7112d0f11809c25f415fa4f48aa6abe5fd84a4
Tom> Author: Tom Tromey <tromey@adacore.com>
Tom> Date:   Wed Feb 20 14:29:23 2019 -0700

Tom>     Handle \r\n in gdbreplay
    
[...]

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-27 18:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21 14:05 [PATCH] Handle \r\n in gdbreplay Tom Tromey
2019-02-21 15:14 ` Eli Zaretskii
2019-02-21 16:07   ` Tom Tromey
2019-02-21 16:12     ` Paul Koning
2019-02-27 18:49     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).