public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/cli-out.c: clear_current_line shouldn't trigger pagination prompt
@ 2023-05-11 23:22 Aaron Merey
  2023-05-12  6:30 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Aaron Merey @ 2023-05-11 23:22 UTC (permalink / raw)
  To: gdb-patches; +Cc: Aaron Merey

clear_current_line overwrites the current line with chars_per_line
blank spaces.  Printing the final space triggers a condition in
pager_file::puts that causes lines_printed to be incremented.  If
lines_printed becomes greater than or equal to lines_allowed, the
pagination prompt will appear if enabled.

In this case the prompt is unnecessary since after printing the final
space clear_current_line immediately moves the cursor to the beginning
of the line with '\r'.  A new line isn't actually started, so the prompt
ends up being spurious.

Additionally it's possible for gdb to crash during this pagination prompt.
Answering the prompt with 'q' throws an exception intended to bring gdb
back to the main event loop.  But since commit 0fea10f32746,
clear_current_line may be called under the progress_update destructor.
The exception will try to propagate through a destructor, causing an abort.

This patch removes the possibility for clear_current_line to trigger the
prompt by only printing chars_per_line - 1 blank spaces.  clear_current_line
is only ever called to clear download progress bars, which do not print
anything on the final character of a line.

An additional step we could take is to revert commit 0fea10f32746 to
prevent any future possibility that an exception could be thrown during
the progress_update destructor.
---
 gdb/cli-out.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 4c598883d4b..e93de1d0aa5 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -396,7 +396,7 @@ cli_ui_out::clear_current_line ()
     chars_per_line = MAX_CHARS_PER_LINE;
 
   gdb_printf (stream, "\r");
-  for (int i = 0; i < chars_per_line; ++i)
+  for (int i = 0; i < chars_per_line - 1; ++i)
     gdb_printf (stream, " ");
   gdb_printf (stream, "\r");
 
-- 
2.39.2


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

end of thread, other threads:[~2023-05-23 15:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11 23:22 [PATCH] gdb/cli-out.c: clear_current_line shouldn't trigger pagination prompt Aaron Merey
2023-05-12  6:30 ` Eli Zaretskii
2023-05-15 21:32   ` Aaron Merey
2023-05-16  2:27     ` Eli Zaretskii
2023-05-19 21:38       ` Aaron Merey
2023-05-20  5:48         ` Eli Zaretskii
2023-05-23 15:13           ` Aaron Merey

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