From patchwork Tue Sep 27 04:08:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 16059 Received: (qmail 101640 invoked by alias); 27 Sep 2016 04:49:36 -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 101578 invoked by uid 89); 27 Sep 2016 04:49:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:4012, interpreter X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Sep 2016 04:49:34 +0000 Received: from cmgw3 (cmgw4 [10.0.90.84]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 996B117607E for ; Mon, 26 Sep 2016 22:49:33 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id oUpW1t00G2f2jeq01UpZys; Mon, 26 Sep 2016 22:49:33 -0600 X-Authority-Analysis: v=2.1 cv=aaryw3Yt c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=ya1uvdF-JPXq6kpwn0UA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:56110 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bojhX-0006Nj-49; Mon, 26 Sep 2016 22:09:03 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 17/22] Remove make_cleanup_restore_current_uiout Date: Mon, 26 Sep 2016 22:08:45 -0600 Message-Id: <1474949330-4307-18-git-send-email-tom@tromey.com> In-Reply-To: <1474949330-4307-1-git-send-email-tom@tromey.com> References: <1474949330-4307-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bojhX-0006Nj-49 X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya.Home) [71.218.192.86]:56110 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This removes make_cleanup_restore_current_uiout in favor of an RAII-based class. 2016-09-26 Tom Tromey * ui-out.c (make_cleanup_restore_current_uiout) (restore_current_uiout_cleanup): Remove. * infrun.c (print_stop_event): Use scoped_restore_uiout. * ui-out.h (scoped_restore_uiout): New class. (make_cleanup_restore_current_uiout): Don't declare. --- gdb/ChangeLog | 8 ++++++++ gdb/infrun.c | 15 +++++++-------- gdb/python/python.c | 3 +-- gdb/ui-out.c | 18 ------------------ gdb/ui-out.h | 25 +++++++++++++++++++++++-- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 770a96f..89ce46f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2016-09-26 Tom Tromey + * ui-out.c (make_cleanup_restore_current_uiout) + (restore_current_uiout_cleanup): Remove. + * infrun.c (print_stop_event): Use scoped_restore_uiout. + * ui-out.h (scoped_restore_uiout): New class. + (make_cleanup_restore_current_uiout): Don't declare. + +2016-09-26 Tom Tromey + * elfread.c (elf_read_minimal_symbols): Use std::vector. 2016-09-26 Tom Tromey diff --git a/gdb/infrun.c b/gdb/infrun.c index 1736526..7136d00 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8084,22 +8084,21 @@ print_stop_location (struct target_waitstatus *ws) void print_stop_event (struct ui_out *uiout) { - struct cleanup *old_chain; struct target_waitstatus last; ptid_t last_ptid; struct thread_info *tp; get_last_target_status (&last_ptid, &last); - old_chain = make_cleanup_restore_current_uiout (); - current_uiout = uiout; - - print_stop_location (&last); + { + scoped_restore_uiout save_uiout; + current_uiout = uiout; - /* Display the auto-display expressions. */ - do_displays (); + print_stop_location (&last); - do_cleanups (old_chain); + /* Display the auto-display expressions. */ + do_displays (); + } tp = inferior_thread (); if (tp->thread_fsm != NULL diff --git a/gdb/python/python.c b/gdb/python/python.c index 9e4d610..b98ef90 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -647,8 +647,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) struct interp *interp; scoped_restore save_async (¤t_ui->async, 0); - - make_cleanup_restore_current_uiout (); + scoped_restore_uiout save_uiout; /* Use the console interpreter uiout to have the same print format for console or MI. */ diff --git a/gdb/ui-out.c b/gdb/ui-out.c index ec44ab6..3972a56 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -953,24 +953,6 @@ ui_out_destroy (struct ui_out *uiout) xfree (uiout); } -/* Cleanup that restores a previous current uiout. */ - -static void -restore_current_uiout_cleanup (void *arg) -{ - struct ui_out *saved_uiout = (struct ui_out *) arg; - - current_uiout = saved_uiout; -} - -/* See ui-out.h. */ - -struct cleanup * -make_cleanup_restore_current_uiout (void) -{ - return make_cleanup (restore_current_uiout_cleanup, current_uiout); -} - /* Standard gdb initialization hook. */ void diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 6a4d78a..12daafd 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -247,8 +247,29 @@ extern void ui_out_destroy (struct ui_out *uiout); extern int ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream); -/* Make a cleanup that restores the previous current uiout. */ +/* An RAII-based class that saves and restores the current uiout. */ -extern struct cleanup *make_cleanup_restore_current_uiout (void); +class scoped_restore_uiout +{ + public: + + scoped_restore_uiout () : saved (current_uiout) + { + } + + ~scoped_restore_uiout () + { + current_uiout = saved; + } + + private: + + // No need for these. They are intentionally not defined anywhere. + scoped_restore_uiout &operator= (const scoped_restore_uiout &); + scoped_restore_uiout (const scoped_restore_uiout &); + + // The saved ui out. + struct ui_out *saved; +}; #endif /* UI_OUT_H */