public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR gdb/16120
@ 2014-01-06 19:44 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2014-01-06 19:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Patrick Palka

Once it processes a line of text, the input handler that we temporarily
install in gdb_readline_wrapper() automatically uninstalls itself.
Afterwards, we restore the original input handler but we fail to
re-register it with readline.  If at this point readline determines that
there is more pending input, it will attempt to call the
currently-installed input handler once again.  But since we just
uninstalled the temporarily input handler, and failed to install the
original input handler, readline will have no input handler yet to call.
This leads to the segfault exhibited by the above PR.

This patch makes sure to register the original input handler with
readline after the temporary input handler finishes.
---
 gdb/ChangeLog |  6 ++++++
 gdb/top.c     | 11 +++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 577c4b0..082e1a5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2014-01-02  Patrick Palka  <patrick@parcs.ath.cx>
+
+	PR gdb/16120
+	* top.c (gdb_readline_wrapper_cleanup): Register the original input
+	handler with readline after restoring it.
+
 2014-01-06  Tom Tromey  <tromey@redhat.com>
 
 	* doublest.c (convert_doublest_to_floatformat): Use const, not
diff --git a/gdb/top.c b/gdb/top.c
index d068450..bc2fb4f 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -776,8 +776,7 @@ gdb_readline_wrapper_cleanup (void *arg)
 {
   struct gdb_readline_wrapper_cleanup *cleanup = arg;
 
-  rl_already_prompted = cleanup->already_prompted_orig;
-
+  /* Restore the original input handler.  */
   gdb_assert (input_handler == gdb_readline_wrapper_line);
   input_handler = cleanup->handler_orig;
   gdb_readline_wrapper_result = NULL;
@@ -786,6 +785,14 @@ gdb_readline_wrapper_cleanup (void *arg)
   after_char_processing_hook = saved_after_char_processing_hook;
   saved_after_char_processing_hook = NULL;
 
+  /* Register the restored input handler with readline by issuing a
+     prompt display.  */
+  gdb_assert (rl_already_prompted);
+  if (async_command_editing_p)
+    display_gdb_prompt (NULL);
+
+  rl_already_prompted = cleanup->already_prompted_orig;
+
   xfree (cleanup);
 }
 
-- 
1.8.5.2

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-01-06 19:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-06 19:44 [PATCH] Fix PR gdb/16120 Patrick Palka

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