From patchwork Mon Apr 14 17:13:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 540 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (mx2.sub5.homie.mail.dreamhost.com [208.113.200.128]) by wilcox.dreamhost.com (Postfix) with ESMTP id 89A43360075 for ; Mon, 14 Apr 2014 10:13:47 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14314964) id 39E4062AC1927; Mon, 14 Apr 2014 10:13:46 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx23.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-mx23.g.dreamhost.com (Postfix) with ESMTPS id D1EA062AC192D for ; Mon, 14 Apr 2014 10:13:46 -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=R8v6OxwdJFT8g2KypGYi9y70RbbKywK 0WXz3ci3oR96qZcbV/NPZYfFDQ/VRTYjBAx62R68bLBkDy9UENrx4JZKvTE9rlz3 vyXJmMo2hjoOCtr4T8nYCyebCQYeh9WmEqZp2D6n53qSWZXQ+DEumKmZzmNO5Z0B FXGO3x64XeFI= 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=EIJkd3ScygRcXoCwZeTSXKbBUDE=; b=WTKnl 0ksJQUTXF/t/teuGAXNOSrVaZ8Ztpci5OgCpe/hjIe8eEsQJE2rgULes4iG+9Xgk oJ4MuIy9z1olKeOXxC0J3DBZiL2fAGx1Rb8YdbH6o11+up/k4Y5qEgk7NI9803ez qfzPWfiH1PzjQ/Kg7VSvzm2TSmwR94rSvfS/0s= Received: (qmail 6778 invoked by alias); 14 Apr 2014 17:13:29 -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 6695 invoked by uid 89); 14 Apr 2014 17:13:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 14 Apr 2014 17:13:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id DCA071160DD; Mon, 14 Apr 2014 13:13:25 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gmw9cldXdrXS; Mon, 14 Apr 2014 13:13:25 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id AA17E1160DB; Mon, 14 Apr 2014 13:13:25 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 45032E02C0; Mon, 14 Apr 2014 10:13:31 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Sanimir Agovic Subject: [PATCH 03/12] vla: enable sizeof operator for indirection Date: Mon, 14 Apr 2014 10:13:07 -0700 Message-Id: <1397495596-25364-4-git-send-email-brobecker@adacore.com> In-Reply-To: <1397495596-25364-1-git-send-email-brobecker@adacore.com> References: <0377C58828D86C4588AEEC42FC3B85A71D8507B7@IRSMSX105.ger.corp.intel.com> <1397495596-25364-1-git-send-email-brobecker@adacore.com> X-DH-Original-To: gdb@patchwork.siddhesh.in From: Sanimir Agovic This patch enables the sizeof operator for indirections: 1| void foo (size_t n) { 2| int vla[n]; 3| int *vla_ptr = &vla; 4| } (gdb) p sizeof(*vla_ptr) yields sizeof (size_t) * n. gdb/ChangeLog: * eval.c (evaluate_subexp_for_sizeof) : Create an indirect value and retrieve the dynamic type size. --- gdb/ChangeLog | 5 +++++ gdb/eval.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1755609..c7efe62 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2014-04-14 Sanimir Agovic + * eval.c (evaluate_subexp_for_sizeof) : Create an indirect + value and retrieve the dynamic type size. + +2014-04-14 Sanimir Agovic + * eval.c (evaluate_subexp_for_sizeof) : If the type passed to sizeof is dynamic evaluate the argument to compute the length. diff --git a/gdb/eval.c b/gdb/eval.c index 85523cd..22392eb 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3026,7 +3026,9 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos) && TYPE_CODE (type) != TYPE_CODE_ARRAY) error (_("Attempt to take contents of a non-pointer value.")); type = TYPE_TARGET_TYPE (type); - break; + if (is_dynamic_type (type)) + type = value_type (value_ind (val)); + return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type)); case UNOP_MEMVAL: (*pos) += 3;