From patchwork Sun Sep 10 21:50:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22804 Received: (qmail 41830 invoked by alias); 10 Sep 2017 21:50:49 -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 41657 invoked by uid 89); 10 Sep 2017 21:50:47 -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=H*MI:sk:2017091, opportunity X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Sep 2017 21:50:45 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 5834B14051C for ; Sun, 10 Sep 2017 15:50:44 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id 7xqh1w00s2f2jeq01xqkrH; Sun, 10 Sep 2017 15:50:44 -0600 X-Authority-Analysis: v=2.2 cv=OZLoNlbY c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=ys-tRNxSrRAqo4q3UtwA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:39396 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1drA7l-0020eg-40; Sun, 10 Sep 2017 15:50:41 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/8] Replace interp_set_temp with scoped_restore_interp Date: Sun, 10 Sep 2017 15:50:31 -0600 Message-Id: <20170910215037.24329-3-tom@tromey.com> In-Reply-To: <20170910215037.24329-1-tom@tromey.com> References: <20170910215037.24329-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1drA7l-0020eg-40 X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:39396 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes interp_set_temp and an associated cleanup, in favor of a new RAII class, scoped_restore_interp. ChangeLog 2017-09-10 Tom Tromey * cli/cli-script.c (restore_interp): Remove. (read_command_lines): Use scoped_restore_interp. * interps.c (scoped_restore_interp::set_temp): Rename from interp_set_temp. * interps.h (class scoped_restore_interp): New. (interp_set_temp): Remove. --- gdb/ChangeLog | 9 +++++++++ gdb/cli/cli-script.c | 10 +--------- gdb/interps.c | 2 +- gdb/interps.h | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 80d615b..de88894 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2017-09-10 Tom Tromey + * cli/cli-script.c (restore_interp): Remove. + (read_command_lines): Use scoped_restore_interp. + * interps.c (scoped_restore_interp::set_temp): Rename from + interp_set_temp. + * interps.h (class scoped_restore_interp): New. + (interp_set_temp): Remove. + +2017-09-10 Tom Tromey + * mi/mi-cmd-catch.c (mi_cmd_catch_assert) (mi_cmd_catch_exception, mi_catch_load_unload): Update. * mi/mi-cmd-break.c (setup_breakpoint_reporting): Return a diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 9b2ffd0..805064f 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1158,12 +1158,6 @@ recurse_read_control_structure (char * (*read_next_line_func) (void), return ret; } -static void -restore_interp (void *arg) -{ - interp_set_temp (interp_name ((struct interp *)arg)); -} - /* Read lines from the input stream and accumulate them in a chain of struct command_line's, which is then returned. For input from a terminal, the special command "end" is used to mark the end of the @@ -1203,12 +1197,10 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, validator, closure); else { - struct interp *old_interp = interp_set_temp (INTERP_CONSOLE); - struct cleanup *old_chain = make_cleanup (restore_interp, old_interp); + scoped_restore_interp interp_restorer (INTERP_CONSOLE); head = read_command_lines_1 (read_next_line, parse_commands, validator, closure); - do_cleanups (old_chain); } if (from_tty && input_interactive_p (current_ui) diff --git a/gdb/interps.c b/gdb/interps.c index 19694ff..63a1230 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -288,7 +288,7 @@ current_interp_set_logging (ui_file_up logfile, /* Temporarily overrides the current interpreter. */ struct interp * -interp_set_temp (const char *name) +scoped_restore_interp::set_interp (const char *name) { struct ui_interp_info *ui_interp = get_current_interp_info (); struct interp *interp = interp_lookup (current_ui, name); diff --git a/gdb/interps.h b/gdb/interps.h index b20cf5c..09d1314 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -104,6 +104,32 @@ extern struct ui_out *interp_ui_out (struct interp *interp); extern const char *interp_name (struct interp *interp); extern struct interp *interp_set_temp (const char *name); +/* Temporarily set the current interpreter, and reset it on + destruction. */ +class scoped_restore_interp +{ +public: + + scoped_restore_interp (const char *name) + : m_interp (set_interp (name)) + { + } + + ~scoped_restore_interp () + { + set_interp (interp_name (m_interp)); + } + + scoped_restore_interp (const scoped_restore_interp &) = delete; + scoped_restore_interp &operator= (const scoped_restore_interp &) = delete; + +private: + + struct interp *set_interp (const char *name); + + struct interp *m_interp; +}; + extern int current_interp_named_p (const char *name); /* Call this function to give the current interpreter an opportunity