This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 02/12] vla: enable sizeof operator to work with variable length arrays
- 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:06 -0700
- Subject: [PATCH 02/12] vla: enable sizeof operator to work with variable length arrays
- 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>
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).
gdb/ChangeLog:
* eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
passed to sizeof is dynamic evaluate the argument to compute the length.
---
gdb/ChangeLog | 5 +++++
gdb/eval.c | 8 +++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cf9a35d..1755609 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,4 +1,9 @@
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.
+
+2014-04-14 Sanimir Agovic <sanimir.agovic@intel.com>
Joel Brobecker <brobecker@adacore.com>
* dwarf2loc.c (dwarf2_locexpr_baton_eval): New function.
diff --git a/gdb/eval.c b/gdb/eval.c
index c1e47e0..85523cd 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3040,8 +3040,14 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
break;
case OP_VAR_VALUE:
- (*pos) += 4;
type = 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;
break;
default:
--
1.8.3.2