* [commit/Ada] print packed arrays indexed by enumerated type
@ 2012-02-29 19:37 Joel Brobecker
2012-03-03 14:02 ` Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2012-02-29 19:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
Consider the following declarations (a packed array indexed by an
enumerated type):
type Color is (Black, Red, Green, Blue, White);
type Full_Table is array (Color) of Boolean;
pragma Pack (Full_Table);
Full : Full_Table := (False, True, False, True, False);
GDB is unable to print the index values correctly. It prints the
enumeration's underlying value instead of the enumeration name:
(gdb) p full
$1 = (0 => false, true, false, true, false)
(gdb) p full'first
$2 = 0
And yet, it is capable of printing the correct type description:
(gdb) ptype full
type = array (black .. white) of boolean <packed: 1-bit elements>
To get to the real index type, one has to follow the parallel XA type.
We already do this for normal arrays. We can do it for this packed
array as well.
gdb/ChangeLog:
* ada-lang.c (constrained_packed_array_type): If there is a
parallel XA type, use it to determine the array index type.
gdb/testsuite/ChangeLog:
* gdb.ada/arrayidx.exp: Adjust expected output for p_one_two_three.
* gdb.ada/enum_idx_packed: New testcase.
Tested on x86_64-linux. Checked in.
---
gdb/ChangeLog | 5 +++
gdb/ada-lang.c | 14 +++++++--
gdb/testsuite/ChangeLog | 5 +++
gdb/testsuite/gdb.ada/arrayidx.exp | 4 +-
gdb/testsuite/gdb.ada/enum_idx_packed.exp | 38 +++++++++++++++++++++++++
gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb | 24 +++++++++++++++
gdb/testsuite/gdb.ada/enum_idx_packed/pck.adb | 21 +++++++++++++
gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads | 23 +++++++++++++++
8 files changed, 129 insertions(+), 5 deletions(-)
create mode 100644 gdb/testsuite/gdb.ada/enum_idx_packed.exp
create mode 100644 gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
create mode 100644 gdb/testsuite/gdb.ada/enum_idx_packed/pck.adb
create mode 100644 gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d09ed94..c00ab1d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2012-02-29 Joel Brobecker <brobecker@adacore.com>
+ * ada-lang.c (constrained_packed_array_type): If there is a
+ parallel XA type, use it to determine the array index type.
+
+2012-02-29 Joel Brobecker <brobecker@adacore.com>
+
* ada-valprint.c (ada_val_print_1): If our value is a reference
to an array descriptor, dereference it before converting it
to a simple array.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7243ab8..b1dbe32 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2006,22 +2006,30 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
{
struct type *new_elt_type;
struct type *new_type;
+ struct type *index_type_desc;
+ struct type *index_type;
LONGEST low_bound, high_bound;
type = ada_check_typedef (type);
if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
return type;
+ index_type_desc = ada_find_parallel_type (type, "___XA");
+ if (index_type_desc)
+ index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, 0),
+ NULL);
+ else
+ index_type = TYPE_INDEX_TYPE (type);
+
new_type = alloc_type_copy (type);
new_elt_type =
constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
elt_bits);
- create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
+ create_array_type (new_type, new_elt_type, index_type);
TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
TYPE_NAME (new_type) = ada_type_name (type);
- if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
- &low_bound, &high_bound) < 0)
+ if (get_discrete_bounds (index_type, &low_bound, &high_bound) < 0)
low_bound = high_bound = 0;
if (high_bound < low_bound)
*elt_bits = TYPE_LENGTH (new_type) = 0;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index af77953..2ff685a 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2012-02-29 Joel Brobecker <brobecker@adacore.com>
+ * gdb.ada/arrayidx.exp: Adjust expected output for p_one_two_three.
+ * gdb.ada/enum_idx_packed: New testcase.
+
+2012-02-29 Joel Brobecker <brobecker@adacore.com>
+
* gdb.ada/aliased_array: New testcase.
2012-02-29 Joel Brobecker <brobecker@adacore.com>
diff --git a/gdb/testsuite/gdb.ada/arrayidx.exp b/gdb/testsuite/gdb.ada/arrayidx.exp
index f8c087d..dd61a60 100644
--- a/gdb/testsuite/gdb.ada/arrayidx.exp
+++ b/gdb/testsuite/gdb.ada/arrayidx.exp
@@ -53,7 +53,7 @@ gdb_test "print u_one_two_three" \
"print u_one_two_three, indexes off"
gdb_test "print p_one_two_three" \
- "= \\(0 => false, true, true\\)" \
+ "= \\(false, true, true\\)" \
"print p_one_two_three, indexes off"
gdb_test "print few_reps" \
@@ -89,7 +89,7 @@ gdb_test "print u_one_two_three" \
"print u_one_two_three"
gdb_test "print p_one_two_three" \
- "= \\(0 => false, 1 => true, 2 => true\\)" \
+ "= \\(one => false, two => true, three => true\\)" \
"print p_one_two_three"
gdb_test "print few_reps" \
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed.exp b/gdb/testsuite/gdb.ada/enum_idx_packed.exp
new file mode 100644
index 0000000..61284bb
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed.exp
@@ -0,0 +1,38 @@
+# Copyright 2012 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"
+
+if { [skip_ada_tests] } { return -1 }
+
+set testdir "enum_idx_packed"
+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 {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 full" " = \\(false, true, false, true, false\\)"
+
+gdb_test "print full'first" " = black"
+
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb b/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
new file mode 100644
index 0000000..a8a0b91
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
@@ -0,0 +1,24 @@
+-- Copyright 2012 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
+ Full : Full_Table := (False, True, False, True, False);
+begin
+ Do_Nothing (Full'Address); -- STOP
+end Foo;
+
+
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed/pck.adb b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.adb
new file mode 100644
index 0000000..1f7d45c
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.adb
@@ -0,0 +1,21 @@
+-- Copyright 2012 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/enum_idx_packed/pck.ads b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
new file mode 100644
index 0000000..cba9eda
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
@@ -0,0 +1,23 @@
+-- Copyright 2012 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
+ type Color is (Black, Red, Green, Blue, White);
+ type Full_Table is array (Color) of Boolean;
+ pragma Pack (Full_Table);
+
+ procedure Do_Nothing (A : System.Address);
+end Pck;
--
1.7.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [commit/Ada] print packed arrays indexed by enumerated type
2012-02-29 19:37 [commit/Ada] print packed arrays indexed by enumerated type Joel Brobecker
@ 2012-03-03 14:02 ` Jan Kratochvil
2012-03-03 17:58 ` Joel Brobecker
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2012-03-03 14:02 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On Wed, 29 Feb 2012 20:35:08 +0100, Joel Brobecker wrote:
> gdb/ChangeLog:
>
> * ada-lang.c (constrained_packed_array_type): If there is a
> parallel XA type, use it to determine the array index type.
>
> gdb/testsuite/ChangeLog:
>
> * gdb.ada/arrayidx.exp: Adjust expected output for p_one_two_three.
> * gdb.ada/enum_idx_packed: New testcase.
Do you agree with these XFAILs? I did not bisect which GCC change it was.
Also gcc-4.7.0-0.16.fc17.x86_64 still FAILs despite it is 4.7; but that may
change with later updates, not sure.
Regards,
Jan
gdb/testsuite/
2012-03-03 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.ada/arrayidx.exp: Call get_compiler_info. New variable old_gcc.
(print one_two_three, indexes off, print few_reps, indexes off)
(print many_reps, indexes off, print empty, indexes off)
(print one_two_three, print few_reps, print many_reps, print empty):
Call setup_xfail if $gcc_old.
--- a/gdb/testsuite/gdb.ada/arrayidx.exp
+++ b/gdb/testsuite/gdb.ada/arrayidx.exp
@@ -27,6 +27,12 @@ if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
return -1
}
+if [get_compiler_info ${binfile}] {
+ return -1;
+}
+set old_gcc [expr [test_compiler_info {gcc-[0-3]-*}] \
+ || [test_compiler_info {gcc-4-[0-6]-*}]]
+
clean_restart ${testfile}
set bp_location [gdb_get_line_number "START" ${testdir}/p.adb]
@@ -36,6 +42,9 @@ runto "p.adb:$bp_location"
gdb_test_no_output "set print array-indexes off"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print one_two_three" \
"= \\(1, 2, 3\\)" \
"print one_two_three, indexes off"
@@ -56,14 +65,23 @@ gdb_test "print p_one_two_three" \
"= \\(false, true, true\\)" \
"print p_one_two_three, indexes off"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print few_reps" \
"= \\(1, 2, 3, 3, 3, 3, 3, 4, 5\\)" \
"print few_reps, indexes off"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print many_reps" \
"= \\(1, 2, 3 <repeats 12 times>, 4, 5\\)" \
"print many_reps, indexes off"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print empty" \
"= \\(\\)" \
"print empty, indexes off"
@@ -72,6 +90,9 @@ gdb_test "print empty" \
gdb_test_no_output "set print array-indexes on"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print one_two_three" \
"= \\(1 => 1, 2 => 2, 3 => 3\\)" \
"print one_two_three"
@@ -92,14 +113,23 @@ gdb_test "print p_one_two_three" \
"= \\(one => false, two => true, three => true\\)" \
"print p_one_two_three"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print few_reps" \
"= \\(1 => 1, 2 => 2, 3 => 3, 4 => 3, 5 => 3, 6 => 3, 7 => 3, 8 => 4, 9 => 5\\)" \
"print few_reps"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print many_reps" \
"= \\(1 => 1, 2 => 2, 3 => 3 <repeats 12 times>, 15 => 4, 16 => 5\\)" \
"print many_reps"
+if $old_gcc {
+ setup_xfail "*-*-*"
+}
gdb_test "print empty" \
"= \\(\\)" \
"print empty"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [commit/Ada] print packed arrays indexed by enumerated type
2012-03-03 14:02 ` Jan Kratochvil
@ 2012-03-03 17:58 ` Joel Brobecker
2012-03-03 18:08 ` [commit] KFAILs: " Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2012-03-03 17:58 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> Do you agree with these XFAILs? I did not bisect which GCC change it was.
> Also gcc-4.7.0-0.16.fc17.x86_64 still FAILs despite it is 4.7; but that may
> change with later updates, not sure.
No problem on my end.
I'll see if I can get the GCC sources and build a recent GCC.
If it's missing something, I'll ask one of our GCC guys if he has
time to look into it.
--
Joel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [commit] KFAILs: [commit/Ada] print packed arrays indexed by enumerated type
2012-03-03 17:58 ` Joel Brobecker
@ 2012-03-03 18:08 ` Jan Kratochvil
2012-03-03 18:13 ` Joel Brobecker
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2012-03-03 18:08 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On Sat, 03 Mar 2012 18:58:35 +0100, Joel Brobecker wrote:
> > Do you agree with these XFAILs? I did not bisect which GCC change it was.
> > Also gcc-4.7.0-0.16.fc17.x86_64 still FAILs despite it is 4.7; but that may
> > change with later updates, not sure.
>
> No problem on my end.
Checked in:
http://sourceware.org/ml/gdb-cvs/2012-03/msg00077.html
> I'll see if I can get the GCC sources and build a recent GCC.
> If it's missing something, I'll ask one of our GCC guys if he has
> time to look into it.
FYI the state it:
KFAIL: gcc (GCC) 4.4.7 20120303 (prerelease)
KFAIL: gcc (GCC) 4.5.4 20120303 (prerelease)
KFAIL: gcc (GCC) 4.6.4 20120303 (prerelease)
(this means KFAIL for _some_ of the testcases, otherwise PASS)
PASS: gcc (GCC) 4.7.0 20120303 (prerelease)
PASS: gcc (GCC) 4.8.0 20120303 (experimental)
(this means PASS for _all_ the testcases)
Fedora GCC 4.7.0pre is more complicated / FAILing but this is offtopic here
IMO, it is a pre-release anyway.
Regards,
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [commit] KFAILs: [commit/Ada] print packed arrays indexed by enumerated type
2012-03-03 18:08 ` [commit] KFAILs: " Jan Kratochvil
@ 2012-03-03 18:13 ` Joel Brobecker
0 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2012-03-03 18:13 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> Fedora GCC 4.7.0pre is more complicated / FAILing but this is offtopic here
> IMO, it is a pre-release anyway.
Ah, I understand now. Thanks for letting me know.
--
Joel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-03-03 18:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-29 19:37 [commit/Ada] print packed arrays indexed by enumerated type Joel Brobecker
2012-03-03 14:02 ` Jan Kratochvil
2012-03-03 17:58 ` Joel Brobecker
2012-03-03 18:08 ` [commit] KFAILs: " Jan Kratochvil
2012-03-03 18:13 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox