]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix bug with character enumeration literal
authorTom Tromey <tromey@adacore.com>
Thu, 1 Aug 2019 17:41:32 +0000 (11:41 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 15 Aug 2019 19:42:31 +0000 (13:42 -0600)
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-15  Tom Tromey  <tromey@adacore.com>

* ada-exp.y (convert_char_literal): Handle "Q%c" encoding.
* ada-lang.c (ada_enum_name): Likewise.

gdb/testsuite/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

* 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
gdb/ada-exp.y
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/char_enum.exp
gdb/testsuite/gdb.ada/char_enum/foo.adb
gdb/testsuite/gdb.ada/char_enum/pck.ads

index 517972aba99a9d044741524376d7581c44c342d9..d11753f60054a4202286f13e3e44854affbc316a 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-15  Tom Tromey  <tromey@adacore.com>
+
+       * ada-exp.y (convert_char_literal): Handle "Q%c" encoding.
+       * ada-lang.c (ada_enum_name): Likewise.
+
 2019-08-15  Christian Biesinger  <cbiesinger@google.com>
 
        * python/lib/gdb/__init__.py (GdbOutputFile): Rename to have a
index f36aabaf15001a3dcc796f8521bcf14bb98d5807..c8a7b9c9c752885619164d2f857199eaca73eb05 100644 (file)
@@ -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)
     {
index 21a8e92462f849a456d750989086b234d9b9d8a5..609f2d4391922c963224353e57a6254d31cb1903 100644 (file)
@@ -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;
 
index 640d392692ba2f366efcc7cf0ef904391dfd4ee8..def8a3174b4592615ab05a15351a3d6b02d1ac6a 100644 (file)
@@ -1,3 +1,11 @@
+2019-08-15  Tom Tromey  <tromey@adacore.com>
+
+       * 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 '+'.
+
 2019-08-15  Christian Biesinger  <cbiesinger@google.com>
 
        * gdb.python/python.exp: Expect a leading underscore on
index c37d696f66d02d957117438b0006b66bf2d72ef7..1c814aa97f462a894f8982979f45774bbba79a05 100644 (file)
@@ -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 '\\+'"
index cf7fb7d339918d9959037959dda00d9c67d25b10..6ae1ef61ae8cdd022d2e7ebe2915ba994c41af08 100644 (file)
@@ -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;
index f952e1c31c1eba973c4dbaa43aa44487f40fb213..d3e7423646bc44089693508ecd7d2e93c7544fe3 100644 (file)
@@ -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;