From 1dbeed45b6a81ddcb725b68ff12236e7c8386a47 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 22 Mar 2018 10:31:41 -0600 Subject: [PATCH] Remove cleanups from gdb_readline_wrapper This removes some cleanups from gdb_readline_wrapper by changing the existing gdb_readline_wrapper_cleanup struct to have a constructor and destructor, and then changing gdb_readline_wrapper to simply instantiate it on the stack. gdb/ChangeLog 2018-03-27 Pedro Alves Tom Tromey * top.c (class gdb_readline_wrapper_cleanup): Add constructor, destructor. Now a class. (gdb_readline_wrapper_cleanup): Remove function. (gdb_readline_wrapper): Remove cleanups. --- gdb/ChangeLog | 8 ++++ gdb/top.c | 108 ++++++++++++++++++++++++-------------------------- 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a3e99e6164..ca67054f50 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-03-27 Pedro Alves + Tom Tromey + + * 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 * typeprint.h (struct type_print_options) 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 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; } -- 2.34.1