From 18920c42269018b87630cab5d90ed7b323dbfd55 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Fri, 1 Jul 2011 18:25:17 +0000 Subject: [PATCH] handle character-based enumeration typedefs 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. --- 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 deletion(-) 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 3c8f30d5ccf..87832cfee3a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2011-07-01 Joel Brobecker + + * ada-exp.y (convert_char_literal): Handle typedef types. + 2011-07-01 Joel Brobecker * ada-lang.c (ada_remove_trailing_digits): Expand documentation. diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index e64d1eb4566..9576be5e308 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 1bf0ba0d2c7..79cbac01b03 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-07-01 Joel Brobecker + + * gdb.ada/char_enum: New testcase. + 2011-07-02 Yao Qi * 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 00000000000..b1996e31d58 --- /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 . + +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 00000000000..1e60214f4b0 --- /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 . + +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 00000000000..01fdc3d7895 --- /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 . + +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 00000000000..a9e3cdedc8a --- /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 . + +with System; + +package Pck is + procedure Do_Nothing (A : System.Address); +end Pck; + -- 2.30.2