aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/top.c108
2 files changed, 59 insertions, 57 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a3e99e6..ca67054 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2018-03-27 Pedro Alves <palves@redhat.com>
+ Tom Tromey <tom@tromey.com>
+
+ * top.c (class gdb_readline_wrapper_cleanup): Add constructor,
+ destructor. Now a class.
+ (gdb_readline_wrapper_cleanup): Remove function.
+ (gdb_readline_wrapper): Remove cleanups.
+
2018-03-27 Tom Tromey <tom@tromey.com>
* typeprint.h (struct type_print_options) <local_typedefs,
diff --git a/gdb/top.c b/gdb/top.c
index 14387b9..8903a92 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -917,76 +917,72 @@ gdb_readline_wrapper_line (char *line)
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 (&current_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 (&current_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
@@ -1004,9 +1000,7 @@ gdb_readline_wrapper (const char *prompt)
if (gdb_readline_wrapper_done)
break;
- retval = gdb_readline_wrapper_result;
- do_cleanups (back_to);
- return retval;
+ return gdb_readline_wrapper_result;
}