From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SLMFJ+yY718XTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:32 -0500 Received: by simark.ca (Postfix, from userid 112) id 74EAA1F0C2; Fri, 1 Jan 2021 16:49:30 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D92331F0B7 for ; Fri, 1 Jan 2021 16:49:25 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B3E4B3938C0E; Fri, 1 Jan 2021 21:48:52 +0000 (GMT) Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.152.11]) by sourceware.org (Postfix) with ESMTPS id 7385538A4475 for ; Fri, 1 Jan 2021 21:48:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7385538A4475 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 15B79171B for ; Fri, 1 Jan 2021 15:48:48 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHwkJApyuDoAvSHwkcclB; Fri, 01 Jan 2021 15:48:48 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ya4Dy/s8T5+42SFF5im/svucOlJwg6aRAcHs1jC94Ro=; b=jawHYC7m6CMkk0eJkO0ywQ9nBX OxdMAaTv3STJExyunM5jVkUnpWpXZRKcU+/thBVg6MtaIPdWDw1+8YIhWvBrVMQk03vFuBzMM34Ad OSWb3ynTMEuKmKJOjtIPVa0uo; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60422 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kvSHv-0029t6-R5 for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:47 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 166/203] Introduce ada_unop_ind_operation Date: Fri, 1 Jan 2021 14:46:46 -0700 Message-Id: <20210101214723.1784144-167-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210101214723.1784144-1-tom@tromey.com> References: <20210101214723.1784144-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.39 X-Source-L: No X-Exim-ID: 1kvSHv-0029t6-R5 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60422 X-Source-Auth: tom+tromey.com X-Email-Count: 167 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This adds class ada_unop_ind_operation, which implements UNOP_IND for Ada. gdb/ChangeLog 2021-01-01 Tom Tromey * ada-lang.c (ada_unop_ind_operation::evaluate): New method. * ada-exp.h (class ada_unop_ind_operation): New. --- gdb/ChangeLog | 5 +++ gdb/ada-exp.h | 13 ++++++++ gdb/ada-lang.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index 8e908464f1f..c87036e2d19 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -358,6 +358,19 @@ class ada_atr_val_operation { return OP_ATR_VAL; } }; +/* The indirection operator for Ada. */ +class ada_unop_ind_operation + : public unop_ind_base_operation +{ +public: + + using unop_ind_base_operation::unop_ind_base_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override; +}; + } /* namespace expr */ #endif /* ADA_EXP_H */ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d621e32ab75..6cceecc080a 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10845,6 +10845,91 @@ ada_atr_val_operation::evaluate (struct type *expect_type, return ada_val_atr (noside, std::get<0> (m_storage), arg); } +value * +ada_unop_ind_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + value *arg1 = std::get<0> (m_storage)->evaluate (expect_type, exp, noside); + + struct type *type = ada_check_typedef (value_type (arg1)); + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + if (ada_is_array_descriptor_type (type)) + /* GDB allows dereferencing GNAT array descriptors. */ + { + struct type *arrType = ada_type_of_array (arg1, 0); + + if (arrType == NULL) + error (_("Attempt to dereference null array pointer.")); + return value_at_lazy (arrType, 0); + } + else if (type->code () == TYPE_CODE_PTR + || type->code () == TYPE_CODE_REF + /* In C you can dereference an array to get the 1st elt. */ + || type->code () == TYPE_CODE_ARRAY) + { + /* As mentioned in the OP_VAR_VALUE case, tagged types can + only be determined by inspecting the object's tag. + This means that we need to evaluate completely the + expression in order to get its type. */ + + if ((type->code () == TYPE_CODE_REF + || type->code () == TYPE_CODE_PTR) + && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0)) + { + arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_NORMAL); + type = value_type (ada_value_ind (arg1)); + } + else + { + type = to_static_fixed_type + (ada_aligned_type + (ada_check_typedef (TYPE_TARGET_TYPE (type)))); + } + ada_ensure_varsize_limit (type); + return value_zero (type, lval_memory); + } + else if (type->code () == TYPE_CODE_INT) + { + /* GDB allows dereferencing an int. */ + if (expect_type == NULL) + return value_zero (builtin_type (exp->gdbarch)->builtin_int, + lval_memory); + else + { + expect_type = + to_static_fixed_type (ada_aligned_type (expect_type)); + return value_zero (expect_type, lval_memory); + } + } + else + error (_("Attempt to take contents of a non-pointer value.")); + } + arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */ + type = ada_check_typedef (value_type (arg1)); + + if (type->code () == TYPE_CODE_INT) + /* GDB allows dereferencing an int. If we were given + the expect_type, then use that as the target type. + Otherwise, assume that the target type is an int. */ + { + if (expect_type != NULL) + return ada_value_ind (value_cast (lookup_pointer_type (expect_type), + arg1)); + else + return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int, + (CORE_ADDR) value_as_address (arg1)); + } + + if (ada_is_array_descriptor_type (type)) + /* GDB allows dereferencing GNAT array descriptors. */ + return ada_coerce_to_simple_array (arg1); + else + return ada_value_ind (arg1); +} + } /* Implement the evaluate_exp routine in the exp_descriptor structure -- 2.26.2