[commit/Ada] handle character-based enumeration typedefs

Joel Brobecker brobecker@adacore.com
Fri Jul 1 18:44:00 GMT 2011


Consider the following type:

   type Char_Enum_Type is ('A', 'B', 'C', 'D');

If the compiler generates a Char_Enum_Type typedef in the debugging
information, the debugger fails in the following case:

   (gdb) p Char_Enum_Type'('B')
   $1 = 66

For our type, the underlying value of 'B' is actually 1, not 66
(ASCII 'B').  We are failing this case because we were not handling
typedef to enum types before.  This patch fixes this.

gdb/ChangeLog:

        * ada-exp.y (convert_char_literal): Handle typedef types.

gdb/testsuite/ChangeLog:

        * gdb.ada/char_enum: New testcase.

Tested on x86_64-linux. Checked in.

---
 gdb/ChangeLog                           |    4 +++
 gdb/ada-exp.y                           |    6 ++++-
 gdb/testsuite/ChangeLog                 |    4 +++
 gdb/testsuite/gdb.ada/char_enum.exp     |   35 +++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.ada/char_enum/foo.adb |   23 ++++++++++++++++++++
 gdb/testsuite/gdb.ada/char_enum/pck.adb |   22 +++++++++++++++++++
 gdb/testsuite/gdb.ada/char_enum/pck.ads |   21 ++++++++++++++++++
 7 files changed, 114 insertions(+), 1 deletions(-)
 create mode 100644 gdb/testsuite/gdb.ada/char_enum.exp
 create mode 100644 gdb/testsuite/gdb.ada/char_enum/foo.adb
 create mode 100644 gdb/testsuite/gdb.ada/char_enum/pck.adb
 create mode 100644 gdb/testsuite/gdb.ada/char_enum/pck.ads

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3c8f30d..87832cf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
 2011-07-01  Joel Brobecker  <brobecker@adacore.com>
 
+	* ada-exp.y (convert_char_literal): Handle typedef types.
+
+2011-07-01  Joel Brobecker  <brobecker@adacore.com>
+
 	* ada-lang.c (ada_remove_trailing_digits): Expand documentation.
 
 2011-06-30  Tom Tromey  <tromey@redhat.com>
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index e64d1eb..9576be5 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1449,8 +1449,12 @@ convert_char_literal (struct type *type, LONGEST val)
   char name[7];
   int f;
 
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM)
+  if (type == NULL)
     return val;
+  type = check_typedef (type);
+  if (TYPE_CODE (type) != TYPE_CODE_ENUM)
+    return val;
+
   xsnprintf (name, sizeof (name), "QU%02x", (int) val);
   for (f = 0; f < TYPE_NFIELDS (type); f += 1)
     {
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1bf0ba0..79cbac0 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2011-07-01  Joel Brobecker  <brobecker@adacore.com>
+
+	* gdb.ada/char_enum: New testcase.
+
 2011-07-02  Yao Qi  <yao@codesourcery.com>
 
 	* gdb.base/dump.exp (capture_pointer_with_type): New.
diff --git a/gdb/testsuite/gdb.ada/char_enum.exp b/gdb/testsuite/gdb.ada/char_enum.exp
new file mode 100644
index 0000000..b1996e3
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/char_enum.exp
@@ -0,0 +1,35 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+load_lib "ada.exp"
+
+set testdir "char_enum"
+set testfile "${testdir}/foo"
+set srcfile ${srcdir}/${subdir}/${testfile}.adb
+set binfile ${objdir}/${subdir}/${testfile}
+
+file mkdir ${objdir}/${subdir}/${testdir}
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+  return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb]
+runto "foo.adb:$bp_location"
+
+gdb_test "print Char_Enum_Type'('B')" "= 1 'B'"
+
+
diff --git a/gdb/testsuite/gdb.ada/char_enum/foo.adb b/gdb/testsuite/gdb.ada/char_enum/foo.adb
new file mode 100644
index 0000000..1e60214
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/char_enum/foo.adb
@@ -0,0 +1,23 @@
+--  Copyright 2011 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with Pck; use Pck;
+
+procedure Foo is
+   type Char_Enum_Type is ('A', 'B', 'C', 'D', 'E');
+   Char : Char_Enum_Type := 'D';
+begin
+   Do_Nothing (Char'Address);  -- STOP
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/char_enum/pck.adb b/gdb/testsuite/gdb.ada/char_enum/pck.adb
new file mode 100644
index 0000000..01fdc3d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/char_enum/pck.adb
@@ -0,0 +1,22 @@
+--  Copyright 2011 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package body Pck is
+   procedure Do_Nothing (A : System.Address) is
+   begin
+      null;
+   end Do_Nothing;
+end Pck;
+
diff --git a/gdb/testsuite/gdb.ada/char_enum/pck.ads b/gdb/testsuite/gdb.ada/char_enum/pck.ads
new file mode 100644
index 0000000..a9e3cde
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/char_enum/pck.ads
@@ -0,0 +1,21 @@
+--  Copyright 2011 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with System;
+
+package Pck is
+   procedure Do_Nothing (A : System.Address);
+end Pck;
+
-- 
1.7.1



More information about the Gdb-patches mailing list