diff options
author | Tom Tromey <tom@tromey.com> | 2018-03-22 10:31:41 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-03-27 10:46:42 -0600 |
commit | 1dbeed45b6a81ddcb725b68ff12236e7c8386a47 (patch) | |
tree | 18b74ac34f2511343f8061a8675ae40bb9543a2b /gdb/top.c | |
parent | c819b2c0b216c69a4ae5bfba0eac71ffdf1b3596 (diff) | |
download | gdb-1dbeed45b6a81ddcb725b68ff12236e7c8386a47.zip gdb-1dbeed45b6a81ddcb725b68ff12236e7c8386a47.tar.gz gdb-1dbeed45b6a81ddcb725b68ff12236e7c8386a47.tar.bz2 |
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 <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.
Diffstat (limited to 'gdb/top.c')
-rw-r--r-- | gdb/top.c | 108 |
1 files changed, 51 insertions, 57 deletions
@@ -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 (¤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 @@ -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; } |