This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR gdb/16120


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]