This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 03/12] vla: enable sizeof operator for indirection
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Cc: Sanimir Agovic <sanimir dot agovic at intel dot com>
- Date: Mon, 14 Apr 2014 10:13:07 -0700
- Subject: [PATCH 03/12] vla: enable sizeof operator for indirection
- Authentication-results: sourceware.org; auth=none
- References: <0377C58828D86C4588AEEC42FC3B85A71D8507B7 at IRSMSX105 dot ger dot corp dot intel dot com> <1397495596-25364-1-git-send-email-brobecker at adacore dot com>
From: Sanimir Agovic <sanimir.agovic@intel.com>
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) <UNOP_IND>: Create an indirect
value and retrieve the dynamic type size.
---
gdb/ChangeLog | 5 +++++
gdb/eval.c | 4 +++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1755609..c7efe62 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2014-04-14 Sanimir Agovic <sanimir.agovic@intel.com>
+ * eval.c (evaluate_subexp_for_sizeof) <UNOP_IND>: Create an indirect
+ value and retrieve the dynamic type size.
+
+2014-04-14 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.
diff --git a/gdb/eval.c b/gdb/eval.c
index 85523cd..22392eb 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;
--
1.8.3.2