From patchwork Mon Apr 14 17:13:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 538 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 84B11360075 for ; Mon, 14 Apr 2014 10:13:32 -0700 (PDT) Received: by homiemail-mx21.g.dreamhost.com (Postfix, from userid 14314964) id 3D67B135325C; Mon, 14 Apr 2014 10:13:32 -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 10E941352B84 for ; Mon, 14 Apr 2014 10:13:32 -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=XBXcxIQSP2BUIJholSm2ryvWaYmbMuq 0DcCefwja4DkHucFEoY7Df3h0kXcflCZtBpiSsYi67VQ3QmocUDOjZo5NGoQMuNP b0mL3wrO0dcqcVeU8c/w8uU1/Xnz3PdNYAyfelbvxgfE5Uav0w3npaHWUcfPIrbU aKatE/VBVxfI= 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=GNs73sM+YxqR1JXuhNARdS90sdE=; b=VLh9I B9408mc6QYfNOZrxpjqrTHEa8lWxWIiBfiA+0f1BvRTSvgapZTKFMQqOQ0w+dtie 0i89aAjk/hIm/Wj4GRVhsgqAWNKiLLc+Hyh5xaA5LW0ECPpB9bFbUH/cfmImiaQ/ wVvkWKsQcv9WpbZxCfZOTfLxkU9k2VJkeazhBI= Received: (qmail 6379 invoked by alias); 14 Apr 2014 17:13:26 -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 6253 invoked by uid 89); 14 Apr 2014 17:13:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RP_MATCHES_RCVD, SPF_PASS autolearn=no 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:24 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1A0DE116132; Mon, 14 Apr 2014 13:13:21 -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 vGdKrbfCLixx; Mon, 14 Apr 2014 13:13:21 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id D8ABB1160DB; Mon, 14 Apr 2014 13:13:20 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 733C7E02C0; Mon, 14 Apr 2014 10:13:26 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Sanimir Agovic Subject: [PATCH 02/12] vla: enable sizeof operator to work with variable length arrays Date: Mon, 14 Apr 2014 10:13:06 -0700 Message-Id: <1397495596-25364-3-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 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). gdb/ChangeLog: * eval.c (evaluate_subexp_for_sizeof) : If the type passed to sizeof is dynamic evaluate the argument to compute the length. --- gdb/ChangeLog | 5 +++++ gdb/eval.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cf9a35d..1755609 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,4 +1,9 @@ 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. + +2014-04-14 Sanimir Agovic Joel Brobecker * dwarf2loc.c (dwarf2_locexpr_baton_eval): New function. diff --git a/gdb/eval.c b/gdb/eval.c index c1e47e0..85523cd 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -3040,8 +3040,14 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos) break; case OP_VAR_VALUE: - (*pos) += 4; type = 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; break; default: