vla: enable sizeof operator to work with variable length arrays

In C99 the sizeof operator computes the size of a variable length array
at runtime (6.5.3.4 The sizeof operator). This patch reflects the semantic
change in the debugger.

We now are able to get the size of a vla:

1| void foo (size_t n) {
2|   int vla[n];
3| }

(gdb) p sizeof(vla)

yields N * sizeof(int).

	* eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
	passed to sizeof is dynamic evaluate the argument to compute the length.
This commit is contained in:
Sanimir Agovic 2013-10-09 15:28:22 +01:00
parent 37c1ab67a3
commit 26cb189f8b
2 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2014-04-11 Sanimir Agovic <sanimir.agovic@intel.com>
* eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
passed to sizeof is dynamic evaluate the argument to compute the length.
2014-04-11 Sanimir Agovic <sanimir.agovic@intel.com>
* dwarf2loc.c (dwarf2_locexpr_baton_eval): New function.

View File

@ -3040,8 +3040,14 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
case OP_VAR_VALUE:
(*pos) += 4;
type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
if (is_dynamic_type (type))
{
val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
type = value_type (val);
}
else
(*pos) += 4;
return
value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));