From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 From: Gaius Mulley To: Tom Tromey Cc: gdb-patches@sourceware.org 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-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, 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, 23 Feb 2022 20:17:16 -0000 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