* [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound()
@ 2005-10-05 23:28 Joel Brobecker
2005-10-05 23:30 ` Joel Brobecker
2005-10-09 20:32 ` Daniel Jacobowitz
0 siblings, 2 replies; 4+ messages in thread
From: Joel Brobecker @ 2005-10-05 23:28 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 2336 bytes --]
Hello,
This is a regression I noticed after introducing "set print array-indexes".
Consider the code submitted in the gdb.ada/arrayidx testcase:
http://sources.redhat.com/ml/gdb-patches/2005-10/msg00046.html
You have an enumerated type declared, and then an array type declared
using that enumerated type as its index:
type Index is (One, Two, Three);
type RTable is array (Index range Two .. Three) of Integer;
As you see, the array type does not use the entire enumerated type
range as its index, but only a subrange of it. So when printing an
array of this type, such as:
R_Two_Three : RTable := (2, 3);
The debugger should notice that the lower bound of the array is
not the first element of the enumerated type, and therefore should
explicitly print the index of the first array element, like this:
(gdb) print r_two_three
$1 = (two => 2, 3)
However, we currently get this:
(gdb) print r_two_three
$1 = (two => 2, 3)
What happens is that GDB sees in print_optional_low_bound() that
the index type is a TYPE_CODE_RANGE, failing to see that underneath
there is an enumerated type. So it therefore compares the value of
the low bound against 1, which it should compare it against the value
of the first enumeration in the enumerated type.
The underlying value of an enumerated type is typically zero, so
"one" is zero, and "two" is 1.
Just to make it easier to see what's after the patch, here is a copy
of the switch seen in the patch:
switch (TYPE_CODE (index_type))
{
case TYPE_CODE_ENUM:
if (low_bound == TYPE_FIELD_BITPOS (index_type, 0))
return 0;
break;
case TYPE_CODE_UNDEF:
index_type = builtin_type_long;
/* FALL THROUGH */
default:
if (low_bound == 1)
return 0;
break;
}
The patch fixes this problem. It's not sufficient to fix the problem,
due to another problem I eluded to when submitting gdb.ada/arrayidx.exp.
But this patch will be needed.
2005-10-05 Joel Brobecker <brobecker@adacore.com>
* ada-valprint.c (print_optional_low_bound): Handle properly
cases where the array index type is a TYPE_CODE_RANGE.
Tested on x86-linux. No regression.
Thanks,
--
Joel
[-- Attachment #2: ada-valprint.c.diff --]
[-- Type: text/plain, Size: 887 bytes --]
Index: ada-valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-valprint.c,v
retrieving revision 1.24
diff -u -p -r1.24 ada-valprint.c
--- ada-valprint.c 3 Oct 2005 21:21:20 -0000 1.24
+++ ada-valprint.c 5 Oct 2005 23:26:09 -0000
@@ -94,6 +94,16 @@ print_optional_low_bound (struct ui_file
index_type = TYPE_INDEX_TYPE (type);
+ if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
+ {
+ /* We need to know what the base type is, in order to do the
+ appropriate check below. Otherwise, if this is a subrange
+ of an enumerated type, where the underlying value of the
+ first element is typically 0, we might test the low bound
+ against the wrong value. */
+ index_type = TYPE_TARGET_TYPE (index_type);
+ }
+
switch (TYPE_CODE (index_type))
{
case TYPE_CODE_ENUM:
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound()
2005-10-05 23:28 [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound() Joel Brobecker
@ 2005-10-05 23:30 ` Joel Brobecker
2005-10-09 20:32 ` Daniel Jacobowitz
1 sibling, 0 replies; 4+ messages in thread
From: Joel Brobecker @ 2005-10-05 23:30 UTC (permalink / raw)
To: gdb-patches
> However, we currently get this:
>
> (gdb) print r_two_three
> $1 = (two => 2, 3)
AARRGH. Copy/paste error. I should have written:
> However, we currently get this:
>
> (gdb) print r_two_three
> $1 = (2, 3)
(no explicit index in the array value)
--
Joel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound()
2005-10-05 23:28 [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound() Joel Brobecker
2005-10-05 23:30 ` Joel Brobecker
@ 2005-10-09 20:32 ` Daniel Jacobowitz
2005-10-10 1:15 ` Joel Brobecker
1 sibling, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-10-09 20:32 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On Wed, Oct 05, 2005 at 04:28:15PM -0700, Joel Brobecker wrote:
> 2005-10-05 Joel Brobecker <brobecker@adacore.com>
>
> * ada-valprint.c (print_optional_low_bound): Handle properly
> cases where the array index type is a TYPE_CODE_RANGE.
Sure, this is OK.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound()
2005-10-09 20:32 ` Daniel Jacobowitz
@ 2005-10-10 1:15 ` Joel Brobecker
0 siblings, 0 replies; 4+ messages in thread
From: Joel Brobecker @ 2005-10-10 1:15 UTC (permalink / raw)
To: gdb-patches
> > 2005-10-05 Joel Brobecker <brobecker@adacore.com>
> >
> > * ada-valprint.c (print_optional_low_bound): Handle properly
> > cases where the array index type is a TYPE_CODE_RANGE.
>
> Sure, this is OK.
Thanks, checked in as well.
--
Joel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-10-10 1:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-05 23:28 [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound() Joel Brobecker
2005-10-05 23:30 ` Joel Brobecker
2005-10-09 20:32 ` Daniel Jacobowitz
2005-10-10 1:15 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox