* [PATCH] Fix logging redirection bug with pager
@ 2021-12-28 2:34 Tom Tromey
2021-12-29 3:52 ` Joel Brobecker
2021-12-30 3:06 ` Simon Marchi
0 siblings, 2 replies; 6+ messages in thread
From: Tom Tromey @ 2021-12-28 2:34 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed yesterday that if gdb output is redirected to a file, the
pager will still be active. This is irritating, because the output
isn't actually visible -- just the pager prompt. Looking in bugzilla,
I found that this had been filed 17 years ago, as PR cli/8798.
This patch fixes the bug. It changes the pagination code to query the
particular ui-file to see if paging is allowable. The ui-file
implementations are changed so that only the stdout implementation and
a tee (where one sub-file is stdout) can page.
Regression tested on x86-64 Fedora 34.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8798
---
gdb/testsuite/gdb.base/page-logging.exp | 51 +++++++++++++++++++++++++
gdb/ui-file.h | 20 ++++++++++
gdb/utils.c | 2 +-
3 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 gdb/testsuite/gdb.base/page-logging.exp
diff --git a/gdb/testsuite/gdb.base/page-logging.exp b/gdb/testsuite/gdb.base/page-logging.exp
new file mode 100644
index 00000000000..8071687b3a1
--- /dev/null
+++ b/gdb/testsuite/gdb.base/page-logging.exp
@@ -0,0 +1,51 @@
+# Copyright (C) 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Do not run if gdb debug is enabled as it will interfere with log redirect.
+if [gdb_debug_enabled] {
+ untested "debug is enabled"
+ return 0
+}
+
+gdb_start
+
+gdb_test_no_output "set width 100"
+gdb_test_no_output "set height 5"
+gdb_test_no_output "set pagination on"
+
+# Test that logging redirect disables the pager.
+set log_name [standard_output_file log.txt]
+gdb_test_no_output "set logging file $log_name" \
+ "set logging filename"
+gdb_test_no_output "set logging redirect on"
+gdb_test "set logging enabled on" "Copying debug output to .*"
+set ok 1
+set str "1\\n2\\n3\\n4\\n5\\n"
+gdb_test_multiple "printf \"$str\"" "printf without paging" {
+ -re "$pagination_prompt" {
+ set ok 0
+ send_gdb "c\n"
+ exp_continue
+ }
+ -re "\r\n$gdb_prompt $" {
+ # Ok.
+ }
+}
+if {$ok} {
+ pass "printf without paging"
+} else {
+ fail "printf without paging"
+}
+gdb_test "set logging enabled off" "Done logging to .*"
diff --git a/gdb/ui-file.h b/gdb/ui-file.h
index 9593c94e673..0faf84996aa 100644
--- a/gdb/ui-file.h
+++ b/gdb/ui-file.h
@@ -88,6 +88,14 @@ class ui_file
Otherwise, return -1. */
virtual int fd () const
{ return -1; }
+
+ /* Return true if this object supports paging, false otherwise. */
+ virtual bool can_page () const
+ {
+ /* Almost no file supports paging, which is why this is the
+ default. */
+ return false;
+ }
};
typedef std::unique_ptr<ui_file> ui_file_up;
@@ -204,6 +212,11 @@ class stdio_file : public ui_file
int fd () const override
{ return m_fd; }
+ virtual bool can_page () const override
+ {
+ return m_file == stdout;
+ }
+
private:
/* Sets the internal stream to FILE, and saves the FILE's file
descriptor in M_FD. */
@@ -278,6 +291,13 @@ class tee_file : public ui_file
bool can_emit_style_escape () override;
void flush () override;
+ virtual bool can_page () const override
+ {
+ /* If one of the underlying files can page, then we allow it
+ here. */
+ return m_one->can_page () || m_two->can_page ();
+ }
+
private:
/* The two underlying ui_files. */
ui_file *m_one;
diff --git a/gdb/utils.c b/gdb/utils.c
index 620ae9f3729..ed99fcfb179 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1749,7 +1749,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
return;
/* Don't do any filtering if it is disabled. */
- if (stream != gdb_stdout
+ if (!stream->can_page ()
|| !pagination_enabled
|| pagination_disabled_for_command
|| batch_flag
--
2.31.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix logging redirection bug with pager
2021-12-28 2:34 [PATCH] Fix logging redirection bug with pager Tom Tromey
@ 2021-12-29 3:52 ` Joel Brobecker
2021-12-30 3:06 ` Simon Marchi
1 sibling, 0 replies; 6+ messages in thread
From: Joel Brobecker @ 2021-12-29 3:52 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, Joel Brobecker
Hi Tom,
On Mon, Dec 27, 2021 at 07:34:07PM -0700, Tom Tromey wrote:
> I noticed yesterday that if gdb output is redirected to a file, the
> pager will still be active. This is irritating, because the output
> isn't actually visible -- just the pager prompt. Looking in bugzilla,
> I found that this had been filed 17 years ago, as PR cli/8798.
>
> This patch fixes the bug. It changes the pagination code to query the
> particular ui-file to see if paging is allowable. The ui-file
> implementations are changed so that only the stdout implementation and
> a tee (where one sub-file is stdout) can page.
>
> Regression tested on x86-64 Fedora 34.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8798
17 years! Thanks for the patch, LGTM.
> gdb/testsuite/gdb.base/page-logging.exp | 51 +++++++++++++++++++++++++
> gdb/ui-file.h | 20 ++++++++++
> gdb/utils.c | 2 +-
> 3 files changed, 72 insertions(+), 1 deletion(-)
> create mode 100644 gdb/testsuite/gdb.base/page-logging.exp
>
> diff --git a/gdb/testsuite/gdb.base/page-logging.exp b/gdb/testsuite/gdb.base/page-logging.exp
> new file mode 100644
> index 00000000000..8071687b3a1
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/page-logging.exp
> @@ -0,0 +1,51 @@
> +# Copyright (C) 2021 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Do not run if gdb debug is enabled as it will interfere with log redirect.
> +if [gdb_debug_enabled] {
> + untested "debug is enabled"
> + return 0
> +}
> +
> +gdb_start
> +
> +gdb_test_no_output "set width 100"
> +gdb_test_no_output "set height 5"
> +gdb_test_no_output "set pagination on"
> +
> +# Test that logging redirect disables the pager.
> +set log_name [standard_output_file log.txt]
> +gdb_test_no_output "set logging file $log_name" \
> + "set logging filename"
> +gdb_test_no_output "set logging redirect on"
> +gdb_test "set logging enabled on" "Copying debug output to .*"
> +set ok 1
> +set str "1\\n2\\n3\\n4\\n5\\n"
> +gdb_test_multiple "printf \"$str\"" "printf without paging" {
> + -re "$pagination_prompt" {
> + set ok 0
> + send_gdb "c\n"
> + exp_continue
> + }
> + -re "\r\n$gdb_prompt $" {
> + # Ok.
> + }
> +}
> +if {$ok} {
> + pass "printf without paging"
> +} else {
> + fail "printf without paging"
> +}
> +gdb_test "set logging enabled off" "Done logging to .*"
> diff --git a/gdb/ui-file.h b/gdb/ui-file.h
> index 9593c94e673..0faf84996aa 100644
> --- a/gdb/ui-file.h
> +++ b/gdb/ui-file.h
> @@ -88,6 +88,14 @@ class ui_file
> Otherwise, return -1. */
> virtual int fd () const
> { return -1; }
> +
> + /* Return true if this object supports paging, false otherwise. */
> + virtual bool can_page () const
> + {
> + /* Almost no file supports paging, which is why this is the
> + default. */
> + return false;
> + }
> };
>
> typedef std::unique_ptr<ui_file> ui_file_up;
> @@ -204,6 +212,11 @@ class stdio_file : public ui_file
> int fd () const override
> { return m_fd; }
>
> + virtual bool can_page () const override
> + {
> + return m_file == stdout;
> + }
> +
> private:
> /* Sets the internal stream to FILE, and saves the FILE's file
> descriptor in M_FD. */
> @@ -278,6 +291,13 @@ class tee_file : public ui_file
> bool can_emit_style_escape () override;
> void flush () override;
>
> + virtual bool can_page () const override
> + {
> + /* If one of the underlying files can page, then we allow it
> + here. */
> + return m_one->can_page () || m_two->can_page ();
> + }
> +
> private:
> /* The two underlying ui_files. */
> ui_file *m_one;
> diff --git a/gdb/utils.c b/gdb/utils.c
> index 620ae9f3729..ed99fcfb179 100644
> --- a/gdb/utils.c
> +++ b/gdb/utils.c
> @@ -1749,7 +1749,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
> return;
>
> /* Don't do any filtering if it is disabled. */
> - if (stream != gdb_stdout
> + if (!stream->can_page ()
> || !pagination_enabled
> || pagination_disabled_for_command
> || batch_flag
> --
> 2.31.1
>
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix logging redirection bug with pager
2021-12-28 2:34 [PATCH] Fix logging redirection bug with pager Tom Tromey
2021-12-29 3:52 ` Joel Brobecker
@ 2021-12-30 3:06 ` Simon Marchi
2021-12-30 8:36 ` Tom Tromey
1 sibling, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2021-12-30 3:06 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2021-12-27 21:34, Tom Tromey wrote:
> I noticed yesterday that if gdb output is redirected to a file, the
> pager will still be active. This is irritating, because the output
> isn't actually visible -- just the pager prompt. Looking in bugzilla,
> I found that this had been filed 17 years ago, as PR cli/8798.
>
> This patch fixes the bug. It changes the pagination code to query the
> particular ui-file to see if paging is allowable. The ui-file
> implementations are changed so that only the stdout implementation and
> a tee (where one sub-file is stdout) can page.
>
> Regression tested on x86-64 Fedora 34.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8798
Hi Tom,
I see:
41 set pagination on^M
42 (gdb) PASS: gdb.base/page-logging.exp: set pagination on
43 ^M</binutils-gdb/gdb/testsuite/outputs/gdb.base/page-logging/log.txt^M
44 (gdb) FAIL: gdb.base/page-logging.exp: set logging filename
I don't have time to dig right now, but I can do so if needed when
coming back from the holidays, if you can't reproduce. I see it on Arch
Linux and on Ubuntu.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix logging redirection bug with pager
2021-12-30 3:06 ` Simon Marchi
@ 2021-12-30 8:36 ` Tom Tromey
2022-01-03 12:32 ` Tom de Vries
0 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2021-12-30 8:36 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
Simon> 41 set pagination on^M
Simon> 42 (gdb) PASS: gdb.base/page-logging.exp: set pagination on
Simon> 43 ^M</binutils-gdb/gdb/testsuite/outputs/gdb.base/page-logging/log.txt^M
Simon> 44 (gdb) FAIL: gdb.base/page-logging.exp: set logging filename
Simon> I don't have time to dig right now, but I can do so if needed when
Simon> coming back from the holidays, if you can't reproduce. I see it on Arch
Simon> Linux and on Ubuntu.
It seems to work fine here:
$ runtest page-logging.exp
[...]
=== gdb Summary ===
# of expected passes 8
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix logging redirection bug with pager
2021-12-30 8:36 ` Tom Tromey
@ 2022-01-03 12:32 ` Tom de Vries
2022-01-03 16:00 ` Tom Tromey
0 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2022-01-03 12:32 UTC (permalink / raw)
To: Tom Tromey, Simon Marchi; +Cc: gdb-patches
On 12/30/21 09:36, Tom Tromey wrote:
> Simon> 41 set pagination on^M
> Simon> 42 (gdb) PASS: gdb.base/page-logging.exp: set pagination on
> Simon> 43 ^M</binutils-gdb/gdb/testsuite/outputs/gdb.base/page-logging/log.txt^M
> Simon> 44 (gdb) FAIL: gdb.base/page-logging.exp: set logging filename
>
> Simon> I don't have time to dig right now, but I can do so if needed when
> Simon> coming back from the holidays, if you can't reproduce. I see it on Arch
> Simon> Linux and on Ubuntu.
>
I also ran into this on openSUSE Leap 15.3.
> It seems to work fine here:
>
> $ runtest page-logging.exp
> [...]
> === gdb Summary ===
>
> # of expected passes 8
>
And I also reproduced this with fedora 34.
I guess it's about the "set logging file" command being longer than the
"width 100" that is used in the test-case. If I change it to 150, the
test passes for me, f.i. on openSUSE like this:
...
(gdb) PASS: gdb.base/page-logging.exp: set pagination on
set logging file
/home/vries/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.base/page-logging/log.txt^M
(gdb) PASS: gdb.base/page-logging.exp: set logging filename
...
Note that the "set logging file" command length is 105 chars.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix logging redirection bug with pager
2022-01-03 12:32 ` Tom de Vries
@ 2022-01-03 16:00 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2022-01-03 16:00 UTC (permalink / raw)
To: Tom de Vries; +Cc: Tom Tromey, Simon Marchi, gdb-patches
Tom> And I also reproduced this with fedora 34.
I was able to reproduce it on my work machine today. Still always
passes on my home machine.
Tom> I guess it's about the "set logging file" command being longer than
Tom> the "width 100" that is used in the test-case. If I change it to 150,
Tom> the test passes for me, f.i. on openSUSE like this:
This width setting was something I copied from a different logging
test. It's not really needed, and when I remove that command, the test
starts working. I'll send the patch and check it in shortly.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-01-03 16:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 2:34 [PATCH] Fix logging redirection bug with pager Tom Tromey
2021-12-29 3:52 ` Joel Brobecker
2021-12-30 3:06 ` Simon Marchi
2021-12-30 8:36 ` Tom Tromey
2022-01-03 12:32 ` Tom de Vries
2022-01-03 16:00 ` Tom Tromey
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).