From: "Agovic, Sanimir" <sanimir.agovic@intel.com>
To: 'Tom Tromey' <tromey@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 2/2] handle VLA in a struct or union
Date: Fri, 09 May 2014 08:05:00 -0000 [thread overview]
Message-ID: <0377C58828D86C4588AEEC42FC3B85A71D86BED8@IRSMSX105.ger.corp.intel.com> (raw)
In-Reply-To: <1399574816-12845-3-git-send-email-tromey@redhat.com>
> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 95b861e..59f354a 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -1636,6 +1636,20 @@ is_dynamic_type (struct type *type)
> return 1;
> return is_dynamic_type (TYPE_TARGET_TYPE (type));
> }
> +
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + {
> + int i;
> +
> + for (i = 0; i < TYPE_NFIELDS (type); ++i)
> + if (!field_is_static (&TYPE_FIELD (type, i))
> + /* This can happen with Ada for reasons unknown. */
> + && TYPE_FIELD_TYPE (type, i) != NULL
> + && is_dynamic_type (TYPE_FIELD_TYPE (type, i)))
> + return 1;
> + }
> + break;
> }
>
> return 0;
> @@ -1753,6 +1767,86 @@ resolve_dynamic_type (struct type *type, CORE_ADDR addr)
> case TYPE_CODE_RANGE:
> resolved_type = resolve_dynamic_range (type);
> break;
> +
> + case TYPE_CODE_UNION:
>
As Joel has moved the heavy work out of the cases into separate function
how about doing the same for arrays and unions (resolve_dynamic_compound)?
> + {
> + int i;
> + unsigned int max_len;
> +
> + resolved_type = copy_type (type);
> + TYPE_FIELDS (resolved_type)
> + = TYPE_ALLOC (resolved_type,
> + TYPE_NFIELDS (resolved_type) * sizeof (struct field));
> + memcpy (TYPE_FIELDS (resolved_type),
> + TYPE_FIELDS (type),
> + TYPE_NFIELDS (resolved_type) * sizeof (struct field));
> + for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
> + {
> + struct type *t;
> +
> + if (field_is_static (&TYPE_FIELD (type, i)))
> + continue;
> +
> + t = resolve_dynamic_type (TYPE_FIELD_TYPE (resolved_type, i),
> + addr);
> +
> + TYPE_FIELD_TYPE (resolved_type, i) = t;
> + if (TYPE_LENGTH (t) > max_len)
> + max_len = TYPE_LENGTH (t);
> + }
> +
> + TYPE_LENGTH (resolved_type) = max_len;
> + }
> + break;
> +
> + case TYPE_CODE_STRUCT:
> + {
> + int i;
> + int vla_field = TYPE_NFIELDS (type) - 1;
> +
How about adding a gdb_assert to ensure NFIELDS is > 0. I know this cannot
happen in this particular case but in others it might and one may assume
that a struct has at least a member which is not the case.
> diff --git a/gdb/testsuite/gdb.base/vla-datatypes.c b/gdb/testsuite/gdb.base/vla-
> datatypes.c
> index 51e342e..8561a4e 100644
> --- a/gdb/testsuite/gdb.base/vla-datatypes.c
> +++ b/gdb/testsuite/gdb.base/vla-datatypes.c
> @@ -46,6 +46,18 @@ vla_factory (int n)
> BAR bar_vla[n];
> int i;
>
> + struct vla_struct
> + {
> + int something;
> + int vla_field[n];
> + } vla_struct_object;
> +
> + union vla_union
> + {
> + int vla_field[n];
> + } vla_union_object;
> +
As you have pointed out the limitation of vla within arrays, this might
as well serve as a test case that we deal with it.
-Sanimir
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
next prev parent reply other threads:[~2014-05-09 8:05 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-08 18:47 [PATCH 0/2] " Tom Tromey
2014-05-08 18:47 ` [PATCH 2/2] handle " Tom Tromey
2014-05-08 19:01 ` pinskia
2014-05-08 19:07 ` Tom Tromey
2014-05-08 20:30 ` Philippe Waroquiers
2014-05-08 21:32 ` Tom Tromey
2014-05-08 21:09 ` Joel Brobecker
2014-05-08 21:33 ` Tom Tromey
2014-05-08 22:38 ` Joel Brobecker
2014-05-09 15:57 ` Joel Brobecker
2014-05-21 17:28 ` Tom Tromey
2014-05-21 18:24 ` Joel Brobecker
2014-05-21 22:02 ` Joel Brobecker
2014-05-21 22:28 ` Tom Tromey
2014-06-04 20:27 ` Tom Tromey
2014-05-09 8:05 ` Agovic, Sanimir [this message]
2014-05-09 21:08 ` Tom Tromey
2014-05-12 15:37 ` Agovic, Sanimir
2014-05-12 17:00 ` Tom Tromey
2014-05-13 7:53 ` Agovic, Sanimir
2014-05-08 18:47 ` [PATCH 1/2] minor cleanups in is_dynamic_type Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0377C58828D86C4588AEEC42FC3B85A71D86BED8@IRSMSX105.ger.corp.intel.com \
--to=sanimir.agovic@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox