From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 505C83857C69 for ; Wed, 16 Feb 2022 17:26:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 505C83857C69 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-ayJ2F0WBNDeDbdYH8dMTmw-1; Wed, 16 Feb 2022 12:26:03 -0500 X-MC-Unique: ayJ2F0WBNDeDbdYH8dMTmw-1 Received: by mail-wr1-f69.google.com with SMTP id j8-20020adfa548000000b001e33074ac51so1342189wrb.11 for ; Wed, 16 Feb 2022 09:25:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6s4XCOT97eazGKT1Na8QZCgvofFwIxIaHdwyKWuXVSI=; b=WIt3FavQdTyOjfiW2ovSDJK1Hxs5utQGYSAgdSfOvFO1pYeTMvDKJSCp8m65mLOsO7 y7nTOMviFNxaBZjJCfjq3y0hKaPmHz3BachDXOVE/jKM+MnnooPfUxYyD5RJp23Yksae Siea0Yk2RUOKu0NChFeRkprImh6x/oCZbllTCtaZnOdmebUIKQGxIHYL4CTGQ65WNzxS 2aozN4D6OPxupYe53wpdujHbdhxgeJ/nLTIG+QWNLj8mQ/TW9YfAgwc+P1fkWLQBXEn+ 6KsDxxwiwSCejsWZ01su7bVEBFaFUkcLT/91J2+gPYrTxYgxp7VZffi0at9ZmWZJf2Pw z1rA== X-Gm-Message-State: AOAM531uRQhPabkafoFolL8VXbszocwBTxJ3qv3WGuqjaE0U1i92yLtJ wKuP7aDs4GNzNqDzD7kFn5SjKQZ3gSbYbabtbCIqIt1pv8oqRC50ci7mUxhzw3ZF+zd9iHI+PAZ SbI+YatWYC6v/tM3q/Z3ioQ== X-Received: by 2002:a1c:a514:0:b0:37b:b7c8:6091 with SMTP id o20-20020a1ca514000000b0037bb7c86091mr2561793wme.133.1645032356661; Wed, 16 Feb 2022 09:25:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnENs7sf71U6KsqF18n12cIZuUcpIBVPA2HetVCm8FJRMECba5Ld3r14svQx++L/F+RI/ngw== X-Received: by 2002:a1c:a514:0:b0:37b:b7c8:6091 with SMTP id o20-20020a1ca514000000b0037bb7c86091mr2561782wme.133.1645032356400; Wed, 16 Feb 2022 09:25:56 -0800 (PST) Received: from localhost (host86-134-151-224.range86-134.btcentralplus.com. [86.134.151.224]) by smtp.gmail.com with ESMTPSA id u7sm28108725wrq.112.2022.02.16.09.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 09:25:55 -0800 (PST) Date: Wed, 16 Feb 2022 17:25:55 +0000 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 10/18] Use a ui_file in print_wchar Message-ID: <20220216172555.GN2571@redhat.com> References: <20220216135518.3162480-1-tom@tromey.com> <20220216135518.3162480-11-tom@tromey.com> MIME-Version: 1.0 In-Reply-To: <20220216135518.3162480-11-tom@tromey.com> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 17:25:06 up 5 days, 7:04, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 16 Feb 2022 17:26:06 -0000 * Tom Tromey [2022-02-16 06:55:10 -0700]: > This introduces a new ui_file subclass, that turns a host string into > a wide string and appends it to an obstack. print_wchar is rewritten > to use this new ui_file. This will be more useful in a later patch. LGTM. Thanks, Andrew > --- > gdb/valprint.c | 49 +++++++++++++++++++++++++++---------------------- > 1 file changed, 27 insertions(+), 22 deletions(-) > > diff --git a/gdb/valprint.c b/gdb/valprint.c > index dec1dce9d3c..00c0cd2c72a 100644 > --- a/gdb/valprint.c > +++ b/gdb/valprint.c > @@ -2163,19 +2163,29 @@ wchar_printable (gdb_wchar_t w) > || w == LCST ('\v') || w == LCST ('\0')); > } > > -/* A helper function that converts the contents of STRING to wide > - characters and then appends them to OUTPUT. */ > - > -static void > -append_string_as_wide (const char *string, > - struct obstack *output) > -{ > - for (; *string; ++string) > - { > - gdb_wchar_t w = gdb_btowc (*string); > - obstack_grow (output, &w, sizeof (gdb_wchar_t)); > - } > -} > +/* A ui_file that writes wide characters to an obstack. */ > +class obstack_wide_file : public ui_file > +{ > +public: > + explicit obstack_wide_file (struct obstack *output) > + : m_output (output) > + { > + } > + > + ~obstack_wide_file () = default; > + > + void write (const char *buf, long length_buf) override > + { > + for (long i = 0; i < length_buf; ++i) > + { > + gdb_wchar_t w = gdb_btowc (buf[i]); > + obstack_grow (m_output, &w, sizeof (gdb_wchar_t)); > + } > + } > + > +private: > + struct obstack *m_output; > +}; > > /* Print a wide character W to OUTPUT. ORIG is a pointer to the > original (target) bytes representing the character, ORIG_LEN is the > @@ -2236,10 +2246,10 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, > else > { > int i; > + obstack_wide_file file (output); > > for (i = 0; i + width <= orig_len; i += width) > { > - char octal[30]; > ULONGEST value; > > value = extract_unsigned_integer (&orig[i], width, > @@ -2247,19 +2257,14 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, > /* If the value fits in 3 octal digits, print it that > way. Otherwise, print it as a hex escape. */ > if (value <= 0777) > - xsnprintf (octal, sizeof (octal), "\\%.3o", > - (int) (value & 0777)); > + fprintf_filtered (&file, "\\%.3o", (int) (value & 0777)); > else > - xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value); > - append_string_as_wide (octal, output); > + fprintf_filtered (&file, "\\x%lx", (long) value); > } > /* If we somehow have extra bytes, print them now. */ > while (i < orig_len) > { > - char octal[5]; > - > - xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff); > - append_string_as_wide (octal, output); > + fprintf_filtered (&file, "\\%.3o", orig[i] & 0xff); > ++i; > } > > -- > 2.31.1 >