From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11182 invoked by alias); 21 Oct 2013 14:40:36 -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 11137 invoked by uid 89); 21 Oct 2013 14:40:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mga02.intel.com Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 21 Oct 2013 14:40:35 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 21 Oct 2013 07:40:34 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 21 Oct 2013 07:40:33 -0700 Received: from ulliclel001.iul.intel.com (ulliclel001.iul.intel.com [172.28.50.199]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id r9LEeW6Y030715 for ; Mon, 21 Oct 2013 15:40:32 +0100 Received: from ulliclel001.iul.intel.com (localhost [127.0.0.1]) by ulliclel001.iul.intel.com (8.14.4/8.12.8/MailSET/client) with ESMTP id r9LEeWnu021116 for ; Mon, 21 Oct 2013 16:40:32 +0200 Received: (from sagovic@localhost) by ulliclel001.iul.intel.com (8.14.4/8.12.8/MailSET/Submit) id r9LEeVr9021115 for gdb-patches@sourceware.org; Mon, 21 Oct 2013 16:40:31 +0200 From: Sanimir Agovic To: gdb-patches@sourceware.org Subject: [PATCH 03/10] vla: enable sizeof operator to work with variable length arrays Date: Mon, 21 Oct 2013 14:40:00 -0000 Message-Id: <1382366424-21010-4-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1382366424-21010-1-git-send-email-sanimir.agovic@intel.com> References: <1382366424-21010-1-git-send-email-sanimir.agovic@intel.com> X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00628.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. 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. * gdbtypes.c (is_dynamic_type): Make extern. * gdbtypes.c (is_dynamic_type): Make extern. Change-Id: I490f695f7a164be5f1f824fe3ba33f805d1ab689 --- gdb/eval.c | 8 +++++++- gdb/gdbtypes.c | 2 +- gdb/gdbtypes.h | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index e83bfdf..9e4afa3 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)); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index c0f375d..9774a4b 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1624,7 +1624,7 @@ resolve_dynamic_prop (const struct dwarf2_prop *prop, CORE_ADDR address, /* Predicates if the type has dynamic values, which are not resolved yet. */ -static int +int is_dynamic_type (const struct type *type) { if (type == NULL) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 96e0ed7..1252fd1 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1580,6 +1580,8 @@ extern struct type *lookup_unsigned_typename (const struct language_defn *, extern struct type *lookup_signed_typename (const struct language_defn *, struct gdbarch *, const char *); +extern int is_dynamic_type (const struct type *type); + extern struct type *resolve_dynamic_type (struct type *, CORE_ADDR); extern struct type *check_typedef (struct type *); -- 1.7.0.7