From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id 89EB339540EC for ; Tue, 6 Oct 2020 15:48:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 89EB339540EC IronPort-SDR: jfee/k+GipsLdxRnCHAOD8qmBj4oqNj049BaKSgBkirEHeFBjZWHP7Iw1yBOd4R8SXnxIshuCU G15tbaxk6HnA== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="143936442" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="143936442" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 08:41:00 -0700 IronPort-SDR: wRbVq2GWGOHcVPtmF9EkzOIoSfN94X1hgu3rFpb7zVsTf5p8FS+QSoWB5p2bWLOnYFHifZtnRj J5HMMXO6vARA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="327604579" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga002.jf.intel.com with ESMTP; 06 Oct 2020 08:40:54 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 096Ferch022337; Tue, 6 Oct 2020 16:40:53 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id 096FereJ022346; Tue, 6 Oct 2020 17:40:53 +0200 Received: (from taktemur@localhost) by ulvlx001.iul.intel.com with LOCAL id 096FerPa022342; Tue, 6 Oct 2020 17:40:53 +0200 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH] gdb/cli: if redirecting output, also redirect top-level interpreter's ui-out Date: Tue, 6 Oct 2020 17:40:42 +0200 Message-Id: <1601998842-22089-1-git-send-email-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 1.7.0.7 X-Spam-Status: No, score=-15.7 required=5.0 tests=AC_FROM_MANY_DOTS, BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Tue, 06 Oct 2020 15:48:23 -0000 When executing commands from Python, the API provides an option to capture the command output in a string and return this to the user. See the `gdb.execute` function at https://sourceware.org/gdb/onlinedocs/gdb/Basic-Python.html#Basic-Python When the `to_string` argument is True, the output of the executed command is supposed to be captured and returned to the caller. For this, GDB temporarily redirects the ui-outs to a string file. However, output does not get captured if the executed command prints its output through the top-level interpreter's ui-out. E.g., in the following we still see the output being printed. (gdb) python gdb.execute("inferior 1", from_tty=False, to_string=True) [Switching to inferior 1 [] ()] (gdb) To fix, also redirect the top-level interpreter's ui-out. gdb/ChangeLog: 2020-10-06 Tankut Baris Aktemur * cli/cli-script.c (execute_control_commands_to_string): Redirect top level interpreter's ui-out before running the command. --- gdb/cli/cli-script.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index f8ac610d4d6..21a4065a5f2 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -425,6 +425,10 @@ execute_control_commands_to_string (struct command_line *commands, current_uiout->redirect (&str_file); ui_out_redirect_pop redirect_popper (current_uiout); + ui_out *uiout = top_level_interpreter ()->interp_ui_out (); + uiout->redirect (&str_file); + ui_out_redirect_pop redirect_popper2 (uiout); + scoped_restore save_stdout = make_scoped_restore (&gdb_stdout, &str_file); scoped_restore save_stderr -- 2.17.1