From patchwork Mon Mar 17 15:51:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 122 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx22.g.dreamhost.com (caibbdcaabij.dreamhost.com [208.113.200.189]) by wilcox.dreamhost.com (Postfix) with ESMTP id DE14E3600D3 for ; Mon, 17 Mar 2014 08:51:27 -0700 (PDT) Received: by homiemail-mx22.g.dreamhost.com (Postfix, from userid 14314964) id 9E1B75000280; Mon, 17 Mar 2014 08:51:27 -0700 (PDT) X-Original-To: gdb@patchwork.siddhesh.in Delivered-To: x14314964@homiemail-mx22.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-mx22.g.dreamhost.com (Postfix) with ESMTPS id 70750500022C for ; Mon, 17 Mar 2014 08:51:27 -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=FQVuHhhUAAzg/7PzGXy0Fej2qdgvQFB S8co8xNqougVodiPrGtl5DIT8bWDh6xm94kCdO222imBKCufiU6Zdxcet41CmtXY ixeG8DI8mSkNTsHa6jdBMBEXjREEWleeM++OJtCuFswZEKcvJZyatOdG0BFCkrXR nCLYsRk/M07c= 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=1SF1QWuUSz2klYpf6RGeV6dOcLY=; b=lRUUd Yu6Qj7NAS21gZocuwNIjlJTV/HkYToREDq+K7XKQgiR5Gv6gNgaKjeXPydP6nIiE /tJxAXtrlfVQXcolreEGkiSFTNTJDTkJjcpq4DBSFFprOCaDEkjUIYkQVMS/7g2t P9GYsV2RuhQX+iUAJOBCAzACwMqIFa6mJfFPuQ= Received: (qmail 3809 invoked by alias); 17 Mar 2014 15:51:24 -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 3657 invoked by uid 89); 17 Mar 2014 15:51:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD 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, 17 Mar 2014 15:51:22 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9C4A8116576; Mon, 17 Mar 2014 11:51:19 -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 QOE9uosyddyh; Mon, 17 Mar 2014 11:51:19 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 692041164E2; Mon, 17 Mar 2014 11:51:19 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id E0A89E0966; Mon, 17 Mar 2014 08:51:18 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Pierre-Marie de Rodat Subject: pushed: [Ada 1/2] Crash with references to GNAT packed arrays handling Date: Mon, 17 Mar 2014 08:51:11 -0700 Message-Id: <1395071472-25068-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1395071472-25068-1-git-send-email-brobecker@adacore.com> References: <1395071472-25068-1-git-send-email-brobecker@adacore.com> X-DH-Original-To: gdb@patchwork.siddhesh.in From: Pierre-Marie de Rodat Consider the following declarations: type Packed_Array is array (Natural range <>) of Boolean; pragma Pack (Packed_Array); function Make (H, L : Natural) return Packed_Array is begin return (H .. L => False); end Make; A1 : Packed_Array := Make (1, 2); A2 : Packed_Array renames A1; One possible DWARF translation for A2 is: <3><1e4>: Abbrev Number: 21 (DW_TAG_variable) <1e5> DW_AT_name : a2 <1ea> DW_AT_type : <0x1d9> <3><1d9>: Abbrev Number: 22 (DW_TAG_const_type) <1da> DW_AT_type : <0x1de> <3><1de>: Abbrev Number: 23 (DW_TAG_reference_type) <1e0> DW_AT_type : <0x1a3> <3><1a3>: Abbrev Number: 17 (DW_TAG_array_type) <1a4> DW_AT_name : foo__Ta1S___XP1 <1a8> DW_AT_GNAT_descriptive_type: <0x16b> <3><16b>: Abbrev Number: 6 (DW_TAG_typedef) <16c> DW_AT_name : foo__Ta1S <172> DW_AT_type : <0x176> <3><176>: Abbrev Number: 17 (DW_TAG_array_type) <177> DW_AT_name : foo__Ta1S <17b> DW_AT_GNAT_descriptive_type: <0x223> Here, foo__Ta1S___XP1 is the type used for the code generation while foo__Ta1S is the source-level type. Both form a valid GNAT encoding for a packed array type. Trying to print A2 (1) can make GDB crash. This is because A2 is defined as a reference to a GNAT encoding for a packed array. When decoding constrained packed arrays, the ada_coerce_ref subprogram follows references and returns a fixed type from the target type, peeling the GNAT encoding for packed arrays. The remaining code assumes that the resulting type is still such an encoding while we only have a standard GDB array type, hence the crash: arr = ada_coerce_ref (arr); [...] type = decode_constrained_packed_array_type (value_type (arr)); decode_constrained_packed_array_type assumes that its argument is such an encoding. From its front comment: /* The array type encoded by TYPE, where ada_is_constrained_packed_array_type (TYPE). */ This patch simply replaces the call to ada_coerce_ref with a call to coerce_ref in order to avoid prematurely transforming the packed array type as a side-effect. This way, the remaining code will always work with a GNAT encoding. gdb/ChangeLog: * ada-lang.c (decode_constrained_packed_array): Perform a minimal coercion for reference with coerce_ref instead of ada_coerce_ref. Tested on x86_64-linux. Pushed. --- gdb/ChangeLog | 6 ++++++ gdb/ada-lang.c | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5b659d2..4e62f0c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2014-03-17 Pierre-Marie de Rodat + + * ada-lang.c (decode_constrained_packed_array): Perform a + minimal coercion for reference with coerce_ref instead of + ada_coerce_ref. + 2014-03-17 Tristan Gingold * solib-darwin.c (DYLD_VERSION_MAX): Increase value. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 31aa380..38df182 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2250,14 +2250,14 @@ decode_constrained_packed_array (struct value *arr) { struct type *type; - arr = ada_coerce_ref (arr); - - /* If our value is a pointer, then dererence it. Make sure that - this operation does not cause the target type to be fixed, as - this would indirectly cause this array to be decoded. The rest - of the routine assumes that the array hasn't been decoded yet, - so we use the basic "value_ind" routine to perform the dereferencing, - as opposed to using "ada_value_ind". */ + /* If our value is a pointer, then dereference it. Likewise if + the value is a reference. Make sure that this operation does not + cause the target type to be fixed, as this would indirectly cause + this array to be decoded. The rest of the routine assumes that + the array hasn't been decoded yet, so we use the basic "coerce_ref" + and "value_ind" routines to perform the dereferencing, as opposed + to using "ada_coerce_ref" or "ada_value_ind". */ + arr = coerce_ref (arr); if (TYPE_CODE (ada_check_typedef (value_type (arr))) == TYPE_CODE_PTR) arr = value_ind (arr);