public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix flush for sys.stderr
@ 2022-08-30 17:55 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-08-30 17:55 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d83dd693901cb2588517d7296f1360d902c89f7
commit 2d83dd693901cb2588517d7296f1360d902c89f7
Author: Tom Tromey <tromey@adacore.com>
Date: Mon Aug 15 12:45:43 2022 -0600
Fix flush for sys.stderr
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.
Diff:
---
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"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-30 17:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 17:55 [binutils-gdb] Fix flush for sys.stderr 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).