This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 02/10] type: add c99 variable length array support

>>>>> "Sanimir" == Sanimir Agovic <> 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.

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

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

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.

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.

Sanimir> +    /* Copy the data pointer as the blocks lifetime is

Missing apostrophe: "block's".

Sanimir> +  gdb_assert(baton->data != NULL);

Space before open paren.

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

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?

I wonder if this series also needs to handle DW_AT_count.
Maybe no compiler generates it.

Sanimir> +      dwarf2_invalid_attrib_class_complaint(dwarf_form_name (attr->form),
Sanimir> +					    dwarf2_name (die, cu));

Missing space before a paren.

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.

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

Sanimir> +
Sanimir> +static void
Sanimir> +resolve_dynamic_bounds (struct type *type, CORE_ADDR address)

Introductory comment.

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.

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 *$".

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]