From patchwork Wed Aug 7 13:59:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33990 Received: (qmail 17104 invoked by alias); 7 Aug 2019 14:00:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17093 invoked by uid 89); 7 Aug 2019 14:00:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:3945 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Aug 2019 13:59:58 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0794856033; Wed, 7 Aug 2019 09:59:57 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vuIPM4gKpDWY; Wed, 7 Aug 2019 09:59:56 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id A772756032; Wed, 7 Aug 2019 09:59:56 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix bug with character enumeration literal Date: Wed, 7 Aug 2019 07:59:54 -0600 Message-Id: <20190807135954.28620-1-tromey@adacore.com> MIME-Version: 1.0 gnat encodes character enumeration literals using a few different schemes. The gnat compiler documented the "QU" and "QW" encodings, but failed to document that a simpler encoding was used for certain characters. This patch updates gdb to handle this simple Q encoding. Note that wide character literals are still not handled. gdb/ChangeLog 2019-08-07 Tom Tromey * ada-exp.y (convert_char_literal): Handle "Q%c" encoding. * ada-lang.c (ada_enum_name): Likewise. gdb/testsuite/ChangeLog 2019-08-07 Tom Tromey * gdb.ada/char_enum.exp: Add regression tests. * gdb.ada/char_enum/foo.adb (Char_Enum_Type): Use '_' and '0'. (Char, Gchar): Update. * gdb.ada/char_enum/pck.ads (Global_Enum_Type): Use '+'. --- gdb/ChangeLog | 5 +++++ gdb/ada-exp.y | 5 ++++- gdb/ada-lang.c | 8 ++++++++ gdb/testsuite/ChangeLog | 8 ++++++++ gdb/testsuite/gdb.ada/char_enum.exp | 6 ++++++ gdb/testsuite/gdb.ada/char_enum/foo.adb | 6 +++--- gdb/testsuite/gdb.ada/char_enum/pck.ads | 2 +- 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index f36aabaf150..c8a7b9c9c75 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -1390,7 +1390,10 @@ convert_char_literal (struct type *type, LONGEST val) if (TYPE_CODE (type) != TYPE_CODE_ENUM) return val; - xsnprintf (name, sizeof (name), "QU%02x", (int) val); + if ((val >= 'a' && val <= 'z') || (val >= '0' && val <= '9')) + xsnprintf (name, sizeof (name), "Q%c", (int) val); + else + xsnprintf (name, sizeof (name), "QU%02x", (int) val); size_t len = strlen (name); for (f = 0; f < TYPE_NFIELDS (type); f += 1) { diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 21a8e92462f..609f2d43919 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -9439,6 +9439,14 @@ ada_enum_name (const char *name) if (sscanf (name + 2, "%x", &v) != 1) return name; } + else if (((name[1] >= '0' && name[1] <= '9') + || (name[1] >= 'a' && name[1] <= 'z')) + && name[2] == '\0') + { + GROW_VECT (result, result_len, 4); + xsnprintf (result, result_len, "'%c'", name[1]); + return result; + } else return name; diff --git a/gdb/testsuite/gdb.ada/char_enum.exp b/gdb/testsuite/gdb.ada/char_enum.exp index c37d696f66d..1c814aa97f4 100644 --- a/gdb/testsuite/gdb.ada/char_enum.exp +++ b/gdb/testsuite/gdb.ada/char_enum.exp @@ -26,5 +26,11 @@ clean_restart ${testfile} set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb] runto "foo.adb:$bp_location" +gdb_test "ptype Char_Enum_Type" "type = \\('A', 'B', 'C', '_', '0'\\)" gdb_test "print Char_Enum_Type'('B')" "= 1 'B'" +gdb_test "print Char_Enum_Type'('_')" "= 3 '_'" +gdb_test "print Char_Enum_Type'('0')" "= 4 '0'" +gdb_test "ptype pck.Global_Enum_Type" "type = \\('x', 'Y', '\\+'\\)" +gdb_test "print pck.Global_Enum_Type'('x')" "= 0 'x'" gdb_test "print pck.Global_Enum_Type'('Y')" "= 1 'Y'" +gdb_test "print pck.Global_Enum_Type'('+')" "= 2 '\\+'" diff --git a/gdb/testsuite/gdb.ada/char_enum/foo.adb b/gdb/testsuite/gdb.ada/char_enum/foo.adb index cf7fb7d3399..6ae1ef61ae8 100644 --- a/gdb/testsuite/gdb.ada/char_enum/foo.adb +++ b/gdb/testsuite/gdb.ada/char_enum/foo.adb @@ -16,9 +16,9 @@ with Pck; use Pck; procedure Foo is - type Char_Enum_Type is ('A', 'B', 'C', 'D', 'E'); - Char : Char_Enum_Type := 'D'; - Gchar : Global_Enum_Type := 'Z'; + type Char_Enum_Type is ('A', 'B', 'C', '_', '0'); + Char : Char_Enum_Type := '_'; + Gchar : Global_Enum_Type := '+'; begin Do_Nothing (Char'Address); -- STOP end Foo; diff --git a/gdb/testsuite/gdb.ada/char_enum/pck.ads b/gdb/testsuite/gdb.ada/char_enum/pck.ads index f952e1c31c1..d3e7423646b 100644 --- a/gdb/testsuite/gdb.ada/char_enum/pck.ads +++ b/gdb/testsuite/gdb.ada/char_enum/pck.ads @@ -16,7 +16,7 @@ with System; package Pck is - type Global_Enum_Type is ('X', 'Y', 'Z'); + type Global_Enum_Type is ('x', 'Y', '+'); procedure Do_Nothing (A : System.Address); end Pck;