From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 1SroBHuV+mKMhScAWB0awg (envelope-from ) for ; Mon, 15 Aug 2022 14:50:35 -0400 Received: by simark.ca (Postfix, from userid 112) id F3C371E5EA; Mon, 15 Aug 2022 14:50:34 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=yisbrePz; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 735F21E227 for ; Mon, 15 Aug 2022 14:50:34 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 636B13858436 for ; Mon, 15 Aug 2022 18:50:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 636B13858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660589433; bh=1uLj2/5dSaYRoC0mPQZwZefOuaQ0Dgr8k8ijifTdi9k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yisbrePzBJonkByfxumGvhYD1FDrT0iO48Ae6+tkuYXFnWGhZys0UO6wOHREBAfcv Q6oq3QhAbpK6YxeTM7DYseqTjbnibPYD4LuSl/tlRWhpgHoqZWsBTb64R8rxzDlA56 qwQyD4jfBhjpX7vvmspEnH4MNC//EjgawdVWCIZ8= Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by sourceware.org (Postfix) with ESMTPS id 108483858404 for ; Mon, 15 Aug 2022 18:50:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 108483858404 Received: by mail-io1-xd2a.google.com with SMTP id h78so1363609iof.13 for ; Mon, 15 Aug 2022 11:50:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=1uLj2/5dSaYRoC0mPQZwZefOuaQ0Dgr8k8ijifTdi9k=; b=kcXO0m5QLVFQAaot7GOU2xaxoLfbfaW6f1m/6IsfnqLVdKM7P4dy8lWgj/iK9/Go3G 6uxwRwwIZjGBLCffACmL/Eh+6c3vzm4InLftzooLMfeJkjBlgn/ksoEPdiINGw7j3uLf WI2zYOKSoNkCsvEpNE6KQxTekHNF1H/OwDziqW7qbYNEEyyRR18ikXfwRi1ywHd4wzXI 3C1FO7rinNYEo6LvLAH1qJOFWsBGZMlxOWTLsD5TgIBVYCF+nrAAz4gx8fRYyJ4VUT6m tHoPoPeEXybKHlKOEIVG5EnRx13LWlJMSLqsK8tyKXXQsV4q2+pgbJUj3CNn2Y3nxJUo 8RxA== X-Gm-Message-State: ACgBeo2qa30+Ki5dixkro58ZA4BIYxgts+vbP+n+1Dc8p6WcxnFdx29X GWpavJJnkQW4+u3crOWjjvWcHc5Z7C+A5A== X-Google-Smtp-Source: AA6agR76/lYoU42aSoBLW4sC5VI81XxcZAss6zM2Bw670+jhwE6qH6LzTzRzAxT9jry5XnmgzgnhWQ== X-Received: by 2002:a05:6602:2c89:b0:67b:7e8c:11c1 with SMTP id i9-20020a0566022c8900b0067b7e8c11c1mr7361105iow.101.1660589412319; Mon, 15 Aug 2022 11:50:12 -0700 (PDT) Received: from murgatroyd.Home (71-211-185-228.hlrn.qwest.net. [71.211.185.228]) by smtp.gmail.com with ESMTPSA id f92-20020a0284e5000000b003434ba08e11sm3579728jai.115.2022.08.15.11.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 11:50:12 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 2/2] Fix flush for sys.stderr Date: Mon, 15 Aug 2022 12:50:09 -0600 Message-Id: <20220815185009.1288079-3-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815185009.1288079-1-tromey@adacore.com> References: <20220815185009.1288079-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , From: Tom Tromey via Gdb-patches Reply-To: Tom Tromey Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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