From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id F169B38582A7; Wed, 31 Aug 2022 17:14:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F169B38582A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661966059; bh=0ylJWaKh7f2Y6+ioxSfz2Xrh7pdTLhISwvLKJr/MTeE=; h=From:To:Subject:Date:From; b=LzgyFDOl4XET4nTIPlYN+JmONHyIoqemSGtwfcXjjGSif4zUIibCMwovM+pR4W1T3 X8JfpgSUXq6u1puVXbK9VrhoO1eL5atN1j148DLK+7ysa/QHwHgrT2EqidCOEWXUMx AnJN8J5TuGOsaZzvmWDsE6cuKbON63bjg8qMqpq4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use ui_out_redirect_pop in more places X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 55a6603404099c0b61a5e4613712d3935c2e2bb6 X-Git-Newrev: 992aeed80b0a6ef1d60ce01df52f3397c3274f35 Message-Id: <20220831171419.F169B38582A7@sourceware.org> Date: Wed, 31 Aug 2022 17:14:19 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D992aeed80b0a= 6ef1d60ce01df52f3397c3274f35 commit 992aeed80b0a6ef1d60ce01df52f3397c3274f35 Author: Tom Tromey Date: Thu Aug 11 10:07:18 2022 -0600 Use ui_out_redirect_pop in more places =20 This changes ui_out_redirect_pop to also perform the redirection, and then updates several sites to use this, rather than explicit redirects. Diff: --- 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 63feea9e9cd..bff3bac7d1a 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -14058,18 +14058,9 @@ save_breakpoints (const char *filename, int from_t= ty, { fp.puts (" commands\n"); =20 - 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); =20 - current_uiout->redirect (NULL); fp.puts (" end\n"); } =20 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) =20 string_file buf; =20 - 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 =3D unpack (except); } =20 - current_uiout->redirect (NULL); GDBSCM_HANDLE_GDB_EXCEPTION (exc); result =3D gdbscm_scm_from_c_string (buf.c_str ()); =20 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 =3D port_file.get (); else { - current_uiout->redirect (port_file.get ()); - redirect_popper.emplace (current_uiout); + redirect_popper.emplace (current_uiout, port_file.get ()); =20 gdb_stdout =3D port_file.get (); } diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 368c13f5925..ed097cf5d5f 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 *t= sv) gdb_printf (mi->event_channel, "tsv-modified"); =20 - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); =20 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)); =20 - mi_uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -844,7 +842,7 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, br= eakpoint *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); =20 try { @@ -857,8 +855,6 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, br= eakpoint *bp) { exception_print (gdb_stderr, ex); } - - mi_uiout->redirect (NULL); } =20 /* Emit notification about a created breakpoint. */ @@ -1090,12 +1086,10 @@ mi_solib_loaded (struct so_list *solib) =20 gdb_printf (mi->event_channel, "library-loaded"); =20 - uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (uiout, mi->event_channel); =20 mi_output_solib_attribs (uiout, solib); =20 - uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1118,7 +1112,7 @@ mi_solib_unloaded (struct so_list *solib) =20 gdb_printf (mi->event_channel, "library-unloaded"); =20 - uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (uiout, mi->event_channel); =20 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); } =20 - uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1157,13 +1149,11 @@ mi_command_param_changed (const char *param, const = char *value) =20 gdb_printf (mi->event_channel, "cmd-param-changed"); =20 - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); =20 mi_uiout->field_string ("param", param); mi_uiout->field_string ("value", value); =20 - mi_uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1193,7 +1183,7 @@ mi_memory_changed (struct inferior *inferior, CORE_AD= DR memaddr, =20 gdb_printf (mi->event_channel, "memory-changed"); =20 - mi_uiout->redirect (mi->event_channel); + ui_out_redirect_pop redir (mi_uiout, mi->event_channel); =20 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_AD= DR memaddr, mi_uiout->field_string ("type", "code"); } =20 - mi_uiout->redirect (NULL); - gdb_flush (mi->event_channel); } } @@ -1243,8 +1231,7 @@ mi_user_selected_context_changed (user_selected_what = selection) =20 mi_uiout =3D top_level_interpreter ()->interp_ui_out (); =20 - 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); =20 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) =20 string_file stb; =20 - 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; } =20 - current_uiout->redirect (NULL); return host_string_to_python_string (stb.c_str ()).release (); } =20 diff --git a/gdb/top.c b/gdb/top.c index 18a447e701b..d8e0ee5495a 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -735,8 +735,7 @@ execute_fn_to_ui_file (struct ui_file *file, std::funct= ion fn) scoped_restore save_async =3D make_scoped_restore (¤t_ui->async, 0= ); =20 { - current_uiout->redirect (file); - ui_out_redirect_pop redirect_popper (current_uiout); + ui_out_redirect_pop redirect_popper (current_uiout, file); =20 scoped_restore save_stdout =3D make_scoped_restore (&gdb_stdout, file); diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 1d74da905e4..65d40875926 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -428,15 +428,17 @@ private: struct ui_out *m_uiout; }; =20 -/* 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: =20 - ui_out_redirect_pop (ui_out *uiout) + ui_out_redirect_pop (ui_out *uiout, ui_file *stream) : m_uiout (uiout) { + m_uiout->redirect (stream); } =20 ~ui_out_redirect_pop ()