* [PATCH] [gdb/ada] Fix assert in ada_is_unconstrained_packed_array_type
@ 2021-12-06 11:31 Tom de Vries
2021-12-07 4:13 ` Joel Brobecker
0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2021-12-06 11:31 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey, Joel Brobecker
On openSUSE Leap 42.3, with system compiler gcc 4.8.5 I run into:
...
(gdb) print u_one_two_three^M
src/gdb/gdbtypes.h:1050: internal-error: field: \
Assertion `idx >= 0 && idx < num_fields ()' failed.^M
...
We run into trouble while doing this in
ada_is_unconstrained_packed_array_type:
...
1953 return TYPE_FIELD_BITSIZE (type, 0) > 0;
...
which tries to get field 0 from a type without fields:
...
(gdb) p type->num_fields ()
$6 = 0
...
which is the case because the type is a typedef:
...
(gdb) p type->code ()
$7 = TYPE_CODE_TYPEDEF
...
Fix this by using the type referenced by the typedef instead.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28323
---
gdb/ada-lang.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f8ba05b4276..336d950ec1d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -1949,6 +1949,8 @@ ada_is_unconstrained_packed_array_type (struct type *type)
/* The structure's first field is a pointer to an array, so this
fetches the array type. */
type = TYPE_TARGET_TYPE (type->field (0).type ());
+ if (type->code () == TYPE_CODE_TYPEDEF)
+ type = ada_typedef_target_type (type);
/* Now we can see if the array elements are packed. */
return TYPE_FIELD_BITSIZE (type, 0) > 0;
}
base-commit: 2427f3b09eb23e7949878cdc0b366fb605df568f
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] [gdb/ada] Fix assert in ada_is_unconstrained_packed_array_type
2021-12-06 11:31 [PATCH] [gdb/ada] Fix assert in ada_is_unconstrained_packed_array_type Tom de Vries
@ 2021-12-07 4:13 ` Joel Brobecker
0 siblings, 0 replies; 2+ messages in thread
From: Joel Brobecker @ 2021-12-07 4:13 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches, Tom Tromey, Joel Brobecker
Hi TomDV,
On Mon, Dec 06, 2021 at 12:31:31PM +0100, Tom de Vries wrote:
> On openSUSE Leap 42.3, with system compiler gcc 4.8.5 I run into:
> ...
> (gdb) print u_one_two_three^M
> src/gdb/gdbtypes.h:1050: internal-error: field: \
> Assertion `idx >= 0 && idx < num_fields ()' failed.^M
> ...
>
> We run into trouble while doing this in
> ada_is_unconstrained_packed_array_type:
> ...
> 1953 return TYPE_FIELD_BITSIZE (type, 0) > 0;
> ...
> which tries to get field 0 from a type without fields:
> ...
> (gdb) p type->num_fields ()
> $6 = 0
> ...
> which is the case because the type is a typedef:
> ...
> (gdb) p type->code ()
> $7 = TYPE_CODE_TYPEDEF
> ...
>
> Fix this by using the type referenced by the typedef instead.
>
> Tested on x86_64-linux.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28323
Thanks for the patch. This looks OK to me.
> gdb/ada-lang.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index f8ba05b4276..336d950ec1d 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -1949,6 +1949,8 @@ ada_is_unconstrained_packed_array_type (struct type *type)
> /* The structure's first field is a pointer to an array, so this
> fetches the array type. */
> type = TYPE_TARGET_TYPE (type->field (0).type ());
> + if (type->code () == TYPE_CODE_TYPEDEF)
> + type = ada_typedef_target_type (type);
> /* Now we can see if the array elements are packed. */
> return TYPE_FIELD_BITSIZE (type, 0) > 0;
> }
>
> base-commit: 2427f3b09eb23e7949878cdc0b366fb605df568f
> --
> 2.31.1
>
--
Joel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-07 4:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06 11:31 [PATCH] [gdb/ada] Fix assert in ada_is_unconstrained_packed_array_type Tom de Vries
2021-12-07 4: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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).