From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id p1uQGsFZz2HXfAAAWB0awg (envelope-from ) for ; Fri, 31 Dec 2021 14:28:01 -0500 Received: by simark.ca (Postfix, from userid 112) id 599431F0D7; Fri, 31 Dec 2021 14:28:01 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 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 C37C81ECEB for ; Fri, 31 Dec 2021 14:28:00 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 46A3B3858439 for ; Fri, 31 Dec 2021 19:28:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46A3B3858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1640978880; bh=nFwqJ5uz+1vHHTiv1obdn4aSPZNYxGmc2nDF50FADQ0=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Ig8e1vsg6vH0gEBdvxC9mN7APM7DoleXJHNN02f+fqxB9/p5JbqFHKCl77nBi/Muv DefMWIRIeW6OOX21Fu6Dr4WmQ7gC0d47loYPyMkqQX7sHPOkiIt7RhZBCUcNV4Ig19 DIrOxEB0VfSGQuwy4XwVESSa2y4LXCWjNib5Jrm4= Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id 02CD83858D39 for ; Fri, 31 Dec 2021 19:27:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 02CD83858D39 Received: from Plymouth (unknown [IPv6:2a02:390:9086:0:1df1:c4df:34dd:21c7]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 3FDAE830F2; Fri, 31 Dec 2021 19:27:39 +0000 (UTC) Date: Fri, 31 Dec 2021 19:27:35 +0000 To: Tom Tromey Subject: Re: [PATCH] Implement putstr and putstrn in ui_file Message-ID: <20211231192735.4ljnjbztxs3dfg7b@Plymouth> References: <20211231180157.946230-1-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211231180157.946230-1-tom@tromey.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Fri, 31 Dec 2021 19:27:39 +0000 (UTC) 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: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, I have included comments and questions below. > +/* See ui-file.h. */ > + > +void > +ui_file::printchar (int c, int quoter, bool async_safe) > +{ > + char buf[4]; > + int out = 0; > + > + c &= 0xFF; /* Avoid sign bit follies */ > + > + if (c < 0x20 || /* Low control chars */ > + (c >= 0x7F && c < 0xA0) || /* DEL, High controls */ > + (sevenbit_strings && c >= 0x80)) > + { /* high order bit set */ > + buf[out++] = '\\'; > + > + switch (c) > + { > + case '\n': > + buf[out++] = 'n'; > + break; > + case '\b': > + buf[out++] = 'b'; > + break; > + case '\t': > + buf[out++] = 't'; > + break; > + case '\f': > + buf[out++] = 'f'; > + break; > + case '\r': > + buf[out++] = 'r'; > + break; > + case '\033': > + buf[out++] = 'e'; > + break; > + case '\007': > + buf[out++] = 'a'; > + break; > + default: > + { > + buf[out++] = '0'; > + buf[out++] = '0'; > + buf[out++] = '0'; This is different from the printchar implementation you moved (and it seems that always printing '\000' is a loss of information). Maybe you forgot to finalize this part? > + break; > + } > + } > + } > + else > + { > + if (quoter != 0 && (c == '\\' || c == quoter)) > + buf[out++] = '\\'; > + buf[out++] = c; > + } > + > + if (async_safe) > + this->write_async_safe (buf, out); > + else > + this->write (buf, out); > +} > + > > > void > diff --git a/gdb/ui-file.h b/gdb/ui-file.h > index 0faf84996aa..a4448d8ea9f 100644 > --- a/gdb/ui-file.h > +++ b/gdb/ui-file.h > @@ -39,7 +39,10 @@ class ui_file > independent of the language of the program being debugged. */ > void putstr (const char *str, int quoter); > > - void putstrn (const char *str, int n, int quoter); > + /* Like putstr, but only print the first N characters. If I find the comment slightly misleading (or incomplete). The function prints exactly N chars. So if 'strlen (str) < n', putstrn prints more stuff than putstrn. Maybe “Like putstr, but print exactly N characters, starting at the position pointed by STR”, or something similar? > + ASYNC_SAFE is true, then the output is done via the > + write_async_safe method. */ > + void putstrn (const char *str, int n, int quoter, bool async_safe = false); > > int putc (int c); > > @@ -96,6 +99,22 @@ class ui_file > default. */ > return false; > } > + > +private: > + > + /* Helper function for putstr and putstrn. > + > + Print the character C on this stream as part of the contents of a > + literal string whose delimiter is QUOTER. Note that this routine > + should only be called for printing things which are independent > + of the language of the program being debugged. > + > + printchar will normally escape backslashes and instances of > + QUOTER. If QUOTER is 0, printchar won't escape backslashes or any > + quoting character. As a side effect, if you pass the backslash > + character as the QUOTER, printchar will escape backslashes as > + usual, but not any other quoting character. */ ^ You are missing one space after the '.'. Best, Lancelot.