From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32170 invoked by alias); 4 Dec 2013 14:21:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32141 invoked by uid 89); 4 Dec 2013 14:21:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.0 required=5.0 tests=AWL,BAYES_50,KAM_STOCKGEN,RDNS_NONE,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mga11.intel.com Received: from Unknown (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Dec 2013 14:20:34 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 04 Dec 2013 06:20:26 -0800 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 04 Dec 2013 06:20:13 -0800 Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [172.28.50.125]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id rB4EKCsw021416; Wed, 4 Dec 2013 14:20:12 GMT Received: from ulliclel004.iul.intel.com (ulliclel004.iul.intel.com [127.0.0.1]) by ulliclel004.iul.intel.com (8.13.8/8.12.8/MailSET/client) with ESMTP id rB4EKBg2010346; Wed, 4 Dec 2013 15:20:11 +0100 Received: (from sagovic@localhost) by ulliclel004.iul.intel.com (8.13.8/8.13.1/Submit) id rB4EK6d0010231; Wed, 4 Dec 2013 15:20:06 +0100 From: Sanimir Agovic To: tromey@redhat.com, palves@redhat.com, xdje42@gmail.com Cc: gdb-patches@sourceware.org, keven.boell@intel.com Subject: [PATCH v3 03/13] vla: enable sizeof operator to work with variable length arrays Date: Wed, 04 Dec 2013 14:21:00 -0000 Message-Id: <1386166785-28037-4-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1386166785-28037-1-git-send-email-sanimir.agovic@intel.com> References: <1386166785-28037-1-git-send-email-sanimir.agovic@intel.com> X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00130.txt.bz2 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 Keven Boell * eval.c (evaluate_subexp_for_sizeof): If the type passed to sizeof is dynamic evaluate the argument to compute the length. Change-Id: I79656d4ec5bd5d728748a1059ac414a5440eb659 Signed-off-by: Sanimir Agovic --- 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