Fix "list" when control characters are seen

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

Commit Message

Tom Tromey April 9, 2019, 6:54 p.m. UTC
  PR symtab/24423 points out that control characters in a source file
cause a hang in the "list" command, a regression introduced by the
styling changes.

This patch, from the PR, fixes the bug.  I've included a minimal
change to the "list" test that exercises this code.

I recall that this bug was discussed on gdb-patches, and I thought
there was a patch there as well, but I was unable to find it.

gdb/ChangeLog
2019-04-09  Ilya Yu. Malakhov  <malakhov@mcst.ru>

	PR symtab/24423:
	* source.c (print_source_lines_base): Advance "iter" when a
	control character is seen.

gdb/testsuite/ChangeLog
2019-04-09  Tom Tromey  <tromey@adacore.com>

	PR symtab/24423:
	* gdb.base/list0.h (foo): Add a control-l character.
---
 gdb/ChangeLog                  | 6 ++++++
 gdb/source.c                   | 8 ++++++--
 gdb/testsuite/ChangeLog        | 5 +++++
 gdb/testsuite/gdb.base/list0.h | 2 +-
 4 files changed, 18 insertions(+), 3 deletions(-)
  

Comments

Andreas Schwab April 9, 2019, 7:24 p.m. UTC | #1
On Apr 09 2019, Tom Tromey <tromey@adacore.com> wrote:

> diff --git a/gdb/source.c b/gdb/source.c
> index f99215f9810..b61880ab503 100644
> --- a/gdb/source.c
> +++ b/gdb/source.c
> @@ -1368,7 +1368,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
>  	      char c = *iter;
>  	      if (c == '\033' && skip_ansi_escape (iter, &skip_bytes))
>  		iter += skip_bytes;
> -	      else if (c < 040 && c != '\t')
> +	      else if (c >= 0 && c < 040 && c != '\t')

Does this give a warning when char is unsigned?

Andreas.
  
Tom Tromey April 10, 2019, 4:53 p.m. UTC | #2
>> +	      else if (c >= 0 && c < 040 && c != '\t')

Andreas> Does this give a warning when char is unsigned?

I tried with -funsigned-char, and did not get a warning.

Tom
  
Tom Tromey April 19, 2019, 7:03 p.m. UTC | #3
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> PR symtab/24423 points out that control characters in a source file
Tom> cause a hang in the "list" command, a regression introduced by the
Tom> styling changes.

Tom> This patch, from the PR, fixes the bug.  I've included a minimal
Tom> change to the "list" test that exercises this code.

Tom> I recall that this bug was discussed on gdb-patches, and I thought
Tom> there was a patch there as well, but I was unable to find it.

I'm going to check this in to master and the 8.3 branch now.

Tom
  
Pedro Alves June 18, 2019, 1:24 p.m. UTC | #4
On 4/9/19 7:54 PM, Tom Tromey wrote:
> --- a/gdb/testsuite/gdb.base/list0.h
> +++ b/gdb/testsuite/gdb.base/list0.h
> @@ -3,7 +3,7 @@
>  extern void bar(int);
>  static void foo (int x)
>  /* !
> -   !
> +

This seems pretty obscure without the context of the patch around.

Should we add a comment here?

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/source.c b/gdb/source.c
index f99215f9810..b61880ab503 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1368,7 +1368,7 @@  print_source_lines_base (struct symtab *s, int line, int stopline,
 	      char c = *iter;
 	      if (c == '\033' && skip_ansi_escape (iter, &skip_bytes))
 		iter += skip_bytes;
-	      else if (c < 040 && c != '\t')
+	      else if (c >= 0 && c < 040 && c != '\t')
 		break;
 	      else if (c == 0177)
 		break;
@@ -1397,9 +1397,13 @@  print_source_lines_base (struct symtab *s, int line, int stopline,
 	    {
 	      xsnprintf (buf, sizeof (buf), "^%c", *iter + 0100);
 	      uiout->text (buf);
+	      ++iter;
 	    }
 	  else if (*iter == 0177)
-	    uiout->text ("^?");
+	    {
+	      uiout->text ("^?");
+	      ++iter;
+	    }
 	}
       uiout->text ("\n");
     }
diff --git a/gdb/testsuite/gdb.base/list0.h b/gdb/testsuite/gdb.base/list0.h
index 42a4fe0f03a..6f280935509 100644
--- a/gdb/testsuite/gdb.base/list0.h
+++ b/gdb/testsuite/gdb.base/list0.h
@@ -3,7 +3,7 @@ 
 extern void bar(int);
 static void foo (int x)
 /* !
-   !
+
    ! */
 {
     bar (x++);