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