From patchwork Sat May 4 16:17:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 32545 Received: (qmail 113607 invoked by alias); 4 May 2019 16:18:10 -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 113537 invoked by uid 89); 4 May 2019 16:18:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.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=1398, execute_command, screen, HContent-Transfer-Encoding:8bit X-HELO: mailsec106.isp.belgacom.be Received: from mailsec106.isp.belgacom.be (HELO mailsec106.isp.belgacom.be) (195.238.20.102) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 04 May 2019 16:18:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1556986688; x=1588522688; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9cDi7PERmCqxv0gNFNvkFp3AywTZ36hcTpxBKngRiv0=; b=Gv8N/ttQMqEPnqECRX49iRVNc5BZWhWl19FQI9nnHhiZqkZMdCeKqyb8 ip1suhCV7K8wqINEdYgiMB6iWXE3Rg==; 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; 04 May 2019 18:17:59 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFAv3 3/6] Add function execute_command_to_ui_file Date: Sat, 4 May 2019 18:17:50 +0200 Message-Id: <20190504161753.15530-4-philippe.waroquiers@skynet.be> In-Reply-To: <20190504161753.15530-1-philippe.waroquiers@skynet.be> References: <20190504161753.15530-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes 2019-05-04 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 | 35 ++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h index 5d0e697d83..1b47719f18 100644 --- a/gdb/gdbcmd.h +++ b/gdb/gdbcmd.h @@ -139,6 +139,8 @@ extern void execute_command (const char *, int); as cli_styling. */ extern std::string execute_command_to_string (const char *p, int from_tty, bool term_out); +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 70f685ffad..900c3fc3e2 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -665,13 +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, - bool term_out) +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. */ @@ -679,26 +678,36 @@ 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 (term_out); - { - 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, + bool term_out) +{ + string_file str_file (term_out); + execute_command_to_ui_file (&str_file, p, from_tty); return std::move (str_file.string ()); }