gdb_rl_callback_handler_remove ();
}
-struct gdb_readline_wrapper_cleanup
- {
- void (*handler_orig) (char *);
- int already_prompted_orig;
-
- /* Whether the target was async. */
- int target_is_async_orig;
- };
-
-static void
-gdb_readline_wrapper_cleanup (void *arg)
+class gdb_readline_wrapper_cleanup
{
- struct ui *ui = current_ui;
- struct gdb_readline_wrapper_cleanup *cleanup
- = (struct gdb_readline_wrapper_cleanup *) arg;
+public:
+ gdb_readline_wrapper_cleanup ()
+ : m_handler_orig (current_ui->input_handler),
+ m_already_prompted_orig (current_ui->command_editing
+ ? rl_already_prompted : 0),
+ m_target_is_async_orig (target_is_async_p ()),
+ m_save_ui (¤t_ui)
+ {
+ current_ui->input_handler = gdb_readline_wrapper_line;
+ current_ui->secondary_prompt_depth++;
- if (ui->command_editing)
- rl_already_prompted = cleanup->already_prompted_orig;
+ if (m_target_is_async_orig)
+ target_async (0);
+ }
- gdb_assert (ui->input_handler == gdb_readline_wrapper_line);
- ui->input_handler = cleanup->handler_orig;
+ ~gdb_readline_wrapper_cleanup ()
+ {
+ struct ui *ui = current_ui;
- /* Don't restore our input handler in readline yet. That would make
- readline prep the terminal (putting it in raw mode), while the
- line we just read may trigger execution of a command that expects
- the terminal in the default cooked/canonical mode, such as e.g.,
- running Python's interactive online help utility. See
- gdb_readline_wrapper_line for when we'll reinstall it. */
+ if (ui->command_editing)
+ rl_already_prompted = m_already_prompted_orig;
- gdb_readline_wrapper_result = NULL;
- gdb_readline_wrapper_done = 0;
- ui->secondary_prompt_depth--;
- gdb_assert (ui->secondary_prompt_depth >= 0);
+ gdb_assert (ui->input_handler == gdb_readline_wrapper_line);
+ ui->input_handler = m_handler_orig;
- after_char_processing_hook = saved_after_char_processing_hook;
- saved_after_char_processing_hook = NULL;
+ /* Don't restore our input handler in readline yet. That would make
+ readline prep the terminal (putting it in raw mode), while the
+ line we just read may trigger execution of a command that expects
+ the terminal in the default cooked/canonical mode, such as e.g.,
+ running Python's interactive online help utility. See
+ gdb_readline_wrapper_line for when we'll reinstall it. */
- if (cleanup->target_is_async_orig)
- target_async (1);
+ gdb_readline_wrapper_result = NULL;
+ gdb_readline_wrapper_done = 0;
+ ui->secondary_prompt_depth--;
+ gdb_assert (ui->secondary_prompt_depth >= 0);
- xfree (cleanup);
-}
+ after_char_processing_hook = saved_after_char_processing_hook;
+ saved_after_char_processing_hook = NULL;
-char *
-gdb_readline_wrapper (const char *prompt)
-{
- struct ui *ui = current_ui;
- struct cleanup *back_to;
- struct gdb_readline_wrapper_cleanup *cleanup;
- char *retval;
+ if (m_target_is_async_orig)
+ target_async (1);
+ }
- cleanup = XNEW (struct gdb_readline_wrapper_cleanup);
- cleanup->handler_orig = ui->input_handler;
- ui->input_handler = gdb_readline_wrapper_line;
+ DISABLE_COPY_AND_ASSIGN (gdb_readline_wrapper_cleanup);
- if (ui->command_editing)
- cleanup->already_prompted_orig = rl_already_prompted;
- else
- cleanup->already_prompted_orig = 0;
+private:
- cleanup->target_is_async_orig = target_is_async_p ();
+ void (*m_handler_orig) (char *);
+ int m_already_prompted_orig;
- ui->secondary_prompt_depth++;
- back_to = make_cleanup (gdb_readline_wrapper_cleanup, cleanup);
+ /* Whether the target was async. */
+ int m_target_is_async_orig;
/* Processing events may change the current UI. */
- scoped_restore save_ui = make_scoped_restore (¤t_ui);
+ scoped_restore_tmpl<struct ui *> m_save_ui;
+};
+
+char *
+gdb_readline_wrapper (const char *prompt)
+{
+ struct ui *ui = current_ui;
- if (cleanup->target_is_async_orig)
- target_async (0);
+ gdb_readline_wrapper_cleanup cleanup;
/* Display our prompt and prevent double prompt display. Don't pass
down a NULL prompt, since that has special meaning for
if (gdb_readline_wrapper_done)
break;
- retval = gdb_readline_wrapper_result;
- do_cleanups (back_to);
- return retval;
+ return gdb_readline_wrapper_result;
}
\f