+/* The functions below are wrappers for rl_callback_handler_remove and
+ rl_callback_handler_install that keep track of whether the callback
+ handler is installed in readline. This is necessary because after
+ handling a target event of a background execution command, we may
+ need to reinstall the callback handler if it was removed due to a
+ secondary prompt. See gdb_readline_wrapper_line. We don't
+ unconditionally install the handler for every target event because
+ that also clears the line buffer, thus installing it while the user
+ is typing would lose input. */
+
+/* Whether we've registered a callback handler with readline. */
+static int callback_handler_installed;
+
+/* See event-top.h, and above. */
+
+void
+gdb_rl_callback_handler_remove (void)
+{
+ rl_callback_handler_remove ();
+ callback_handler_installed = 0;
+}
+
+/* See event-top.h, and above. Note this wrapper doesn't have an
+ actual callback parameter because we always install
+ INPUT_HANDLER. */
+
+void
+gdb_rl_callback_handler_install (const char *prompt)
+{
+ /* Calling rl_callback_handler_install resets readline's input
+ buffer. Calling this when we were already processing input
+ therefore loses input. */
+ gdb_assert (!callback_handler_installed);
+
+ rl_callback_handler_install (prompt, input_handler);
+ callback_handler_installed = 1;
+}
+
+/* See event-top.h, and above. */
+
+void
+gdb_rl_callback_handler_reinstall (void)
+{
+ if (!callback_handler_installed)
+ {
+ /* Passing NULL as prompt argument tells readline to not display
+ a prompt. */
+ gdb_rl_callback_handler_install (NULL);
+ }
+}
+