public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 3/3] Don't let gdb_stdlog use pager
Date: Thu, 17 Nov 2022 11:29:04 -0700	[thread overview]
Message-ID: <20221117182904.1291713-4-tromey@adacore.com> (raw)
In-Reply-To: <20221117182904.1291713-1-tromey@adacore.com>

When using the "set logging" commands, cli_interp_base::set_logging
will send gdb_stdlog output (among others) to the tee it makes for
gdb_stdout.  However, this has the side effect of also causing logging
to use the pager.  This is PR gdb/29787.

This patch fixes the problem by keeping stderr and stdlog separate
from stdout, preserving the rule that only gdb_stdout should page.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29787
---
 gdb/cli/cli-interp.c | 24 ++++++++++++++----------
 gdb/cli/cli-interp.h |  1 +
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 2e8f6135405..3254efc3581 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -389,24 +389,28 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
       ui_file *logfile_p = logfile.get ();
       m_saved_output->file_to_delete = std::move (logfile);
 
-      /* If something is not being redirected, then a tee containing both the
-	 logfile and stdout.  */
-      ui_file *tee = nullptr;
-      if (!logging_redirect || !debug_redirect)
+      /* The new stdout and stderr only depend on whether logging
+	 redirection is being done.  */
+      ui_file *new_stdout = logfile_p;
+      ui_file *new_stderr = logfile_p;
+      if (!logging_redirect)
 	{
 	  m_saved_output->tee_to_delete.reset
 	    (new tee_file (gdb_stdout, logfile_p));
-	  tee = m_saved_output->tee_to_delete.get ();
+	  new_stdout = m_saved_output->tee_to_delete.get ();
+	  m_saved_output->stderr_to_delete.reset
+	    (new tee_file (gdb_stderr, logfile_p));
+	  new_stderr = m_saved_output->stderr_to_delete.get ();
 	}
 
       m_saved_output->log_to_delete.reset
-	(new timestamped_file (debug_redirect ? logfile_p : tee));
+	(new timestamped_file (debug_redirect ? logfile_p : new_stderr));
 
-      gdb_stdout = logging_redirect ? logfile_p : tee;
+      gdb_stdout = new_stdout;
       gdb_stdlog = m_saved_output->log_to_delete.get ();
-      gdb_stderr = logging_redirect ? logfile_p : tee;
-      gdb_stdtarg = logging_redirect ? logfile_p : tee;
-      gdb_stdtargerr = logging_redirect ? logfile_p : tee;
+      gdb_stderr = new_stderr;
+      gdb_stdtarg = new_stderr;
+      gdb_stdtargerr = new_stderr;
     }
   else
     {
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index fa007d78621..978e7f291e4 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -42,6 +42,7 @@ class cli_interp_base : public interp
     ui_file *targ;
     ui_file *targerr;
     ui_file_up tee_to_delete;
+    ui_file_up stderr_to_delete;
     ui_file_up file_to_delete;
     ui_file_up log_to_delete;
   };
-- 
2.34.3


  parent reply	other threads:[~2022-11-17 18:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17 18:29 [PATCH 0/3] Do not let logging " Tom Tromey
2022-11-17 18:29 ` [PATCH 1/3] Remove 'saved_output' global Tom Tromey
2022-11-17 18:29 ` [PATCH 2/3] Don't let tee_file own a stream Tom Tromey
2022-11-28 19:18   ` Simon Marchi
2022-11-28 20:29     ` Tom Tromey
2022-11-17 18:29 ` Tom Tromey [this message]
2022-11-28 19:23   ` [PATCH 3/3] Don't let gdb_stdlog use pager Simon Marchi
2022-11-28 20:34     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221117182904.1291713-4-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).