From patchwork Thu Sep 15 03:23:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 15650 Received: (qmail 97363 invoked by alias); 15 Sep 2016 03:24:38 -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 97270 invoked by uid 89); 15 Sep 2016 03:24:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:sk:cable-1, H*RU:sk:cable-1, H*r:sk:cable-1, simark.ca X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Sep 2016 03:24:06 +0000 Received: from [10.0.0.11] (cable-11.246.173-162.electronicbox.net [173.246.11.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 67F331E13F; Wed, 14 Sep 2016 23:24:04 -0400 (EDT) Subject: Re: [PATCH master+7.12 v2 1/3] Introduce cleanup to restore current_uiout To: Pedro Alves , Simon Marchi , gdb-patches@sourceware.org References: <20160914174548.5873-1-simon.marchi@ericsson.com> <20160914174548.5873-2-simon.marchi@ericsson.com> <1f255130-b5ca-86a1-c774-ec543b44f7d9@redhat.com> From: Simon Marchi Message-ID: Date: Wed, 14 Sep 2016 23:23:58 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1f255130-b5ca-86a1-c774-ec543b44f7d9@redhat.com> On 14/09/16 01:56 PM, Pedro Alves wrote: > On 09/14/2016 06:45 PM, Simon Marchi wrote: >> Make a globally available cleanup from a pre-existing one in infrun.c. >> This is used in the following patch. >> >> gdb/ChangeLog: >> >> * infrun.c (restore_current_uiout_cleanup): Move to ui-out.c. >> (print_stop_event): Use make_cleanup_restore_current_uiout. >> * ui-out.c (restore_current_uiout_cleanup): Move from infrun.c. >> (make_cleanup_restore_current_uiout): New function definition. >> * ui-out.h (make_cleanup_restore_current_uiout): New function >> definition. > > OK. > > Thanks, > Pedro Alves A little addition, I replace the usage of make_cleanup_restore_ui_out in python.c by this new make_cleanup_restore_current_uiout, and remove make_cleanupt_restore_ui_out. From 21169da5b93b01a1c83174f79e6a377c7049974a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 13 Sep 2016 16:44:05 -0400 Subject: [PATCH] Introduce cleanup to restore current_uiout Make a globally available cleanup from a pre-existing one in infrun.c. This is used in the following patch. gdb/ChangeLog: * infrun.c (restore_current_uiout_cleanup): Move to ui-out.c. (print_stop_event): Use make_cleanup_restore_current_uiout. * python/python.c (execute_gdb_command): Likewise. * ui-out.c (restore_current_uiout_cleanup): Move from infrun.c. (make_cleanup_restore_current_uiout): New function definition. * ui-out.h (make_cleanup_restore_current_uiout): New function declaration. * utils.c (do_restore_ui_out): Remove. (make_cleanup_restore_ui_out): Remove. * utils.h (make_cleanup_restore_ui_out): Remove. --- gdb/infrun.c | 12 +----------- gdb/python/python.c | 3 ++- gdb/ui-out.c | 18 ++++++++++++++++++ gdb/ui-out.h | 4 ++++ gdb/utils.c | 23 ----------------------- gdb/utils.h | 3 --- 6 files changed, 25 insertions(+), 38 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 70d7a09..ec37ca1 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8096,16 +8096,6 @@ print_stop_location (struct target_waitstatus *ws) print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1); } -/* 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 infrun.h. */ void @@ -8118,7 +8108,7 @@ print_stop_event (struct ui_out *uiout) get_last_target_status (&last_ptid, &last); - old_chain = make_cleanup (restore_current_uiout_cleanup, current_uiout); + old_chain = make_cleanup_restore_current_uiout (); current_uiout = uiout; print_stop_location (&last); diff --git a/gdb/python/python.c b/gdb/python/python.c index 621e201..b00b70b 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -654,7 +654,8 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) make_cleanup_restore_integer (¤t_ui->async); current_ui->async = 0; - make_cleanup_restore_ui_out (¤t_uiout); + make_cleanup_restore_current_uiout (); + /* Use the console interpreter uiout to have the same print format for console or MI. */ interp = interp_lookup (current_ui, "console"); diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 3972a56..ec44ab6 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -953,6 +953,24 @@ 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 9e1e74d..6a4d78a 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -247,4 +247,8 @@ 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. */ + +extern struct cleanup *make_cleanup_restore_current_uiout (void); + #endif /* UI_OUT_H */ diff --git a/gdb/utils.c b/gdb/utils.c index 5188828..2afff80 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -338,29 +338,6 @@ struct restore_ui_out_closure struct ui_out *value; }; -static void -do_restore_ui_out (void *p) -{ - struct restore_ui_out_closure *closure - = (struct restore_ui_out_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_ui_out (struct ui_out **variable) -{ - struct restore_ui_out_closure *c = XNEW (struct restore_ui_out_closure); - - c->variable = variable; - c->value = *variable; - - return make_cleanup_dtor (do_restore_ui_out, (void *) c, xfree); -} - struct restore_ui_file_closure { struct ui_file **variable; diff --git a/gdb/utils.h b/gdb/utils.h index 6080f5b..bf77d7d 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -93,9 +93,6 @@ extern struct cleanup *make_cleanup_restore_uinteger (unsigned int *variable); struct target_ops; extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops); - -extern struct cleanup * - make_cleanup_restore_ui_out (struct ui_out **variable); extern struct cleanup * make_cleanup_restore_ui_file (struct ui_file **variable);