From patchwork Sun Oct 1 04:06:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23272 Received: (qmail 103535 invoked by alias); 1 Oct 2017 04:07:29 -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 102542 invoked by uid 89); 1 Oct 2017 04:07:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 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=restoration, destroyed, restoring X-HELO: gproxy2-pub.mail.unifiedlayer.com Received: from gproxy2-pub.mail.unifiedlayer.com (HELO gproxy2-pub.mail.unifiedlayer.com) (69.89.18.3) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Oct 2017 04:07:22 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id C4AA01E085B for ; Sat, 30 Sep 2017 22:07:20 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id G47H1w0172f2jeq0147L6V; Sat, 30 Sep 2017 22:07:20 -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=K4rO5fhPs9hYvweeWm4A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-0-208.hlrn.qwest.net ([75.166.0.208]:43148 helo=pokyo.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dyVWg-002l9R-F3; Sat, 30 Sep 2017 22:06:46 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/8] Remove set_batch_flag_and_make_cleanup_restore_page_info Date: Sat, 30 Sep 2017 22:06:37 -0600 Message-Id: <20171001040643.25162-3-tom@tromey.com> In-Reply-To: <20171001040643.25162-1-tom@tromey.com> References: <20171001040643.25162-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dyVWg-002l9R-F3 X-Source-Sender: 75-166-0-208.hlrn.qwest.net (pokyo.Home) [75.166.0.208]:43148 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes set_batch_flag_and_make_cleanup_restore_page_info and make_cleanup_restore_page_info in favor of a new RAII class. This then allows for the removal of make_cleanup_restore_uinteger and make_cleanup_restore_integer ChangeLog 2017-09-30 Tom Tromey * guile/scm-ports.c (ioscm_with_output_to_port_worker): Update. * top.c (execute_command_to_string): Update. * utils.c (make_cleanup_restore_page_info): Remove. (do_restore_page_info_cleanup): Remove. (set_batch_flag_and_restore_page_info): New. (make_cleanup_restore_page_info): Remove. (set_batch_flag_and_make_cleanup_restore_page_info): Remove. (~set_batch_flag_and_restore_page_info): New (make_cleanup_restore_uinteger): Remove. (make_cleanup_restore_integer): Remove. (struct restore_integer_closure): Remove. (restore_integer): Remove. * utils.h (struct set_batch_flag_and_restore_page_info): New class. (set_batch_flag_and_make_cleanup_restore_page_info): Remove. (make_cleanup_restore_page_info): Remove. (make_cleanup_restore_uinteger) Remove. (make_cleanup_restore_integer) Remove. --- gdb/ChangeLog | 22 ++++++++++++++ gdb/guile/scm-ports.c | 5 +--- gdb/top.c | 6 +--- gdb/utils.c | 81 ++++++++------------------------------------------- gdb/utils.h | 27 +++++++++++++---- 5 files changed, 57 insertions(+), 84 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a415c18..a17a83c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,27 @@ 2017-09-30 Tom Tromey + * guile/scm-ports.c (ioscm_with_output_to_port_worker): Update. + * top.c (execute_command_to_string): Update. + * utils.c (make_cleanup_restore_page_info): Remove. + (do_restore_page_info_cleanup): Remove. + (set_batch_flag_and_restore_page_info): + New. + (make_cleanup_restore_page_info): Remove. + (set_batch_flag_and_make_cleanup_restore_page_info): Remove. + (~set_batch_flag_and_restore_page_info): New + (make_cleanup_restore_uinteger): Remove. + (make_cleanup_restore_integer): Remove. + (struct restore_integer_closure): Remove. + (restore_integer): Remove. + * utils.h (struct set_batch_flag_and_restore_page_info): New + class. + (set_batch_flag_and_make_cleanup_restore_page_info): Remove. + (make_cleanup_restore_page_info): Remove. + (make_cleanup_restore_uinteger) Remove. + (make_cleanup_restore_integer) Remove. + +2017-09-30 Tom Tromey + * record-full.h (record_full_gdb_operation_disable_set): Return scoped_restore_tmpl. * infrun.c (adjust_pc_after_break): Update. diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c index 78187c4..a7c0bd4 100644 --- a/gdb/guile/scm-ports.c +++ b/gdb/guile/scm-ports.c @@ -461,7 +461,6 @@ static SCM ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport, const char *func_name) { - struct cleanup *cleanups; SCM result; SCM_ASSERT_TYPE (gdbscm_is_true (scm_output_port_p (port)), port, @@ -469,7 +468,7 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport, SCM_ASSERT_TYPE (gdbscm_is_true (scm_thunk_p (thunk)), thunk, SCM_ARG2, func_name, _("thunk")); - cleanups = set_batch_flag_and_make_cleanup_restore_page_info (); + set_batch_flag_and_restore_page_info save_page_info; scoped_restore restore_async = make_scoped_restore (¤t_ui->async, 0); @@ -493,8 +492,6 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport, result = gdbscm_safe_call_0 (thunk, NULL); } - do_cleanups (cleanups); - if (gdbscm_is_exception (result)) gdbscm_throw (result); diff --git a/gdb/top.c b/gdb/top.c index 4fc987c..56117a3 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -666,11 +666,9 @@ execute_command (char *p, int from_tty) std::string execute_command_to_string (char *p, int from_tty) { - struct cleanup *cleanup; - /* GDB_STDOUT should be better already restored during these restoration callbacks. */ - cleanup = set_batch_flag_and_make_cleanup_restore_page_info (); + set_batch_flag_and_restore_page_info save_page_info; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); @@ -694,8 +692,6 @@ execute_command_to_string (char *p, int from_tty) execute_command (p, from_tty); } - do_cleanups (cleanup); - return std::move (str_file.string ()); } diff --git a/gdb/utils.c b/gdb/utils.c index b2e0813..0c59b4e 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -150,44 +150,6 @@ make_cleanup_free_section_addr_info (struct section_addr_info *addrs) return make_cleanup (do_free_section_addr_info, addrs); } -struct restore_integer_closure -{ - int *variable; - int value; -}; - -static void -restore_integer (void *p) -{ - struct restore_integer_closure *closure - = (struct restore_integer_closure *) p; - - *(closure->variable) = closure->value; -} - -/* Remember the current value of *VARIABLE and make it restored when - the cleanup is run. */ - -struct cleanup * -make_cleanup_restore_integer (int *variable) -{ - struct restore_integer_closure *c = XNEW (struct restore_integer_closure); - - c->variable = variable; - c->value = *variable; - - return make_cleanup_dtor (restore_integer, (void *) c, xfree); -} - -/* Remember the current value of *VARIABLE and make it restored when - the cleanup is run. */ - -struct cleanup * -make_cleanup_restore_uinteger (unsigned int *variable) -{ - return make_cleanup_restore_integer ((int *) variable); -} - /* Helper for make_cleanup_unpush_target. */ static void @@ -1464,42 +1426,23 @@ filtered_printing_initialized (void) return wrap_buffer != NULL; } -/* Helper for make_cleanup_restore_page_info. */ - -static void -do_restore_page_info_cleanup (void *arg) -{ - set_screen_size (); - set_width (); -} - -/* Provide cleanup for restoring the terminal size. */ - -struct cleanup * -make_cleanup_restore_page_info (void) +set_batch_flag_and_restore_page_info::set_batch_flag_and_restore_page_info () + : m_save_lines_per_page (lines_per_page), + m_save_chars_per_line (chars_per_line), + m_save_batch_flag (batch_flag) { - struct cleanup *back_to; - - back_to = make_cleanup (do_restore_page_info_cleanup, NULL); - make_cleanup_restore_uinteger (&lines_per_page); - make_cleanup_restore_uinteger (&chars_per_line); - - return back_to; + batch_flag = 1; + init_page_info (); } -/* Temporarily set BATCH_FLAG and the associated unlimited terminal size. - Provide cleanup for restoring the original state. */ - -struct cleanup * -set_batch_flag_and_make_cleanup_restore_page_info (void) +set_batch_flag_and_restore_page_info::~set_batch_flag_and_restore_page_info () { - struct cleanup *back_to = make_cleanup_restore_page_info (); - - make_cleanup_restore_integer (&batch_flag); - batch_flag = 1; - init_page_info (); + batch_flag = m_save_batch_flag; + chars_per_line = m_save_chars_per_line; + lines_per_page = m_save_lines_per_page; - return back_to; + set_screen_size (); + set_width (); } /* Set the screen size based on LINES_PER_PAGE and CHARS_PER_LINE. */ diff --git a/gdb/utils.h b/gdb/utils.h index 7b45cc8..022af51 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -211,9 +211,6 @@ extern struct cleanup *(make_cleanup_free_section_addr_info /* For make_cleanup_close see common/filestuff.h. */ -extern struct cleanup *make_cleanup_restore_integer (int *variable); -extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable); - struct target_ops; extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops); @@ -236,9 +233,27 @@ extern void free_current_contents (void *); extern void init_page_info (void); -extern struct cleanup *make_cleanup_restore_page_info (void); -extern struct cleanup * - set_batch_flag_and_make_cleanup_restore_page_info (void); +/* Temporarily set BATCH_FLAG and the associated unlimited terminal size. + Restore when destroyed. */ + +struct set_batch_flag_and_restore_page_info +{ +public: + + set_batch_flag_and_restore_page_info (); + ~set_batch_flag_and_restore_page_info (); + + DISABLE_COPY_AND_ASSIGN (set_batch_flag_and_restore_page_info); + +private: + + /* Note that this doesn't use scoped_restore, because it's important + to control the ordering of operations in the destruction, and it + was simpler to avoid introducing a new ad hoc class. */ + unsigned m_save_lines_per_page; + unsigned m_save_chars_per_line; + int m_save_batch_flag; +}; extern struct cleanup *make_bpstat_clear_actions_cleanup (void);