This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH 02/10] type: add c99 variable length array support
- From: "Agovic, Sanimir" <sanimir dot agovic at intel dot com>
- To: "Tom Tromey (tromey at redhat dot com)" <tromey at redhat dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 19 Nov 2013 15:11:33 +0000
- Subject: RE: [PATCH 02/10] type: add c99 variable length array support
- Authentication-results: sourceware.org; auth=none
- References: <1382366424-21010-1-git-send-email-sanimir dot agovic at intel dot com> <1382366424-21010-3-git-send-email-sanimir dot agovic at intel dot com> <87eh6sujea dot fsf at fleche dot redhat dot com>
Thanks for your review.
> Sanimir> + switch (ctx->location)
> Sanimir> + {
> Sanimir> + case DWARF_VALUE_REGISTER:
> Sanimir> + *valp = dwarf_expr_read_reg (&baton, dwarf_expr_fetch_address (ctx, 0));
> Sanimir> + break;
> Sanimir> + case DWARF_VALUE_MEMORY:
> Sanimir> + *valp = dwarf_expr_fetch_address (ctx, 0);
> Sanimir> + break;
> Sanimir> + }
>
> It seems that something should be done for other DWARF_VALUE_* results
> here.
>
I will try, please have a closer look at this hunk in the upcoming v2.
> Sanimir> +struct type *
> Sanimir> +resolve_dynamic_type (struct type *type, CORE_ADDR address)
> Sanimir> +{
> [...]
> Sanimir> + if (!TYPE_OBJFILE_OWNED (ty))
> Sanimir> + return type;
>
> This seems like a bit of a wart, though I am not sure whether the
> situation can actually arise.
>
>
> One thing I didn't see in here is error-checking of whether resolution
> makes sense.
>
> E.g., suppose I print the value of a pointer-to-VLA. Then I move to
> some other frame and "print *$".
>
1| void foo (size_t n) {
2| int vla[n];
3| }
(gdb) print &vla
$1 = (int (*)[42]) 0xffffffffffff
(gdb) up
(gdb) print *$
$2 = {0 <repeats 42 times>}
(gdb) down
(gdb) print *$
$3 = {0 <repeats 42 times>}
> In this situation the bounds have not been resolved -- but applying the
> DWARF expression in the currently-selected frame will silently do the
> wrong thing.
>
The bounds will be resolved in this case and therefore it is save to change
the frame+re-evaluate. If you have a different example in mind please tell
me and I see how to deal with it.
> I wonder if this series also needs to handle DW_AT_count.
> Maybe no compiler generates it.
>
I will add a separate patch which implements DW_AT_count, I could not test
it as no compiler emits this attribute so far.
Below you will find the trivial reviews.
-Sanimir
> -----Original Message-----
> From: Tom Tromey [mailto:tromey@redhat.com]
> Sent: Thursday, November 07, 2013 08:00 PM
> To: Agovic, Sanimir
> Cc: gdb-patches@sourceware.org
> Subject: Re: [PATCH 02/10] type: add c99 variable length array support
>
> >>>>> "Sanimir" == Sanimir Agovic <sanimir.agovic@intel.com> writes:
>
> Sanimir> The dwarf standard allow certain attributes to be expressed as
> Sanimir> dwarf expressions rather than constants. For instance
> Sanimir> upper-/lowerbound attributes. In case of a c99 variable length
> Sanimir> array the upperbound is a dynamic attribute.
>
>
> Sanimir> +int
> Sanimir> +dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
> Sanimir> + CORE_ADDR addr, CORE_ADDR *valp)
>
> Need an introductory comment. It can just say "See dwarf2loc.h.", since
> you put the real comment there.
>
Done.
> Sanimir> +static struct dwarf2_locexpr_baton* attr_to_locexprbaton
> Sanimir> +(const struct attribute *, struct dwarf2_cu *);
> Sanimir> +
> Sanimir> +static struct dwarf2_locexpr_baton* attr_to_locexprbaton_1
> Sanimir> +(const struct attribute *, struct dwarf2_cu *, const gdb_byte *additional_data,
> Sanimir> + int extra_size);
> Sanimir> +
> Sanimir> +static int attr_to_dwarf2_prop
> Sanimir> +(struct die_info *, const struct attribute *, struct dwarf2_cu *,
> Sanimir> + struct dwarf2_prop *);
>
> In cases like this we usually indent the subsequent lines a bit, like:
>
> static int attr_to_dwarf2_prop
> (struct die_info *, const struct attribute *, struct dwarf2_cu *,
> struct dwarf2_prop *);
>
> However in this case I think it may be preferable to rearrange the
> functions so that forward declarations are not needed. What do you
> think?
>
Done. Moved functions and dropped forward declaration.
> Sanimir> +static struct dwarf2_locexpr_baton*
> Sanimir> +attr_to_locexprbaton (const struct attribute *attribute, struct dwarf2_cu *cu)
> Sanimir> +{
> Sanimir> + return attr_to_locexprbaton_1 (attribute, cu, NULL, 0);
> Sanimir> +}
>
> If there is just a single caller (there is in this patch, but I haven't
> read all the patches yet), I would remove this function and just update
> the caller.
>
Done. Folded function attr_to_locexprbaton/_1 into attr_to_locexprbaton.
> Sanimir> +static struct dwarf2_locexpr_baton*
> Sanimir> +attr_to_locexprbaton_1 (const struct attribute *attribute, struct dwarf2_cu *cu,
> Sanimir> + const gdb_byte *additional_data, int extra_size)
>
> Needs an introductory comment.
>
Done.
> Sanimir> + /* Copy the data pointer as the blocks lifetime is
>
> Missing apostrophe: "block's".
>
Done.
> Sanimir> + gdb_assert(baton->data != NULL);
>
> Space before open paren.
>
Done.
> Sanimir> +/* Parse dwarf attribute if it's a block, reference or constant and put the
> Sanimir> + resulting value of the attribute into struct dwarf2_prop. */
> Sanimir> +
> Sanimir> +static int
> Sanimir> +attr_to_dwarf2_prop (struct die_info *die, const struct attribute *attr,
> Sanimir> + struct dwarf2_cu *cu,
> Sanimir> + struct dwarf2_prop *prop)
>
> I think it would be good if the introductory comment describe the return
> value.
>
Done.
> Sanimir> + else if (attr_form_is_ref (attr))
> Sanimir> + {
> Sanimir> + struct dwarf2_cu *target_cu = cu;
> Sanimir> + struct die_info *target_die;
> Sanimir> + struct attribute *target_attr;
> Sanimir> + const gdb_byte append_ops[] = { DW_OP_deref };
> Sanimir> +
> Sanimir> + target_die = follow_die_ref (die, attr, &target_cu);
> Sanimir> + target_attr = dwarf2_attr (target_die, DW_AT_location, target_cu);
> Sanimir> +
> Sanimir> + prop->data.locexpr =
> Sanimir> + attr_to_locexprbaton_1 (target_attr, cu, append_ops,
> Sanimir> + sizeof (append_ops) / sizeof (append_ops[0]));
> Sanimir> + prop->kind = DWARF_LOCEXPR;
> Sanimir> + gdb_assert (prop->data.locexpr != NULL);
>
> I don't understand this hunk. Could you say why it is needed?
>
DW_AT_upper_bound may reference a die e.g. artificial variable, in this case we
need to read DW_AT_location of the target die. Some compilers emit this form to
implement vla.
> Sanimir> + dwarf2_invalid_attrib_class_complaint(dwarf_form_name (attr->form),
> Sanimir> + dwarf2_name (die, cu));
>
> Missing space before a paren.
>
Done.
> Sanimir> +static int
> Sanimir> +has_static_range (const struct range_bounds *bounds)
> Sanimir> +{
> Sanimir> + return bounds->low.kind == DWARF_CONST
> Sanimir> + && bounds->high.kind == DWARF_CONST;
> Sanimir> +}
>
> THis needs parens around the argument to "return" and then an
> indentation fix on the second line.
>
Done.
> Sanimir> +/* Calculates the size of a type given the upper and lower bound of a dynamic
> Sanimir> + type. */
> Sanimir> +
> Sanimir> +static ULONGEST
> Sanimir> +get_type_length (const struct type *type)
> Sanimir> +{
> Sanimir> + const struct type *range_type, *target_type;
> Sanimir> + ULONGEST len = TYPE_LENGTH (type);
> Sanimir> + LONGEST low_bound, high_bound;
> Sanimir> +
> Sanimir> + if (TYPE_CODE (type) != TYPE_CODE_ARRAY
> Sanimir> + && TYPE_CODE (type) != TYPE_CODE_STRING)
> Sanimir> + return len;
> Sanimir> +
> Sanimir> + range_type = TYPE_INDEX_TYPE (type);
> Sanimir> +
> Sanimir> + if (!has_static_range (TYPE_RANGE_DATA (range_type)))
> Sanimir> + return len;
>
> This seems like it doesn't follow what the introductory comment says it
> does.
>
Fixed document.
> Sanimir> +
> Sanimir> +static void
> Sanimir> +resolve_dynamic_bounds (struct type *type, CORE_ADDR address)
>
> Introductory comment.
>
Done.
> Sanimir> + do {
> Sanimir> + struct type *range_type = TYPE_INDEX_TYPE (ary_dim);
>
> It's hard to know but perhaps a check_typedef is required here.
>
> Sanimir> + ary_dim = TYPE_TARGET_TYPE (ary_dim);
>
> Here too.
>
Done.
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