From: Tom Tromey via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 2/2] Fix flush for sys.stderr
Date: Mon, 15 Aug 2022 12:50:09 -0600 [thread overview]
Message-ID: <20220815185009.1288079-3-tromey@adacore.com> (raw)
In-Reply-To: <20220815185009.1288079-1-tromey@adacore.com>
GDB overwrites Python's sys.stdout and sys.stderr, but does not
properly implement the 'flush' method -- it only ever will flush
stdout. This patch fixes the bug. I couldn't find a straightforward
way to write a test for this.
---
gdb/python/lib/gdb/__init__.py | 19 +++++++------------
gdb/testsuite/gdb.python/python.exp | 4 ++--
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 5b10e3e2381..191915e4f3b 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -39,6 +39,9 @@ class _GdbFile(object):
encoding = "UTF-8"
errors = "strict"
+ def __init__(self, stream):
+ self.stream = stream
+
def close(self):
# Do nothing.
return None
@@ -51,23 +54,15 @@ class _GdbFile(object):
self.write(line)
def flush(self):
- flush()
-
+ flush(stream=self.stream)
-class _GdbOutputFile(_GdbFile):
def write(self, s):
- write(s, stream=STDOUT)
-
+ write(s, stream=self.stream)
-sys.stdout = _GdbOutputFile()
-
-
-class _GdbOutputErrorFile(_GdbFile):
- def write(self, s):
- write(s, stream=STDERR)
+sys.stdout = _GdbFile(STDOUT)
-sys.stderr = _GdbOutputErrorFile()
+sys.stderr = _GdbFile(STDERR)
# Default prompt hook does nothing.
prompt_hook = None
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 8c0da6daa26..48ff07e91e5 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -297,8 +297,8 @@ with_test_prefix "test decode_line" {
}
# gdb.write
-gdb_test "python print (sys.stderr)" ".*gdb._GdbOutputErrorFile (instance|object) at.*" "test stderr location"
-gdb_test "python print (sys.stdout)" ".*gdb._GdbOutputFile (instance|object) at.*" "test stdout location"
+gdb_test "python print (sys.stderr)" ".*gdb._GdbFile (instance|object) at.*" "test stderr location"
+gdb_test "python print (sys.stdout)" ".*gdb._GdbFile (instance|object) at.*" "test stdout location"
gdb_test "python gdb.write(\"Foo\\n\")" "Foo" "test default write"
gdb_test "python gdb.write(\"Error stream\\n\", stream=gdb.STDERR)" "Error stream" "test stderr write"
gdb_test "python gdb.write(\"Normal stream\\n\", stream=gdb.STDOUT)" "Normal stream" "test stdout write"
--
2.34.1
next prev parent reply other threads:[~2022-08-15 18:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 18:50 [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches
2022-08-15 18:50 ` [PATCH 1/2] Fix gdb.flush documentation Tom Tromey via Gdb-patches
2022-08-15 19:00 ` Eli Zaretskii via Gdb-patches
2022-08-15 18:50 ` Tom Tromey via Gdb-patches [this message]
2022-08-30 17:49 ` [PATCH 0/2] Fix two small Python flush problems Tom Tromey via Gdb-patches
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=20220815185009.1288079-3-tromey@adacore.com \
--to=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/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