From patchwork Thu Feb 20 04:12:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 38252 Received: (qmail 61564 invoked by alias); 20 Feb 2020 04:12:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 61552 invoked by uid 89); 20 Feb 2020 04:12:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=dirty, IRC, irc X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Feb 2020 04:12:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582171943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=24SmK/AMe42hWf2qzN68YfvsnN2+2RrmJeT/B0YoGuM=; b=Db4XDXF4wASEpheXsaGzq1msMKvvmlvGCSEPqfTiJOi08QO2q+lknLPlcvlQ9CsnXv+Pez m5ZGh9GqKDFhONFxxHmoSSlkgzwy2MG07D2bp0gJUJzrnMd3VbzPmj81+ns5iMgFmNuAIq Fe8hRtazK60HY9ukLfkdF4Asa5IB0D0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-MIagvLraMO2foXl_coIWIg-1; Wed, 19 Feb 2020 23:12:21 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 073CC107ACC4; Thu, 20 Feb 2020 04:12:21 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-54.yyz.redhat.com [10.15.17.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22EAB8B56F; Thu, 20 Feb 2020 04:12:18 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Tom Tromey , Sergio Durigan Junior Subject: [PATCH] Make '{putchar,fputc}_unfiltered' use 'fputs_unfiltered' Date: Wed, 19 Feb 2020 23:12:14 -0500 Message-Id: <20200220041214.155369-1-sergiodj@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes There is currently a regression when using '{putchar,fputc}_unfiltered' with 'puts_unfiltered' which was introduced by one of the commits that reworked the unfiltered print code. The regression makes it impossible to use '{putchar,fputc}_unfiltered' with 'puts_unfiltered', because the former writes directly to the ui_file stream using 'stream->write', while the latter uses a buffered mechanism (see 'wrap_buffer') and delays the printing. If you do a quick & dirty hack on e.g. top.c:show_gdb_datadir: @@ -2088,6 +2088,13 @@ static void show_gdb_datadir (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { + putchar_unfiltered ('\n'); + puts_unfiltered ("TEST"); + putchar_unfiltered ('>'); + puts_unfiltered ("PUTS"); + putchar_unfiltered ('\n'); rebuild GDB and invoke the "show data-directory" command, you will see: (gdb) show data-directory > TESTPUTSGDB's data directory is "/usr/local/share/gdb". Note how the '>' was printed before the output, and "TEST" and "PUTS" were printed together. My first attempt to fix this was to always call 'flush_wrap_buffer' at the end of 'fputs_maybe_filtered', since it seemed to me that the function should always print what was requested. But I wasn't sure this was the right thing to do, so I talked to Tom on IRC and he gave me another, simpler idea: make '{putchar,fputc}_unfiltered' call into the already existing 'fputs_unfiltered' function. This patch implements the idea. I regtested it on the Buildbot, and no regressions were detected. gdb/ChangeLog: 2020-02-20 Sergio Durigan Junior Tom Tromey * utils.c (fputs_maybe_filtered): Call 'stream->puts' instead of 'fputc_unfiltered'. (putchar_unfiltered): Call 'fputc_unfiltered'. (fputc_unfiltered): Call 'fputs_unfiltered'. --- gdb/utils.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gdb/utils.c b/gdb/utils.c index 0200a8621f..0b470120a2 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1776,7 +1776,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, newline -- if chars_per_line is right, we probably just overflowed anyway; if it's wrong, let us keep going. */ - fputc_unfiltered ('\n', stream); + /* XXX: The ideal thing would be to call + 'stream->putc' here, but we can't because it + currently calls 'fputc_unfiltered', which ends up + calling us, which generates an infinite + recursion. */ + stream->puts ("\n"); } else { @@ -1821,7 +1826,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, wrap_here ((char *) 0); /* Spit out chars, cancel further wraps. */ lines_printed++; - fputc_unfiltered ('\n', stream); + /* XXX: The ideal thing would be to call + 'stream->putc' here, but we can't because it + currently calls 'fputc_unfiltered', which ends up + calling us, which generates an infinite + recursion. */ + stream->puts ("\n"); lineptr++; } } @@ -1916,10 +1926,7 @@ fputs_highlighted (const char *str, const compiled_regex &highlight, int putchar_unfiltered (int c) { - char buf = c; - - gdb_stdout->write (&buf, 1); - return c; + return fputc_unfiltered (c, gdb_stdout); } /* Write character C to gdb_stdout using GDB's paging mechanism and return C. @@ -1934,9 +1941,11 @@ putchar_filtered (int c) int fputc_unfiltered (int c, struct ui_file *stream) { - char buf = c; + char buf[2]; - stream->write (&buf, 1); + buf[0] = c; + buf[1] = 0; + fputs_unfiltered (buf, stream); return c; }