From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ntnOHV6WFmLhfgAAWB0awg (envelope-from ) for ; Wed, 23 Feb 2022 15:17:34 -0500 Received: by simark.ca (Postfix, from userid 112) id 649641F3C8; Wed, 23 Feb 2022 15:17:34 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_REPLYTO_END_DIGIT,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 A644A1F0D2 for ; Wed, 23 Feb 2022 15:17:33 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8A20385840B for ; Wed, 23 Feb 2022 20:17:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8A20385840B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1645647452; bh=CnHmfVp8PDnMEjQciURMf+6yKdDHOzJM2l4SSN+MqNE=; h=To:Subject:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jbh8KgWqdxVQ4QBVkQSc2vFhI9XW5klDk048YWOv9Deb4xZOc4XH1+dqGqnIrT2cp 4xn3eaAUReY4iszD3y7RHGznSy7CzJ161rXD2cIDbYp4QVT4wCXnEndIorPQwSU36H qtSZEinjbsZZ0uIRHUzdJI1RozaVVxRs06OuhAu4= Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id A93213858C2D for ; Wed, 23 Feb 2022 20:17:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A93213858C2D Received: by mail-wr1-x436.google.com with SMTP id d17so6624103wrc.9 for ; Wed, 23 Feb 2022 12:17:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=CnHmfVp8PDnMEjQciURMf+6yKdDHOzJM2l4SSN+MqNE=; b=XH3hsLUJtND2rhIN4Es23AQ8IDI999Zqn1zJvQp3ixn3HoPPh02EaHhLI7vLe2eaBX Y7R+Mxrg6PQL25X4BMEktY3gbBUmMG/f8K97rspOs2/ew0Xu/mKpp3raJjqYF6vaH67z SYb6rlm7l2EoeLztIe5xyOuXJjFys8f53rep80OVG90Cmx27lrP25iP6r1M68yYs7JQ8 RzoY+wxUhl6Pv6xKGADIg+9PDynesQdv4AX8HiQgJ+EoQX3XBwAtRI4EJUs/PoIdLc22 W5YXjir6WL46KZxs2IG1dvAOxRFTkbDgFDqjzazGod8V5QgmGAuaqquFptrEAHOZX2x5 21mA== X-Gm-Message-State: AOAM5330QAEP94iFNDCR2IY1eIOth0jcuyQP8c1Ao8AY247WOuqb19Cp qUdTjDzx8JCN3uvbq7xqmX8= X-Google-Smtp-Source: ABdhPJxfIsRreK3tQOcyPCjk4IQLTEIE0Vdn1g/WmCUwCFw3oB0oNFSXhDaZn3j9W7y+nHL7yn108A== X-Received: by 2002:a5d:424e:0:b0:1ea:8df9:bd04 with SMTP id s14-20020a5d424e000000b001ea8df9bd04mr924977wrr.599.1645647432703; Wed, 23 Feb 2022 12:17:12 -0800 (PST) Received: from lancelot (92.40.169.30.threembb.co.uk. [92.40.169.30]) by smtp.gmail.com with ESMTPSA id o3-20020a05600c4fc300b0037bea2f9775sm697379wmq.25.2022.02.23.12.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 12:17:12 -0800 (PST) Received: from gaius by lancelot with local (Exim 4.94.2) (envelope-from ) id 1nMy4V-000qnY-2L; Wed, 23 Feb 2022 20:17:11 +0000 To: Tom Tromey Subject: Re: [PATCH v2 16/18] Use generic_emit_char in Modula-2 References: <20220217220547.3874030-1-tom@tromey.com> <20220217220547.3874030-17-tom@tromey.com> Date: Wed, 23 Feb 2022 20:17:10 +0000 In-Reply-To: <20220217220547.3874030-17-tom@tromey.com> (Tom Tromey's message of "Thu, 17 Feb 2022 15:05:44 -0700") Message-ID: <87v8x5l4mx.fsf@debian> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: Gaius Mulley via Gdb-patches Reply-To: Gaius Mulley Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Tom Tromey writes: > 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; Hi Tom, all looks fine - but I'll test this and report back. It might be a few days as my Internet connection is down - storm damage on the North Cornwall coast, regards, Gaius