From patchwork Thu Apr 10 12:40:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Agovic, Sanimir" X-Patchwork-Id: 476 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx21.g.dreamhost.com (peon2454.g.dreamhost.com [208.113.200.127]) by wilcox.dreamhost.com (Postfix) with ESMTP id 2EDA436005B for ; Thu, 10 Apr 2014 05:44:45 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id E1E3B2455972; Thu, 10 Apr 2014 05:44:44 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx21.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx21.g.dreamhost.com (Postfix) with ESMTPS id B696127CA7FA for ; Thu, 10 Apr 2014 05:44:44 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=ZfcKYg1mOx8zjV6tAs6hHhUVeqKNMi1 w/gbtSPCLurLtcDfE4JFFNSdd5RsxaKcJaSraG7+y8baPp88sT54wlQvSjvc0ajd 9pKYU7m53jo9Symg9n5O9S/yrm5h6xCnvIUGTXhqxFNolbvn19MF8viV+DRCPgq+ 0MDLNvS6tExc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=4eSnDdp4L56ii4g8DypyPfuGozQ=; b=O66b3 DRi1dubaXGkveQqtTwDXb0S0wmGDL+XWuux/FuWgM3Nd5U8fa0KxEbb0/a2PO2wZ F3iBr0oyJ0/cSfDdcYw6f+AOPRC+qv+T6JNbxXsQwEOlxIAkepbbbgPcgP9jj/6S UFTbJisQBdZFRXx1aPqPxYhGzWgHYpONRellhM= Received: (qmail 26945 invoked by alias); 10 Apr 2014 12:44:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 26924 invoked by uid 89); 10 Apr 2014 12:44:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mga11.intel.com Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Apr 2014 12:44:41 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 10 Apr 2014 05:44:39 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2014 05:44:38 -0700 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 s3ACiMHV009777; Thu, 10 Apr 2014 13:44:27 +0100 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 s3AChKmk026746; Thu, 10 Apr 2014 14:43:51 +0200 Received: (from sagovic@localhost) by ulliclel004.iul.intel.com (8.13.8/8.13.1/Submit) id s3AChFKg026745; Thu, 10 Apr 2014 14:43:15 +0200 From: Sanimir Agovic To: brobecker@adacore.com Cc: gdb-patches@sourceware.org, tromey@redhat.com Subject: [PATCH v6 04/15] vla: enable sizeof operator to work with variable length arrays Date: Thu, 10 Apr 2014 14:40:06 +0200 Message-Id: <1397133617-26681-5-git-send-email-sanimir.agovic@intel.com> In-Reply-To: <1397133617-26681-1-git-send-email-sanimir.agovic@intel.com> References: <1397133617-26681-1-git-send-email-sanimir.agovic@intel.com> X-IsSubscribed: yes X-DH-Original-To: gdb@patchwork.siddhesh.in 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. 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));