From 014bc49bfcf15d53c65d956ed337ab3217431483 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 9 Apr 2019 12:52:46 -0600 Subject: [PATCH] Fix "list" when control characters are seen 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. 2019-04-19 Ilya Yu. Malakhov PR symtab/24423: * source.c (print_source_lines_base): Advance "iter" when a control character is seen. gdb/testsuite/ChangeLog 2019-04-19 Tom Tromey 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(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8a4da983..328cf29 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-04-19 Ilya Yu. Malakhov + + PR symtab/24423: + * source.c (print_source_lines_base): Advance "iter" when a + control character is seen. + 2019-04-19 Philippe Waroquiers * inferior.h (struct infcall_suspend_state_deleter): diff --git a/gdb/source.c b/gdb/source.c index f99215f..b61880a 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/ChangeLog b/gdb/testsuite/ChangeLog index 7308417..1ff0526 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-04-19 Tom Tromey + + PR symtab/24423: + * gdb.base/list0.h (foo): Add a control-l character. + 2019-03-28 Pedro Alves * lib/gdb.exp (gdb_test_multiple): Split appends to $code and diff --git a/gdb/testsuite/gdb.base/list0.h b/gdb/testsuite/gdb.base/list0.h index 42a4fe0..6f28093 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++); -- 2.7.4