This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v4 03/13] vla: enable sizeof operator to work with variable length arrays
- From: Sanimir Agovic <sanimir dot agovic at intel dot com>
- To: tromey at redhat dot com, palves at redhat dot com, xdje42 at gmail dot com
- Cc: gdb-patches at sourceware dot org, keven dot boell at intel dot com
- Date: Tue, 17 Dec 2013 13:17:48 +0100
- Subject: [PATCH v4 03/13] vla: enable sizeof operator to work with variable length arrays
- Authentication-results: sourceware.org; auth=none
- References: <1387282678-3847-1-git-send-email-sanimir dot agovic at intel dot 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).
2013-10-18 Sanimir Agovic <sanimir.agovic@intel.com>
Keven Boell <keven.boell@intel.com>
* eval.c (evaluate_subexp_for_sizeof): If the type passed to sizeof is
dynamic evaluate the argument to compute the length.
Change-Id: I79656d4ec5bd5d728748a1059ac414a5440eb659
---
gdb/eval.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 9d81a92..a81e789 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3041,8 +3041,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));
--
1.8.3.1