From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by sourceware.org (Postfix) with ESMTPS id D9EF83857C7D for ; Wed, 16 Feb 2022 13:55:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9EF83857C7D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id B912E1004473D for ; Wed, 16 Feb 2022 13:55:29 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id KKmHnON8A2s5dKKmHn4nUC; Wed, 16 Feb 2022 13:55:29 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=BOh2EHcG c=1 sm=1 tr=0 ts=620d0251 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=oGFeUVbbRNcA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=3kJaGHpBqJBlH9tbVrIA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=J0gb658jqoNkXROcsNxAT5kjKfAhMNMxU8msblieHrM=; b=MkdVDN8HTXcOxTODlaKwFGvjVh OQilfya5IKf5/2qC1+7lwzTA63uAf2H8enJFXjrjie9q6d5YpoWZk+Q4n8ocL3gHCOmaqkBywJfCD sWkTTUxc/V2Qz714iBmYsHyC8; Received: from 97-122-95-113.hlrn.qwest.net ([97.122.95.113]:41020 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nKKmG-000GRy-Vs; Wed, 16 Feb 2022 06:55:29 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 11/18] Add an emitter callback to generic_printstr and generic_emit_char Date: Wed, 16 Feb 2022 06:55:11 -0700 Message-Id: <20220216135518.3162480-12-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220216135518.3162480-1-tom@tromey.com> References: <20220216135518.3162480-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.95.113 X-Source-L: No X-Exim-ID: 1nKKmG-000GRy-Vs X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-95-113.hlrn.qwest.net (prentzel.Home) [97.122.95.113]:41020 X-Source-Auth: tom+tromey.com X-Email-Count: 12 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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 13:55:32 -0000 This adds an emitter callback to generic_printstr and generic_emit_char, passing it through to print_wchar. print_wchar is modified to call it, if possible. This will be used to let languages override the way that escape sequences are emitted. Nothing uses this yet, that comes later in the series. --- gdb/valprint.c | 41 ++++++++++++++++++++++++++++------------- gdb/valprint.h | 30 ++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 00c0cd2c72a..c0e5e678005 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -2201,12 +2201,19 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len, int width, enum bfd_endian byte_order, struct obstack *output, - int quoter, bool *need_escapep) + int quoter, bool *need_escapep, + emit_char_ftype emitter) { bool need_escape = *need_escapep; *need_escapep = false; + obstack_wide_file file (output); + if (emitter != nullptr + && emitter (&file, w, gdb::make_array_view (orig, orig_len), + width, byte_order, quoter)) + return; + switch (w) { case LCST ('\a'): @@ -2246,7 +2253,6 @@ 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) { @@ -2281,7 +2287,8 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, void generic_emit_char (int c, struct type *type, struct ui_file *stream, - int quoter, const char *encoding) + int quoter, const char *encoding, + emit_char_ftype emitter) { enum bfd_endian byte_order = type_byte_order (type); @@ -2330,14 +2337,16 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream, for (i = 0; i < num_chars; ++i) print_wchar (chars[i], buf, buflen, TYPE_LENGTH (type), byte_order, - &wchar_buf, quoter, &need_escape); + &wchar_buf, quoter, &need_escape, + emitter); } } /* This handles the NUM_CHARS == 0 case as well. */ if (print_escape) print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), - byte_order, &wchar_buf, quoter, &need_escape); + byte_order, &wchar_buf, quoter, &need_escape, + emitter); } /* The output in the host encoding. */ @@ -2445,7 +2454,8 @@ print_converted_chars_to_obstack (struct obstack *obstack, const std::vector &chars, int quote_char, int width, enum bfd_endian byte_order, - const struct value_print_options *options) + const struct value_print_options *options, + emit_char_ftype emitter) { unsigned int idx; const converted_character *elem; @@ -2486,10 +2496,12 @@ print_converted_chars_to_obstack (struct obstack *obstack, { if (elem->result == wchar_iterate_ok) print_wchar (elem->chars[0], elem->buf, elem->buflen, width, - byte_order, obstack, quote_char, &need_escape); + byte_order, obstack, quote_char, &need_escape, + emitter); else print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, - byte_order, obstack, quote_char, &need_escape); + byte_order, obstack, quote_char, &need_escape, + emitter); } } break; @@ -2514,10 +2526,12 @@ print_converted_chars_to_obstack (struct obstack *obstack, obstack_grow_wstr (obstack, LCST ("'")); if (elem->result == wchar_iterate_ok) print_wchar (elem->chars[0], elem->buf, elem->buflen, width, - byte_order, obstack, quote_char, &need_escape); + byte_order, obstack, quote_char, &need_escape, + emitter); else print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, - byte_order, obstack, quote_char, &need_escape); + byte_order, obstack, quote_char, &need_escape, + emitter); obstack_grow_wstr (obstack, LCST ("'")); std::string s = string_printf (_(" "), elem->repeat_count); @@ -2543,7 +2557,7 @@ print_converted_chars_to_obstack (struct obstack *obstack, /* Output the incomplete sequence string. */ obstack_grow_wstr (obstack, LCST ("buf, elem->buflen, width, byte_order, - obstack, 0, &need_escape); + obstack, 0, &need_escape, emitter); obstack_grow_wstr (obstack, LCST (">")); /* We do not attempt to output anything after this. */ @@ -2602,7 +2616,8 @@ generic_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, int quote_char, int c_style_terminator, - const struct value_print_options *options) + const struct value_print_options *options, + emit_char_ftype emitter) { enum bfd_endian byte_order = type_byte_order (type); unsigned int i; @@ -2678,7 +2693,7 @@ generic_printstr (struct ui_file *stream, struct type *type, /* Print the output string to the obstack. */ print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char, - width, byte_order, options); + width, byte_order, options, emitter); if (force_ellipses || !finished) obstack_grow_wstr (&wchar_buf, LCST ("...")); diff --git a/gdb/valprint.h b/gdb/valprint.h index 0586836f9e6..64fea1ccb4a 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -233,14 +233,40 @@ extern void generic_value_print (struct value *val, struct ui_file *stream, const struct value_print_options *options, const struct generic_val_print_decorations *d); +/* A callback that can be used to print a representation of a wide + character to a stream. + + If the character can be represented by this callback, it will + return true. A false return indicates that the default behavior + should be taken -- for printable characters, the default is to emit + it verbatim; for non-printable characters, C-style escapes are + used. Normally a callback should always return false for + printable, non-control characters. + + STREAM is the stream to write to. + W is the character. It might be gdb_WEOF, meaning an unconvertible + sequence. + ORIG is the original (target) bytes corresponding to W. + WIDTH is the width of a base character in the encoding. + BYTE_ORDER is the character type's byte order. + QUOTER is the quote character used -- this is a host character. */ +typedef gdb::function_view orig, + int width, + enum bfd_endian byte_order, + int quoter)> emit_char_ftype; + extern void generic_emit_char (int c, struct type *type, struct ui_file *stream, - int quoter, const char *encoding); + int quoter, const char *encoding, + emit_char_ftype emitter = nullptr); extern void generic_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string, unsigned int length, const char *encoding, int force_ellipses, int quote_char, int c_style_terminator, - const struct value_print_options *options); + const struct value_print_options *options, + emit_char_ftype emitter = nullptr); /* Run the "output" command. ARGS and FROM_TTY are the usual arguments passed to all command implementations, except ARGS is -- 2.31.1