[1/4] gdb: Fix skip of `\r` before `\n` in source output

Message ID bf75f988b1fad2b4a039a57b5bb6d082806addc0.1546860547.git.andrew.burgess@embecosm.com
State New, archived
Headers

Commit Message

Andrew Burgess Jan. 7, 2019, 12:42 p.m. UTC
  In this commit:

  commit 62f29fda90cf1d5a1899f57ef78452471c707fd6
  Date:   Tue Oct 9 22:21:05 2018 -0600

      Highlight source code using GNU Source Highlight

A bug was introduced such that when displaying source code from a file
with lines `\r\n` GDB would print `^M` at the end of each line.

This caused a regression on the test gdb.fortran/nested-funcs.exp,
which happens to have `\r\n` line endings.

gdb/ChangeLog:

	* source.c (print_source_lines_base): Fix skip of '\r' if next
	character is '\n'.
---
 gdb/ChangeLog | 5 +++++
 gdb/source.c  | 7 +------
 2 files changed, 6 insertions(+), 6 deletions(-)
  

Comments

Tom Tromey Jan. 8, 2019, 5:17 a.m. UTC | #1
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> This caused a regression on the test gdb.fortran/nested-funcs.exp,
Andrew> which happens to have `\r\n` line endings.

Andrew> gdb/ChangeLog:

Andrew> 	* source.c (print_source_lines_base): Fix skip of '\r' if next
Andrew> 	character is '\n'.

Thanks,  This is ok.

Tom
  

Patch

diff --git a/gdb/source.c b/gdb/source.c
index ad6c6466b44..e77789c0dba 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1379,12 +1379,7 @@  print_source_lines_base (struct symtab *s, int line, int stopline,
 	  else if (c == '\r')
 	    {
 	      /* Skip a \r character, but only before a \n.  */
-	      if (iter[1] == '\n')
-		{
-		  ++iter;
-		  c = '\n';
-		}
-	      else
+	      if (*iter != '\n')
 		printf_filtered ("^%c", c + 0100);
 	    }
 	  else