From patchwork Sat Sep 9 15:35:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22781 Received: (qmail 92415 invoked by alias); 9 Sep 2017 15:35:58 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 92193 invoked by uid 89); 9 Sep 2017 15:35:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=scm, SCM X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Sep 2017 15:35:55 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy9.mail.unifiedlayer.com (Postfix) with ESMTP id 302C11E06FD for ; Sat, 9 Sep 2017 09:35:54 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 7Tbr1w00A2f2jeq01TbuxD; Sat, 09 Sep 2017 09:35:54 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=4gMyArSuBCE_94qcLncA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:59756 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dqhnS-00381I-Ui; Sat, 09 Sep 2017 09:35:51 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 6/7] Remove make_cleanup_ui_out_redirect_pop Date: Sat, 9 Sep 2017 09:35:39 -0600 Message-Id: <20170909153540.15008-7-tom@tromey.com> In-Reply-To: <20170909153540.15008-1-tom@tromey.com> References: <20170909153540.15008-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dqhnS-00381I-Ui X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:59756 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This patch introduces ui_out_redirect_pop. All uses of make_cleanup_ui_out_redirect_pop are replaced with this new class. ChangeLog 2017-09-09 Tom Tromey * mi/mi-interp.c (mi_user_selected_context_changed): Use ui_out_redirect_pop. * guile/scm-ports.c (ioscm_with_output_to_port_worker): Use ui_out_redirect_pop. * utils.c (do_ui_out_redirect_pop) (make_cleanup_ui_out_redirect_pop): Remove. * top.c (execute_command_to_string): Use ui_out_redirect_pop. * utils.h (make_cleanup_ui_out_redirect_pop): Remove. * ui-out.h (ui_out_redirect_pop): New class. --- gdb/ChangeLog | 12 ++++++++++++ gdb/guile/scm-ports.c | 22 +++++++++++++--------- gdb/mi/mi-interp.c | 5 ++--- gdb/top.c | 32 +++++++++++++++++--------------- gdb/ui-out.h | 23 +++++++++++++++++++++++ gdb/utils.c | 19 ------------------- gdb/utils.h | 4 ---- 7 files changed, 67 insertions(+), 50 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a8c1642..cc8e4e4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,17 @@ 2017-09-09 Tom Tromey + * mi/mi-interp.c (mi_user_selected_context_changed): Use + ui_out_redirect_pop. + * guile/scm-ports.c (ioscm_with_output_to_port_worker): Use + ui_out_redirect_pop. + * utils.c (do_ui_out_redirect_pop) + (make_cleanup_ui_out_redirect_pop): Remove. + * top.c (execute_command_to_string): Use ui_out_redirect_pop. + * utils.h (make_cleanup_ui_out_redirect_pop): Remove. + * ui-out.h (ui_out_redirect_pop): New class. + +2017-09-09 Tom Tromey + * mi/mi-main.c (output_cores): Use ui_out_emit_list. (list_available_thread_groups, mi_cmd_list_thread_groups) (mi_cmd_data_list_changed_registers, mi_cmd_data_read_memory) diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c index 735abc2..78187c4 100644 --- a/gdb/guile/scm-ports.c +++ b/gdb/guile/scm-ports.c @@ -26,6 +26,7 @@ #include "top.h" #include "target.h" #include "guile-internal.h" +#include "common/gdb_optional.h" #ifdef HAVE_POLL #if defined (HAVE_POLL_H) @@ -477,17 +478,20 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport, scoped_restore save_file = make_scoped_restore (oport == GDB_STDERR ? &gdb_stderr : &gdb_stdout); - if (oport == GDB_STDERR) - gdb_stderr = port_file.get (); - else - { - current_uiout->redirect (port_file.get ()); - make_cleanup_ui_out_redirect_pop (current_uiout); + { + gdb::optional redirect_popper; + if (oport == GDB_STDERR) + gdb_stderr = port_file.get (); + else + { + current_uiout->redirect (port_file.get ()); + redirect_popper.emplace (current_uiout); - gdb_stdout = port_file.get (); - } + gdb_stdout = port_file.get (); + } - result = gdbscm_safe_call_0 (thunk, NULL); + result = gdbscm_safe_call_0 (thunk, NULL); + } do_cleanups (cleanups); diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 6b6d8f0..1331860 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -1314,10 +1314,9 @@ mi_user_selected_context_changed (user_selected_what selection) mi_uiout = interp_ui_out (top_level_interpreter ()); mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redirect_popper (mi_uiout); - old_chain = make_cleanup_ui_out_redirect_pop (mi_uiout); - - make_cleanup_restore_target_terminal (); + old_chain = make_cleanup_restore_target_terminal (); target_terminal_ours_for_output (); if (selection & USER_SELECTED_INFERIOR) diff --git a/gdb/top.c b/gdb/top.c index a4fd262..742c1e7 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -679,21 +679,23 @@ execute_command_to_string (char *p, int from_tty) string_file str_file; - current_uiout->redirect (&str_file); - make_cleanup_ui_out_redirect_pop (current_uiout); - - scoped_restore save_stdout - = make_scoped_restore (&gdb_stdout, &str_file); - scoped_restore save_stderr - = make_scoped_restore (&gdb_stderr, &str_file); - scoped_restore save_stdlog - = make_scoped_restore (&gdb_stdlog, &str_file); - scoped_restore save_stdtarg - = make_scoped_restore (&gdb_stdtarg, &str_file); - scoped_restore save_stdtargerr - = make_scoped_restore (&gdb_stdtargerr, &str_file); - - execute_command (p, from_tty); + { + current_uiout->redirect (&str_file); + ui_out_redirect_pop redirect_popper (current_uiout); + + scoped_restore save_stdout + = make_scoped_restore (&gdb_stdout, &str_file); + scoped_restore save_stderr + = make_scoped_restore (&gdb_stderr, &str_file); + scoped_restore save_stdlog + = make_scoped_restore (&gdb_stdlog, &str_file); + scoped_restore save_stdtarg + = make_scoped_restore (&gdb_stdtarg, &str_file); + scoped_restore save_stdtargerr + = make_scoped_restore (&gdb_stdtargerr, &str_file); + + execute_command (p, from_tty); + } do_cleanups (cleanup); diff --git a/gdb/ui-out.h b/gdb/ui-out.h index d983837..9ed2bd2 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -242,4 +242,27 @@ private: struct ui_out *m_uiout; }; +/* On destruction, pop the last redirection by calling the uiout's + redirect method with a NULL parameter. */ +class ui_out_redirect_pop +{ +public: + + ui_out_redirect_pop (ui_out *uiout) + : m_uiout (uiout) + { + } + + ~ui_out_redirect_pop () + { + m_uiout->redirect (NULL); + } + + ui_out_redirect_pop (const ui_out_redirect_pop &) = delete; + ui_out_redirect_pop &operator= (const ui_out_redirect_pop &) = delete; + +private: + struct ui_out *m_uiout; +}; + #endif /* UI_OUT_H */ diff --git a/gdb/utils.c b/gdb/utils.c index f2da2df..1941e7c 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -137,25 +137,6 @@ show_pagination_enabled (struct ui_file *file, int from_tty, because while they use the "cleanup API" they are not part of the "cleanup API". */ -/* Helper function for make_cleanup_ui_out_redirect_pop. */ - -static void -do_ui_out_redirect_pop (void *arg) -{ - struct ui_out *uiout = (struct ui_out *) arg; - - uiout->redirect (NULL); -} - -/* Return a new cleanup that pops the last redirection by ui_out_redirect - with NULL parameter. */ - -struct cleanup * -make_cleanup_ui_out_redirect_pop (struct ui_out *uiout) -{ - return make_cleanup (do_ui_out_redirect_pop, uiout); -} - static void do_free_section_addr_info (void *arg) { diff --git a/gdb/utils.h b/gdb/utils.h index 1c8b95c..6d33e8d 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -205,10 +205,6 @@ private: /* Cleanup utilities. */ -struct ui_out; -extern struct cleanup * - make_cleanup_ui_out_redirect_pop (struct ui_out *uiout); - struct section_addr_info; extern struct cleanup *(make_cleanup_free_section_addr_info (struct section_addr_info *));