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 86122385BF91 for ; Thu, 17 Feb 2022 22:05:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 86122385BF91 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 cmgw15.mail.unifiedlayer.com (unknown [10.0.90.130]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id E0551100462BF for ; Thu, 17 Feb 2022 22:05:54 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id KouQn7CTfkku4KouQnOTuT; Thu, 17 Feb 2022 22:05:54 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=LOaj/La9 c=1 sm=1 tr=0 ts=620ec6c2 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=XMA7NqP2lYUSiKgIJX0A: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=0zJTJZ8AG8EIXO0M7PPfG2qg/EIdf2ChCJ689XMtLf8=; b=PJ35LaiA1sn9O3Pn09983pLiUB Hxvh9Qcss4NHTxWZBQhMX+Oafg7LsFfDZ9T7sw5CAWHBQcaNX7CvaBBU+ZWz39v8XJMuaGGTJ2wR7 BW+dIeaxssflGvpkkzBROOa8Y; Received: from 75-166-146-214.hlrn.qwest.net ([75.166.146.214]:41038 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 1nKouQ-002ABb-1T; Thu, 17 Feb 2022 15:05:54 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 17/18] Use generic_emit_char in Pascal Date: Thu, 17 Feb 2022 15:05:45 -0700 Message-Id: <20220217220547.3874030-18-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220217220547.3874030-1-tom@tromey.com> References: <20220217220547.3874030-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: 75.166.146.214 X-Source-L: No X-Exim-ID: 1nKouQ-002ABb-1T X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-146-214.hlrn.qwest.net (prentzel.Home) [75.166.146.214]:41038 X-Source-Auth: tom+tromey.com X-Email-Count: 23 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.5 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: Thu, 17 Feb 2022 22:05:57 -0000 This changes the Pascal to use generic_emit_char and generic_printstr. The output isn't identical, though it does pass the Pascal tests (during which I learned that FPC does not work with gold...). I think this is an improvement, nevertheless, because the Pascal expression parser accepts the C-style output that is now generated. --- gdb/p-lang.c | 134 +++++++-------------------------------------------- gdb/p-lang.h | 12 ----- 2 files changed, 18 insertions(+), 128 deletions(-) diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 70ff404bac3..6afaada6a68 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -143,31 +143,23 @@ pascal_is_string_type (struct type *type,int *length_pos, int *length_size, return 0; } -/* See p-lang.h. */ - -void -pascal_language::print_one_char (int c, struct ui_file *stream, - int *in_quotes) const +/* A callback function for generic_emit_char and generic_printstr that + escapes characters Pascal style. */ + +static void +pascal_emit_char (obstack_wide_file *stream, + gdb_wint_t w, + gdb::array_view orig, + int width, + enum bfd_endian byte_order, + int quoter, + bool *need_escapep) { - if (c == '\'' || ((unsigned int) c <= 0xff && (PRINT_LITERAL_FORM (c)))) - { - if (!(*in_quotes)) - fputs_filtered ("'", stream); - *in_quotes = 1; - if (c == '\'') - { - fputs_filtered ("''", stream); - } - else - fprintf_filtered (stream, "%c", c); - } + if (w == LCST ('\'')) + fputs_filtered ("''", stream); else - { - if (*in_quotes) - fputs_filtered ("'", stream); - *in_quotes = 0; - fprintf_filtered (stream, "#%d", (unsigned int) c); - } + default_emit_wchar (stream, w, orig, width, byte_order, quoter, + need_escapep); } /* See language.h. */ @@ -176,11 +168,7 @@ void pascal_language::printchar (int c, struct type *type, struct ui_file *stream) const { - int in_quotes = 0; - - print_one_char (c, stream, &in_quotes); - if (in_quotes) - fputs_filtered ("'", stream); + generic_emit_char (c, type, stream, '\'', nullptr, pascal_emit_char); } @@ -228,94 +216,8 @@ pascal_language::printstr (struct ui_file *stream, struct type *elttype, const char *encoding, int force_ellipses, const struct value_print_options *options) const { - enum bfd_endian byte_order = type_byte_order (elttype); - unsigned int i; - unsigned int things_printed = 0; - int in_quotes = 0; - int need_comma = 0; - int width; - - /* Preserve ELTTYPE's original type, just set its LENGTH. */ - check_typedef (elttype); - width = TYPE_LENGTH (elttype); - - /* If the string was not truncated due to `set print elements', and - the last byte of it is a null, we don't print that, in traditional C - style. */ - if ((!force_ellipses) && length > 0 - && extract_unsigned_integer (string + (length - 1) * width, width, - byte_order) == 0) - length--; - - if (length == 0) - { - fputs_filtered ("''", stream); - return; - } - - for (i = 0; i < length && things_printed < options->print_max; ++i) - { - /* Position of the character we are examining - to see whether it is repeated. */ - unsigned int rep1; - /* Number of repetitions we have detected so far. */ - unsigned int reps; - unsigned long int current_char; - - QUIT; - - if (need_comma) - { - fputs_filtered (", ", stream); - need_comma = 0; - } - - current_char = extract_unsigned_integer (string + i * width, width, - byte_order); - - rep1 = i + 1; - reps = 1; - while (rep1 < length - && extract_unsigned_integer (string + rep1 * width, width, - byte_order) == current_char) - { - ++rep1; - ++reps; - } - - if (reps > options->repeat_count_threshold) - { - if (in_quotes) - { - fputs_filtered ("', ", stream); - in_quotes = 0; - } - printchar (current_char, elttype, stream); - fprintf_filtered (stream, " %p[%p]", - metadata_style.style ().ptr (), - reps, nullptr); - i = rep1 - 1; - things_printed += options->repeat_count_threshold; - need_comma = 1; - } - else - { - if ((!in_quotes) && (PRINT_LITERAL_FORM (current_char))) - { - fputs_filtered ("'", stream); - in_quotes = 1; - } - print_one_char (current_char, stream, &in_quotes); - ++things_printed; - } - } - - /* Terminate the quotes if necessary. */ - if (in_quotes) - fputs_filtered ("'", stream); - - if (force_ellipses || i < length) - fputs_filtered ("...", stream); + generic_printstr (stream, elttype, string, length, encoding, force_ellipses, + '\'', 0, options, pascal_emit_char); } /* Single instance of the Pascal language class. */ diff --git a/gdb/p-lang.h b/gdb/p-lang.h index b831bde0af6..79f8fd7c28d 100644 --- a/gdb/p-lang.h +++ b/gdb/p-lang.h @@ -109,18 +109,6 @@ class pascal_language : public language_defn /* See language.h. */ - void emitchar (int ch, struct type *chtype, - struct ui_file *stream, int quoter) const - { - int in_quotes = 0; - - print_one_char (ch, stream, &in_quotes); - if (in_quotes) - fputs_filtered ("'", stream); - } - - /* See language.h. */ - void printchar (int ch, struct type *chtype, struct ui_file *stream) const override; -- 2.31.1