From patchwork Fri Apr 26 20:11:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 32430 Received: (qmail 112358 invoked by alias); 26 Apr 2019 20:11:24 -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 112300 invoked by uid 89); 26 Apr 2019 20:11:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=gdb_stdout, UD:string, string_file, restoration X-HELO: mailsec108.isp.belgacom.be Received: from mailsec108.isp.belgacom.be (HELO mailsec108.isp.belgacom.be) (195.238.20.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Apr 2019 20:11:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1556309482; x=1587845482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lYqXbCREm0PwmA87gLBsS8lecsDUU9jEbPDY09dGcjo=; b=ASm/8j3ZY1u8Wav6srRcVposOck0UPsuEcoB2xCEOdn65weB0J24/232 m2ChFGcA5n3mR1Yn7ZrPbOVoYHRLbw==; Received: from 59.151-129-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.129.151.59]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 26 Apr 2019 22:11:14 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv2 3/6] Add function execute_command_to_ui_file Date: Fri, 26 Apr 2019 22:11:05 +0200 Message-Id: <20190426201108.7489-4-philippe.waroquiers@skynet.be> In-Reply-To: <20190426201108.7489-1-philippe.waroquiers@skynet.be> References: <20190426201108.7489-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 2019-04-26 Philippe Waroquiers * gdbcmd.h (execute_command_to_ui_file): New declaration. top.c (execute_command_to_ui_file): New function, mostly a copy of execute_command_to_string. (execute_command_to_string): Implement by calling execute_command_to_ui_file. --- gdb/gdbcmd.h | 2 ++ gdb/top.c | 33 +++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h index 4614ec748c..14c0b80bac 100644 --- a/gdb/gdbcmd.h +++ b/gdb/gdbcmd.h @@ -134,6 +134,8 @@ extern struct cmd_list_element *save_cmdlist; extern void execute_command (const char *, int); extern std::string execute_command_to_string (const char *p, int from_tty); +extern void execute_command_to_ui_file (struct ui_file *file, + const char *p, int from_tty); extern void print_command_line (struct command_line *, unsigned int, struct ui_file *); diff --git a/gdb/top.c b/gdb/top.c index 93fed2ed80..bd68ba182b 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -665,12 +665,12 @@ execute_command (const char *p, int from_tty) cleanup_if_error.release (); } -/* Run execute_command for P and FROM_TTY. Capture its output into the - returned string, do not display it to the screen. BATCH_FLAG will be +/* Run execute_command for P and FROM_TTY. Sends its output to FILE, + do not display it to the screen. BATCH_FLAG will be temporarily set to true. */ -std::string -execute_command_to_string (const char *p, int from_tty) +void +execute_command_to_ui_file (struct ui_file *file, const char *p, int from_tty) { /* GDB_STDOUT should be better already restored during these restoration callbacks. */ @@ -678,26 +678,35 @@ execute_command_to_string (const char *p, int from_tty) scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); - string_file str_file; - { - current_uiout->redirect (&str_file); + current_uiout->redirect (file); ui_out_redirect_pop redirect_popper (current_uiout); scoped_restore save_stdout - = make_scoped_restore (&gdb_stdout, &str_file); + = make_scoped_restore (&gdb_stdout, file); scoped_restore save_stderr - = make_scoped_restore (&gdb_stderr, &str_file); + = make_scoped_restore (&gdb_stderr, file); scoped_restore save_stdlog - = make_scoped_restore (&gdb_stdlog, &str_file); + = make_scoped_restore (&gdb_stdlog, file); scoped_restore save_stdtarg - = make_scoped_restore (&gdb_stdtarg, &str_file); + = make_scoped_restore (&gdb_stdtarg, file); scoped_restore save_stdtargerr - = make_scoped_restore (&gdb_stdtargerr, &str_file); + = make_scoped_restore (&gdb_stdtargerr, file); execute_command (p, from_tty); } +} + +/* Run execute_command for P and FROM_TTY. Capture its output into the + returned string, do not display it to the screen. BATCH_FLAG will be + temporarily set to true. */ + +std::string +execute_command_to_string (const char *p, int from_tty) +{ + string_file str_file; + execute_command_to_ui_file (&str_file, p, from_tty); return std::move (str_file.string ()); }