From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mF6SOnD29mKv9CUAWB0awg (envelope-from ) for ; Fri, 12 Aug 2022 20:55:12 -0400 Received: by simark.ca (Postfix, from userid 112) id ECD2C1E5EA; Fri, 12 Aug 2022 20:55:12 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=fvUNZhes; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 413BB1E13B for ; Fri, 12 Aug 2022 20:55:12 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4A8738582AD for ; Sat, 13 Aug 2022 00:55:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4A8738582AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660352111; bh=bcLMxK+L3nvCoB42tR0RJevKp32v2IcpBCMYM2/KuEc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fvUNZhesZsZkdxPCBHZhItMFlw53O+N0A1ki+kw9yxRKLRSbIRqX32Qtw7EpEPmLy ScQxsw2V3BcFCF6WBlukDx63Y4U6ysUzzrxHrhMQbsclarAquhcNjk+sSIxjM+PcyC SRkIn+OZ4sRTdS0toydKDu0DZ0b5gBVjMeRtEZwI= Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id C24E53858C2C for ; Sat, 13 Aug 2022 00:54:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C24E53858C2C Received: by mail-io1-xd2f.google.com with SMTP id x64so2089500iof.1 for ; Fri, 12 Aug 2022 17:54:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bcLMxK+L3nvCoB42tR0RJevKp32v2IcpBCMYM2/KuEc=; b=3F8y7jHKZIRNaDL/SL3xaLaW/RLnP+OxIIS4Brn0jE5pgxvcDxB69EbGacMeW9eFTz CPU74oUwW0C+CvJ2OGlXeIYcPnIAu72YIlTkn3B8iCBFu3WkD7g3Pb8DIbd/UqqWhbZS 5reZrryTbOAlL8iJvp8wWLm1rsx3lg1gd3E1syTc93pad864ilINVqkTAlxzO6QVL7rw sfcC5ro59wXySIFMIDYsMGT7L3x5kZEYb5sBgessFqYNKEcDzVBYUX/1Cm4/zOpkYBZ7 cBWe4kcvtzJb/wejGpEoRtDuZXdj1Q3M4sarZ/j1189miEKX2uMW2BczkZIOnBxjGd3N 4+kg== X-Gm-Message-State: ACgBeo06N/f2f3qV0jWGtFSqqFCyCvbcZpjuQeYKSVnjlFjkBkEN7icF /2uDDrUdUMraSC8jfyWu3pd32G988CZPKQ== X-Google-Smtp-Source: AA6agR5JpVKuLBauu9tnKH5rjsajcrFfYLdMXTrYw02RgT1lDOhazkOqPOhWNze9grGDEV9cBlAzEA== X-Received: by 2002:a05:6602:2dc4:b0:648:adac:bae8 with SMTP id l4-20020a0566022dc400b00648adacbae8mr2691857iow.9.1660352087044; Fri, 12 Aug 2022 17:54:47 -0700 (PDT) Received: from murgatroyd.Home (71-211-185-228.hlrn.qwest.net. [71.211.185.228]) by smtp.gmail.com with ESMTPSA id p17-20020a056638217100b00343455007f7sm494366jak.110.2022.08.12.17.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Aug 2022 17:54:46 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 03/14] Use ui_out_redirect_pop in more places Date: Fri, 12 Aug 2022 18:54:31 -0600 Message-Id: <20220813005442.4163512-4-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220813005442.4163512-1-tromey@adacore.com> References: <20220813005442.4163512-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom Tromey via Gdb-patches Reply-To: Tom Tromey Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This changes ui_out_redirect_pop to also perform the redirection, and then updates several sites to use this, rather than explicit redirects. --- gdb/breakpoint.c | 13 ++----------- gdb/guile/scm-breakpoint.c | 3 +-- gdb/guile/scm-ports.c | 3 +-- gdb/mi/mi-interp.c | 29 ++++++++--------------------- gdb/python/py-breakpoint.c | 4 +--- gdb/top.c | 3 +-- gdb/ui-out.h | 6 ++++-- 7 files changed, 18 insertions(+), 43 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index dae96d205be..0329c1a47c6 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -14049,18 +14049,9 @@ save_breakpoints (const char *filename, int from_tty, { fp.puts (" commands\n"); - current_uiout->redirect (&fp); - try - { - print_command_lines (current_uiout, tp->commands.get (), 2); - } - catch (const gdb_exception &ex) - { - current_uiout->redirect (NULL); - throw; - } + ui_out_redirect_pop redir (current_uiout, &fp); + print_command_lines (current_uiout, tp->commands.get (), 2); - current_uiout->redirect (NULL); fp.puts (" end\n"); } diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index 5406b74a389..a7799416c50 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -999,10 +999,10 @@ gdbscm_breakpoint_commands (SCM self) string_file buf; - current_uiout->redirect (&buf); gdbscm_gdb_exception exc {}; try { + ui_out_redirect_pop redir (current_uiout, &buf); print_command_lines (current_uiout, breakpoint_commands (bp), 0); } catch (const gdb_exception &except) @@ -1010,7 +1010,6 @@ gdbscm_breakpoint_commands (SCM self) exc = unpack (except); } - current_uiout->redirect (NULL); GDBSCM_HANDLE_GDB_EXCEPTION (exc); result = gdbscm_scm_from_c_string (buf.c_str ()); diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c index 946859aa1f3..9173cb6f26e 100644 --- a/gdb/guile/scm-ports.c +++ b/gdb/guile/scm-ports.c @@ -607,8 +607,7 @@ ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport, gdb_stderr = port_file.get (); else { - current_uiout->redirect (port_file.get ()); - redirect_popper.emplace (current_uiout); + redirect_popper.emplace (current_uiout, port_file.get ()); gdb_stdout = port_file.get (); } diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index ae15177890c..6633a7fa0a8 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -816,16 +816,14 @@ mi_tsv_modified (const struct trace_state_variable *tsv) gdb_printf (mi->event_channel, "tsv-modified"); - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); mi_uiout->field_string ("name", tsv->name); mi_uiout->field_string ("initial", - plongest (tsv->initial_value)); + plongest (tsv->initial_value)); if (tsv->value_known) mi_uiout->field_string ("current", plongest (tsv->value)); - mi_uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -844,7 +842,7 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, breakpoint *bp) break if anything is output to mi_uiout prior to calling the breakpoint_created notifications. So, we use ui_out_redirect. */ - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); try { @@ -857,8 +855,6 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, breakpoint *bp) { exception_print (gdb_stderr, ex); } - - mi_uiout->redirect (NULL); } /* Emit notification about a created breakpoint. */ @@ -1090,12 +1086,10 @@ mi_solib_loaded (struct so_list *solib) gdb_printf (mi->event_channel, "library-loaded"); - uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (uiout, mi->event_channel); mi_output_solib_attribs (uiout, solib); - uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1118,7 +1112,7 @@ mi_solib_unloaded (struct so_list *solib) gdb_printf (mi->event_channel, "library-unloaded"); - uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (uiout, mi->event_channel); uiout->field_string ("id", solib->so_original_name); uiout->field_string ("target-name", solib->so_original_name); @@ -1128,8 +1122,6 @@ mi_solib_unloaded (struct so_list *solib) uiout->field_fmt ("thread-group", "i%d", current_inferior ()->num); } - uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1157,13 +1149,11 @@ mi_command_param_changed (const char *param, const char *value) gdb_printf (mi->event_channel, "cmd-param-changed"); - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); mi_uiout->field_string ("param", param); mi_uiout->field_string ("value", value); - mi_uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1193,7 +1183,7 @@ mi_memory_changed (struct inferior *inferior, CORE_ADDR memaddr, gdb_printf (mi->event_channel, "memory-changed"); - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); mi_uiout->field_fmt ("thread-group", "i%d", inferior->num); mi_uiout->field_core_addr ("addr", target_gdbarch (), memaddr); @@ -1210,8 +1200,6 @@ mi_memory_changed (struct inferior *inferior, CORE_ADDR memaddr, mi_uiout->field_string ("type", "code"); } - mi_uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1243,8 +1231,7 @@ mi_user_selected_context_changed (user_selected_what selection) mi_uiout = top_level_interpreter ()->interp_ui_out (); - mi_uiout->redirect (mi->event_channel); - ui_out_redirect_pop redirect_popper (mi_uiout); + ui_out_redirect_pop redirect_popper (mi_uiout, mi->event_channel); target_terminal::scoped_restore_terminal_state term_state; target_terminal::ours_for_output (); diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 48ec86cebfe..dd4519a1b05 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -548,19 +548,17 @@ bppy_get_commands (PyObject *self, void *closure) string_file stb; - current_uiout->redirect (&stb); try { + ui_out_redirect_pop redir (current_uiout, &stb); print_command_lines (current_uiout, breakpoint_commands (bp), 0); } catch (const gdb_exception &except) { - current_uiout->redirect (NULL); gdbpy_convert_exception (except); return NULL; } - current_uiout->redirect (NULL); return host_string_to_python_string (stb.c_str ()).release (); } diff --git a/gdb/top.c b/gdb/top.c index 10983919011..655bcd77598 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -735,8 +735,7 @@ execute_fn_to_ui_file (struct ui_file *file, std::function fn) scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); { - current_uiout->redirect (file); - ui_out_redirect_pop redirect_popper (current_uiout); + ui_out_redirect_pop redirect_popper (current_uiout, file); scoped_restore save_stdout = make_scoped_restore (&gdb_stdout, file); diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 9e6ff9a29bf..9c455d3ed67 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -427,15 +427,17 @@ class ui_out_emit_table struct ui_out *m_uiout; }; -/* On destruction, pop the last redirection by calling the uiout's +/* On construction, redirect a uiout to a given stream. 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) + ui_out_redirect_pop (ui_out *uiout, ui_file *stream) : m_uiout (uiout) { + m_uiout->redirect (stream); } ~ui_out_redirect_pop () -- 2.34.1