From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 668E93858C20 for ; Mon, 28 Feb 2022 17:49:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 668E93858C20 Received: by mail-il1-x131.google.com with SMTP id i1so3971436ilu.6 for ; Mon, 28 Feb 2022 09:49:00 -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:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LypTE5qGvv5W5TMRGVlvOUsywknY7KMNiWVv3Jmy/fU=; b=wLf8A4zng9aXE3K4Ozr9hTZ0BrOhfznklKgtXttrXgJFEm9SXgqj5O1ug9yQrw9nv9 ogt/Qxq+ZW6sQfOLhD3/505s7nO6M1c60tB/AuGDeuviIMQ0i9lhv10YYSZoYvEm5vZP Pk6f/fI+lvEPgCoNULYcSovHLuRY6aGPc9G3VEc4buW4wLf/R8QHsZC3RZXpC8K5Y5/f 79EIXLks0fkPsv+mmyViGqrij95l8C5mdM026TjGwU2XYWcWi5dGHbdxL4K59eoFpj4L R004H6SapnRGfToduRgH+AG8+GuBC6Mkaws7B2fK/1kiOSWZclk2IFNBzYqmh2mqbpcj KY6g== X-Gm-Message-State: AOAM530V1ZD5TmV3luUmHh8/2qJeW8ejmbdsnmC3WgzQLDDcFBQpFsX3 Jej3bHDM17M2jCW9Zxk+buNhm8nkqFINow== X-Google-Smtp-Source: ABdhPJzRhKUCm/p9JIf7X3TsARVhXv6iSsE2ioe80SbYL0Kpx0gO31doYGjWE/9EcOvlAIjvnECuRg== X-Received: by 2002:a05:6e02:214b:b0:2be:ff52:adea with SMTP id d11-20020a056e02214b00b002beff52adeamr19493607ilv.255.1646070539764; Mon, 28 Feb 2022 09:48:59 -0800 (PST) Received: from murgatroyd.Home (75-166-141-253.hlrn.qwest.net. [75.166.141.253]) by smtp.gmail.com with ESMTPSA id p12-20020a92740c000000b002c2585ec04asm6391314ilc.44.2022.02.28.09.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 09:48:59 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed 2/2] Handle multi-byte bracket sequences in Ada lexer Date: Mon, 28 Feb 2022 10:48:56 -0700 Message-Id: <20220228174856.287372-3-tromey@adacore.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220228174856.287372-1-tromey@adacore.com> References: <20220228174856.287372-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: Mon, 28 Feb 2022 17:49:05 -0000 As noted in an earlier patch, the Ada lexer does not handle multi-byte bracket sequences. This patch adds support for these for character literals. gdb does not generally seem to handle the Ada wide string types, so for the time being these continue to be excluded -- but an explicit error is added to make this more clear. --- gdb/ada-exp.y | 16 ++++++++++---- gdb/ada-lang.c | 14 ++++++++---- gdb/ada-lex.l | 24 ++++++++++++--------- gdb/ada-valprint.c | 6 +++++- gdb/testsuite/gdb.ada/char_enum_unicode.exp | 9 ++++++++ gdb/testsuite/gdb.ada/widewide.exp | 4 ++-- 6 files changed, 52 insertions(+), 21 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 916b8ef94fe..d3fce8d05e3 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -98,7 +98,7 @@ static struct type *type_long_long (struct parser_state *); static struct type *type_long_double (struct parser_state *); -static struct type *type_char (struct parser_state *); +static struct type *type_for_char (struct parser_state *, ULONGEST); static struct type *type_boolean (struct parser_state *); @@ -1727,10 +1727,18 @@ type_long_double (struct parser_state *par_state) } static struct type * -type_char (struct parser_state *par_state) +type_for_char (struct parser_state *par_state, ULONGEST value) { - return language_string_char_type (par_state->language (), - par_state->gdbarch ()); + if (value <= 0xff) + return language_string_char_type (par_state->language (), + par_state->gdbarch ()); + else if (value <= 0xffff) + return language_lookup_primitive_type (par_state->language (), + par_state->gdbarch (), + "wide_character"); + return language_lookup_primitive_type (par_state->language (), + par_state->gdbarch (), + "wide_wide_character"); } static struct type * diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f1d59d2aadb..d44b0906e6d 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10187,7 +10187,7 @@ ada_resolvable::replace (operation_up &&owner, return std::move (owner); } -/* Convert the character literal whose ASCII value would be VAL to the +/* Convert the character literal whose value would be VAL to the appropriate value of type TYPE, if there is a translation. Otherwise return VAL. Hence, in an enumeration type ('A', 'B'), the literal 'A' (VAL == 65), returns 0. */ @@ -10195,7 +10195,7 @@ ada_resolvable::replace (operation_up &&owner, static LONGEST convert_char_literal (struct type *type, LONGEST val) { - char name[7]; + char name[12]; int f; if (type == NULL) @@ -10206,8 +10206,12 @@ convert_char_literal (struct type *type, LONGEST val) if ((val >= 'a' && val <= 'z') || (val >= '0' && val <= '9')) xsnprintf (name, sizeof (name), "Q%c", (int) val); + else if (val >= 0 && val < 256) + xsnprintf (name, sizeof (name), "QU%02x", (unsigned) val); + else if (val >= 0 && val < 0x10000) + xsnprintf (name, sizeof (name), "QW%04x", (unsigned) val); else - xsnprintf (name, sizeof (name), "QU%02x", (int) val); + xsnprintf (name, sizeof (name), "QWW%08lx", (unsigned long) val); size_t len = strlen (name); for (f = 0; f < type->num_fields (); f += 1) { @@ -13005,9 +13009,11 @@ class ada_language : public language_defn add (arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "short_integer")); struct type *char_type = arch_character_type (gdbarch, TARGET_CHAR_BIT, - 0, "character"); + 1, "character"); lai->set_string_char_type (char_type); add (char_type); + add (arch_character_type (gdbarch, 16, 1, "wide_character")); + add (arch_character_type (gdbarch, 32, 1, "wide_wide_character")); add (arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), "float", gdbarch_float_format (gdbarch))); add (arch_float_type (gdbarch, gdbarch_double_bit (gdbarch), diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index d64496a3775..f61efba81a9 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -1,4 +1,4 @@ -/* FLEX lexer for Ada expressions, for GDB. +/* FLEX lexer for Ada expressions, for GDB. -*- c++ -*- Copyright (C) 1994-2022 Free Software Foundation, Inc. This file is part of GDB. @@ -150,20 +150,22 @@ static int paren_depth; } "'"({GRAPHIC}|\")"'" { - yylval.typed_val.type = type_char (pstate); yylval.typed_val.val = yytext[1]; + yylval.typed_val.type = type_for_char (pstate, yytext[1]); return CHARLIT; } -"'[\""{HEXDIG}{2}"\"]'" { - int v; - yylval.typed_val.type = type_char (pstate); - sscanf (yytext+3, "%2x", &v); +"'[\""{HEXDIG}{2,}"\"]'" { + ULONGEST v = strtoulst (yytext+3, nullptr, 16); yylval.typed_val.val = v; + yylval.typed_val.type = type_for_char (pstate, v); return CHARLIT; } -\"({GRAPHIC}|"[\""({HEXDIG}{2}|\")"\"]")*\" { + /* Note that we don't handle bracket sequences of more than 2 + digits here. Currently there's no support for wide or + wide-wide strings. */ +\"({GRAPHIC}|"[\""({HEXDIG}{2,}|\")"\"]")*\" { yylval.sval = processString (yytext+1, yyleng-2); return STRING; } @@ -513,10 +515,12 @@ processString (const char *text, int len) } else { - int chr; - sscanf (p+2, "%2x", &chr); + const char *end; + ULONGEST chr = strtoulst (p + 2, &end, 16); + if (chr > 0xff) + error (_("wide strings are not yet supported")); *q = (char) chr; - p += 5; + p = end + 1; } } else diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index a59c392bef4..bf95719f040 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -277,7 +277,11 @@ ada_emit_char (int c, struct type *type, struct ui_file *stream, fprintf_filtered (stream, "%c", c); } else - fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c); + { + /* Follow GNAT's lead here and only use 6 digits for + wide_wide_character. */ + fprintf_filtered (stream, "[\"%0*x\"]", std::min (6, type_len * 2), c); + } } /* Character #I of STRING, given that TYPE_LEN is the size in bytes diff --git a/gdb/testsuite/gdb.ada/char_enum_unicode.exp b/gdb/testsuite/gdb.ada/char_enum_unicode.exp index aa8136054e7..fad239983a3 100644 --- a/gdb/testsuite/gdb.ada/char_enum_unicode.exp +++ b/gdb/testsuite/gdb.ada/char_enum_unicode.exp @@ -40,4 +40,13 @@ gdb_test "print Char_Y" " = 2 $y" gdb_test "print Char_King" " = 3 $king" gdb_test "print Char_Thorn" " = 4 $thorn" gdb_test "print Char_Enum_Type'('x')" " = 1 'x'" +gdb_test "print Char_Enum_Type'('\[\"0178\"\]')" " = 2 $y" +gdb_test "print Char_Enum_Type'('\[\"1fa00\"\]')" " = 3 $king" gdb_test "print Char_Enum_Type'('\[\"de\"\]')" " = 4 $thorn" + +gdb_test "print '\[\"0178\"\]'" " = 376 $y" +gdb_test "print '\[\"01fa00\"\]'" " = 129536 $king" +gdb_test "print '\[\"de\"\]'" " = 222 $thorn" + +gdb_test "print \"\[\"0178\"\]\"" "wide strings are not yet supported" +gdb_test "print \"\[\"de\"\]\"" " = \"\\\[\"de\"\\\]\"" diff --git a/gdb/testsuite/gdb.ada/widewide.exp b/gdb/testsuite/gdb.ada/widewide.exp index 6fabb5bb08c..c0268f9c99b 100644 --- a/gdb/testsuite/gdb.ada/widewide.exp +++ b/gdb/testsuite/gdb.ada/widewide.exp @@ -33,9 +33,9 @@ if ![runto "foo.adb:$bp_location" ] then { gdb_test "print some_easy" "= 74 'J'" -gdb_test "print some_larger" "= 48879 '\\\[\"0000beef\"\\\]'" +gdb_test "print some_larger" "= 48879 '\\\[\"00beef\"\\\]'" -gdb_test "print some_big" "= 14335727 '\\\[\"00dabeef\"\\\]'" +gdb_test "print some_big" "= 14335727 '\\\[\"dabeef\"\\\]'" gdb_test "print my_wws" "= \" helo\"" -- 2.31.1