From: Sanimir Agovic Date: Sat, 12 Oct 2013 11:36:16 +0000 (+0100) Subject: vla: enable sizeof operator for indirection X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3c8452d46ac23d455c30438d0885a738e02b56e1;p=binutils-gdb.git vla: enable sizeof operator for indirection This patch enables the sizeof operator for indirections: 1| void foo (size_t n) { 2| int vla[n]; 3| int *vla_ptr = &vla; 4| } (gdb) p sizeof(*vla_ptr) yields sizeof (size_t) * n. gdb/ChangeLog: * eval.c (evaluate_subexp_for_sizeof) : Create an indirect value and retrieve the dynamic type size. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 17556097ace..c7efe6298ba 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2014-04-14 Sanimir Agovic + + * eval.c (evaluate_subexp_for_sizeof) : Create an indirect + value and retrieve the dynamic type size. + 2014-04-14 Sanimir Agovic * eval.c (evaluate_subexp_for_sizeof) : If the type diff --git a/gdb/eval.c b/gdb/eval.c index 85523cd2fd3..22392eb4aae 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3026,7 +3026,9 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos) && TYPE_CODE (type) != TYPE_CODE_ARRAY) error (_("Attempt to take contents of a non-pointer value.")); type = TYPE_TARGET_TYPE (type); - break; + if (is_dynamic_type (type)) + type = value_type (value_ind (val)); + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); case UNOP_MEMVAL: (*pos) += 3;