From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@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 17:13:00 -0000 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-SW-Source: 2014-04/txt/msg00261.txt.bz2 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: -- 1.8.3.2