From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qproxy5-pub.mail.unifiedlayer.com (qproxy5-pub.mail.unifiedlayer.com [69.89.21.30]) by sourceware.org (Postfix) with ESMTPS id 64B0C385BF81 for ; Thu, 17 Feb 2022 22:06:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 64B0C385BF81 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 gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by qproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id EE79E8033F01 for ; Thu, 17 Feb 2022 22:06:54 +0000 (UTC) Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id A0BE310047525 for ; Thu, 17 Feb 2022 22:05:54 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id KouQn5brEnAlUKouQnzJVf; Thu, 17 Feb 2022 22:05:54 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=QIOt+iHL 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=arHcos6n2OpJZ7XGp40A: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=BnEdYVTfU885Mwy8BzWMpOpRCQUl5cE6qYK58CHiNb0=; b=DUEE9pqmJG1FUf3STtKy4KRnXD cBZivfkW8W1LGnNYKrL2mJRI/n89wrF0aqbvVrHFQPrQaEA2+hiOXbt/zGgzQARkg2PlUh2pONqMd Ye4+QYzm7ktNB3VNBVQcEGozv; 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 1nKouP-002ABb-Ob; Thu, 17 Feb 2022 15:05:53 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 16/18] Use generic_emit_char in Modula-2 Date: Thu, 17 Feb 2022 15:05:44 -0700 Message-Id: <20220217220547.3874030-17-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: 1nKouP-002ABb-Ob 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: 22 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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:06:58 -0000 This changes the Modula-2 code to use generic_emit_char and generic_printstr. I have no way to test this. However, the Modula-2 code seems to be pretty much a copy of the old C code from before the charset work. --- gdb/m2-lang.c | 144 +++++++++----------------------------------------- gdb/m2-lang.h | 5 -- 2 files changed, 26 insertions(+), 123 deletions(-) diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index 7673426b7a8..29aaec87405 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -139,137 +139,45 @@ m2_language::language_arch_info (struct gdbarch *gdbarch, lai->set_bool_type (builtin->builtin_bool, "BOOLEAN"); } +/* A callback function for generic_emit_char and generic_printstr that + escapes characters Modula 2-style. */ + +static void +m2_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) +{ + /* Historically the Modula-2 code in gdb handled \e as well. */ + if (w == LCST ('\033')) + fputs_filtered ("\\e", stream); + else + default_emit_wchar (stream, w, orig, width, byte_order, quoter, + need_escapep); +} + /* See languge.h. */ void m2_language::printchar (int c, struct type *type, struct ui_file *stream) const { - fputs_filtered ("'", stream); - emitchar (c, type, stream, '\''); - fputs_filtered ("'", stream); + generic_emit_char (c, type, stream, '\'', nullptr, m2_emit_char); } /* See language.h. */ void m2_language::printstr (struct ui_file *stream, struct type *elttype, - const gdb_byte *string, unsigned int length, - const char *encoding, int force_ellipses, - const struct value_print_options *options) const -{ - unsigned int i; - unsigned int things_printed = 0; - int in_quotes = 0; - int need_comma = 0; - - if (length == 0) - { - puts_filtered ("\"\""); - 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; - - QUIT; - - if (need_comma) - { - fputs_filtered (", ", stream); - need_comma = 0; - } - - rep1 = i + 1; - reps = 1; - while (rep1 < length && string[rep1] == string[i]) - { - ++rep1; - ++reps; - } - - if (reps > options->repeat_count_threshold) - { - if (in_quotes) - { - fputs_filtered ("\", ", stream); - in_quotes = 0; - } - printchar (string[i], elttype, stream); - fprintf_filtered (stream, " ", reps); - i = rep1 - 1; - things_printed += options->repeat_count_threshold; - need_comma = 1; - } - else - { - if (!in_quotes) - { - fputs_filtered ("\"", stream); - in_quotes = 1; - } - emitchar (string[i], elttype, stream, '"'); - ++things_printed; - } - } - - /* Terminate the quotes if necessary. */ - if (in_quotes) - fputs_filtered ("\"", stream); - - if (force_ellipses || i < length) - fputs_filtered ("...", stream); -} - -/* See language.h. */ - -void -m2_language::emitchar (int ch, struct type *chtype, - struct ui_file *stream, int quoter) const + const gdb_byte *string, unsigned int length, + const char *encoding, int force_ellipses, + const struct value_print_options *options) const { - ch &= 0xFF; /* Avoid sign bit follies. */ - - if (PRINT_LITERAL_FORM (ch)) - { - if (ch == '\\' || ch == quoter) - fputs_filtered ("\\", stream); - fprintf_filtered (stream, "%c", ch); - } - else - { - switch (ch) - { - case '\n': - fputs_filtered ("\\n", stream); - break; - case '\b': - fputs_filtered ("\\b", stream); - break; - case '\t': - fputs_filtered ("\\t", stream); - break; - case '\f': - fputs_filtered ("\\f", stream); - break; - case '\r': - fputs_filtered ("\\r", stream); - break; - case '\033': - fputs_filtered ("\\e", stream); - break; - case '\007': - fputs_filtered ("\\a", stream); - break; - default: - fprintf_filtered (stream, "\\%.3o", (unsigned int) ch); - break; - } - } + generic_printstr (stream, elttype, string, length, encoding, force_ellipses, + '"', 0, options, m2_emit_char); } /* Called during architecture gdbarch initialisation to create language diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h index ee2fc6fb8bc..2f516bc6427 100644 --- a/gdb/m2-lang.h +++ b/gdb/m2-lang.h @@ -92,11 +92,6 @@ class m2_language : public language_defn /* See language.h. */ - void emitchar (int ch, struct type *chtype, - struct ui_file *stream, int quoter) const; - - /* See language.h. */ - void printchar (int ch, struct type *chtype, struct ui_file *stream) const override; -- 2.31.1