From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16238 invoked by alias); 9 Sep 2010 21:33:20 -0000 Received: (qmail 16228 invoked by uid 22791); 9 Sep 2010 21:33:18 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_TD,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Sep 2010 21:33:12 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o89LXB5k019143 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 9 Sep 2010 17:33:11 -0400 Received: from host1.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o89LX8t5014092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 9 Sep 2010 17:33:10 -0400 Received: from host1.dyn.jankratochvil.net (localhost [127.0.0.1]) by host1.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o89LX8oG032269; Thu, 9 Sep 2010 23:33:08 +0200 Received: (from jkratoch@localhost) by host1.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o89LX7fq032268; Thu, 9 Sep 2010 23:33:07 +0200 Date: Fri, 10 Sep 2010 13:02:00 -0000 From: Jan Kratochvil To: Paul Bolle Cc: gdb-patches@sourceware.org Subject: Re: [patch] Fix uiout for execute_command_to_string Message-ID: <20100909213307.GA32018@host1.dyn.jankratochvil.net> References: <20100903180619.GA15409@host1.dyn.jankratochvil.net> <1283551592.3230.27.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1283551592.3230.27.camel@localhost.localdomain> User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-09/txt/msg00213.txt.bz2 On Sat, 04 Sep 2010 00:06:31 +0200, Paul Bolle wrote: > It seems I need the (trivial) patch below (to be applied on your recent > work) to also get the output from remote commands invoked by the python > command redirected to a string. Example: > > foo = gdb.execute("monitor foo", to_string=True) Updated the patch with this part. Paul Bolle said he does not have a signed FSF copyright assignment; if it matters in this case. Redirected also gdb_stdtargerr although I did not verify that part, IMO FSF gdbserver cannot send inferior data to it. No regressions on {x86_64,x86_64-m32,i686}-fedora14snapshot-linux-gnu. Only for nat, I did not regression test it against gdbserver, though. OK to check-in? Thanks, Jan gdb/ 2010-09-09 Jan Kratochvil Paul Bolle Redirect also uiout and stdtarg{,err} in execute_command_to_string. * cli-logging.c (struct saved_output_files) : New. (set_logging_redirect, pop_output_files, handle_redirections): Redirect also gdb_stdtargerr. * defs.h (struct ui_out, make_cleanup_ui_out_redirect_pop): New declarations. * event-top.c (gdb_setup_readline, gdb_disable_readline): Redirect also gdb_stdtargerr. * top.c (execute_command_to_string): Move make_cleanup_ui_file_delete to the top. Redirect also gdb_stdlog, gdb_stdtarg and gdb_stdtargerr. Use ui_out_redirect, register make_cleanup_ui_out_redirect_pop. * tui/tui-io.c (tui_setup_io): Redirect also gdb_stdtargerr. * utils.c (do_ui_out_redirect_pop, make_cleanup_ui_out_redirect_pop): New functions. gdb/testsuite/ 2010-09-09 Jan Kratochvil * gdb.python/python.exp (set height 0, collect help from uiout) (verify help to uiout): New tests. --- a/gdb/cli/cli-logging.c +++ b/gdb/cli/cli-logging.c @@ -33,6 +33,7 @@ struct saved_output_files struct ui_file *err; struct ui_file *log; struct ui_file *targ; + struct ui_file *targerr; }; static struct saved_output_files saved_output; static char *saved_filename; @@ -116,6 +117,7 @@ set_logging_redirect (char *args, int from_tty, struct cmd_list_element *c) gdb_stderr = output; gdb_stdlog = output; gdb_stdtarg = output; + gdb_stdtargerr = output; logging_no_redirect_file = new_logging_no_redirect_file; /* There is a former output pushed on the ui_out_redirect stack. We want to @@ -154,10 +156,12 @@ pop_output_files (void) gdb_stderr = saved_output.err; gdb_stdlog = saved_output.log; gdb_stdtarg = saved_output.targ; + gdb_stdtargerr = saved_output.targ; saved_output.out = NULL; saved_output.err = NULL; saved_output.log = NULL; saved_output.targ = NULL; + saved_output.targerr = NULL; ui_out_redirect (uiout, NULL); } @@ -211,11 +215,13 @@ handle_redirections (int from_tty) saved_output.err = gdb_stderr; saved_output.log = gdb_stdlog; saved_output.targ = gdb_stdtarg; + saved_output.targerr = gdb_stdtargerr; gdb_stdout = output; gdb_stderr = output; gdb_stdlog = output; gdb_stdtarg = output; + gdb_stdtargerr = output; if (ui_out_redirect (uiout, output) < 0) warning (_("Current output protocol does not support redirection")); --- a/gdb/defs.h +++ b/gdb/defs.h @@ -337,6 +337,10 @@ extern struct cleanup *make_cleanup_freeargv (char **); struct ui_file; extern struct cleanup *make_cleanup_ui_file_delete (struct ui_file *); +struct ui_out; +extern struct cleanup * + make_cleanup_ui_out_redirect_pop (struct ui_out *uiout); + struct section_addr_info; extern struct cleanup *(make_cleanup_free_section_addr_info (struct section_addr_info *)); --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -1048,6 +1048,7 @@ gdb_setup_readline (void) gdb_stderr = stdio_fileopen (stderr); gdb_stdlog = gdb_stderr; /* for moment */ gdb_stdtarg = gdb_stderr; /* for moment */ + gdb_stdtargerr = gdb_stderr; /* for moment */ /* If the input stream is connected to a terminal, turn on editing. */ @@ -1106,6 +1107,7 @@ gdb_disable_readline (void) ui_file_delete (gdb_stderr); gdb_stdlog = NULL; gdb_stdtarg = NULL; + gdb_stdtargerr = NULL; #endif rl_callback_handler_remove (); --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -149,6 +149,12 @@ gdb_test_multiple "python print \"\\n\" * $lines" $test { } gdb_test "q" "Quit" "verify pagination afterwards: q" +gdb_test_no_output "set height 0" + +gdb_test_no_output "python a = gdb.execute('help', to_string=True)" "collect help from uiout" + +gdb_test "python print a" ".*aliases -- Aliases of other commands.*" "verify help to uiout" + # Start with a fresh gdb. clean_restart ${testfile} --- a/gdb/top.c +++ b/gdb/top.c @@ -475,12 +475,23 @@ execute_command_to_string (char *p, int from_tty) str_file = mem_fileopen (); + make_cleanup_ui_file_delete (str_file); make_cleanup_restore_ui_file (&gdb_stdout); make_cleanup_restore_ui_file (&gdb_stderr); - make_cleanup_ui_file_delete (str_file); + make_cleanup_restore_ui_file (&gdb_stdlog); + make_cleanup_restore_ui_file (&gdb_stdtarg); + make_cleanup_restore_ui_file (&gdb_stdtargerr); + + if (ui_out_redirect (uiout, str_file) < 0) + warning (_("Current output protocol does not support redirection")); + else + make_cleanup_ui_out_redirect_pop (uiout); gdb_stdout = str_file; gdb_stderr = str_file; + gdb_stdlog = str_file; + gdb_stdtarg = str_file; + gdb_stdtargerr = str_file; execute_command (p, from_tty); --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -545,6 +545,7 @@ tui_setup_io (int mode) gdb_stderr = tui_stderr; gdb_stdlog = gdb_stdout; /* for moment */ gdb_stdtarg = gdb_stderr; /* for moment */ + gdb_stdtargerr = gdb_stderr; /* for moment */ uiout = tui_out; /* Save tty for SIGCONT. */ @@ -557,6 +558,7 @@ tui_setup_io (int mode) gdb_stderr = tui_old_stderr; gdb_stdlog = gdb_stdout; /* for moment */ gdb_stdtarg = gdb_stderr; /* for moment */ + gdb_stdtargerr = gdb_stderr; /* for moment */ uiout = tui_old_uiout; /* Restore readline. */ --- a/gdb/utils.c +++ b/gdb/utils.c @@ -312,6 +312,21 @@ make_cleanup_ui_file_delete (struct ui_file *arg) } static void +do_ui_out_redirect_pop (void *arg) +{ + struct ui_out *uiout = arg; + + if (ui_out_redirect (uiout, NULL) < 0) + warning (_("Cannot restore redirection of the current output protocol")); +} + +struct cleanup * +make_cleanup_ui_out_redirect_pop (struct ui_out *uiout) +{ + return make_my_cleanup (&cleanup_chain, do_ui_out_redirect_pop, uiout); +} + +static void do_free_section_addr_info (void *arg) { free_section_addr_info (arg);