From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YOznEeuY71/aTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:31 -0500 Received: by simark.ca (Postfix, from userid 112) id 03F6B1F0AA; Fri, 1 Jan 2021 16:49:27 -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 533611F0AA for ; Fri, 1 Jan 2021 16:49:20 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53BA33938396; Fri, 1 Jan 2021 21:48:49 +0000 (GMT) Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.47]) by sourceware.org (Postfix) with ESMTPS id E361F389851B for ; Fri, 1 Jan 2021 21:48:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E361F389851B 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 cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 860DF3185D for ; Fri, 1 Jan 2021 15:48:43 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHrk11BMiQiZvSHrki8Mc; Fri, 01 Jan 2021 15:48:43 -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=mhmw5lyCdQzkAEh9S7J8ZdIkQg4i2/UvMAcvJLlBy0E=; b=USXOVREGOtw6biptjTfvQXaYUQ K82I9qVYQ8aEfJ6OXJvrBn0mhR6VVcoiMnPbkseqLtP/YK6yGa3/Hg81z4YqiGgwKXahXAlTONX4S y5EtOZn9dFprBgY+zTGTK3oZI; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60418 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 1kvSHr-0029qJ-C2 for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:43 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 159/203] Introduce ada_var_value_operation Date: Fri, 1 Jan 2021 14:46:39 -0700 Message-Id: <20210101214723.1784144-160-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: 1kvSHr-0029qJ-C2 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60418 X-Source-Auth: tom+tromey.com X-Email-Count: 160 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_var_value_operation, which implements OP_VAR_VALUE for Ada. gdb/ChangeLog 2021-01-01 Tom Tromey * ada-lang.c (ada_var_value_operation::evaluate_for_cast) (ada_var_value_operation::evaluate): New methods. * ada-exp.h (class ada_var_value_operation): New. --- gdb/ChangeLog | 6 +++ gdb/ada-exp.h | 21 ++++++++++ gdb/ada-lang.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index e92ae469b63..0f2f62f5978 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -283,6 +283,27 @@ class ada_unop_atr_operation { return std::get<1> (m_storage); } }; +/* Variant of var_value_operation for Ada. */ +class ada_var_value_operation + : public var_value_operation +{ +public: + + using var_value_operation::var_value_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + value *evaluate_for_cast (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + +protected: + + using operation::do_generate_ax; +}; + } /* namespace expr */ #endif /* ADA_EXP_H */ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 9887590a782..bdd574d033c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10695,6 +10695,118 @@ ada_unop_atr_operation::evaluate (struct type *expect_type, val, type_arg, std::get<2> (m_storage)); } +value * +ada_var_value_operation::evaluate_for_cast (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + value *val = evaluate_var_value (noside, + std::get<1> (m_storage), + std::get<0> (m_storage)); + + val = ada_value_cast (expect_type, val); + + /* Follow the Ada language semantics that do not allow taking + an address of the result of a cast (view conversion in Ada). */ + if (VALUE_LVAL (val) == lval_memory) + { + if (value_lazy (val)) + value_fetch_lazy (val); + VALUE_LVAL (val) = not_lval; + } + return val; +} + +value * +ada_var_value_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + symbol *sym = std::get<0> (m_storage); + + if (SYMBOL_DOMAIN (sym) == UNDEF_DOMAIN) + /* Only encountered when an unresolved symbol occurs in a + context other than a function call, in which case, it is + invalid. */ + error (_("Unexpected unresolved symbol, %s, during evaluation"), + sym->print_name ()); + + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + struct type *type = static_unwrap_type (SYMBOL_TYPE (sym)); + /* Check to see if this is a tagged type. We also need to handle + the case where the type is a reference to a tagged type, but + we have to be careful to exclude pointers to tagged types. + The latter should be shown as usual (as a pointer), whereas + a reference should mostly be transparent to the user. */ + if (ada_is_tagged_type (type, 0) + || (type->code () == TYPE_CODE_REF + && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0))) + { + /* Tagged types are a little special in the fact that the real + type is dynamic and can only be determined by inspecting the + object's tag. This means that we need to get the object's + value first (EVAL_NORMAL) and then extract the actual object + type from its tag. + + Note that we cannot skip the final step where we extract + the object type from its tag, because the EVAL_NORMAL phase + results in dynamic components being resolved into fixed ones. + This can cause problems when trying to print the type + description of tagged types whose parent has a dynamic size: + We use the type name of the "_parent" component in order + to print the name of the ancestor type in the type description. + If that component had a dynamic size, the resolution into + a fixed type would result in the loss of that type name, + thus preventing us from printing the name of the ancestor + type in the type description. */ + value *arg1 = var_value_operation::evaluate (nullptr, exp, + EVAL_NORMAL); + + if (type->code () != TYPE_CODE_REF) + { + struct type *actual_type; + + actual_type = type_from_tag (ada_value_tag (arg1)); + if (actual_type == NULL) + /* If, for some reason, we were unable to determine + the actual type from the tag, then use the static + approximation that we just computed as a fallback. + This can happen if the debugging information is + incomplete, for instance. */ + actual_type = type; + return value_zero (actual_type, not_lval); + } + else + { + /* In the case of a ref, ada_coerce_ref takes care + of determining the actual type. But the evaluation + should return a ref as it should be valid to ask + for its address; so rebuild a ref after coerce. */ + arg1 = ada_coerce_ref (arg1); + return value_ref (arg1, TYPE_CODE_REF); + } + } + + /* Records and unions for which GNAT encodings have been + generated need to be statically fixed as well. + Otherwise, non-static fixing produces a type where + all dynamic properties are removed, which prevents "ptype" + from being able to completely describe the type. + For instance, a case statement in a variant record would be + replaced by the relevant components based on the actual + value of the discriminants. */ + if ((type->code () == TYPE_CODE_STRUCT + && dynamic_template_type (type) != NULL) + || (type->code () == TYPE_CODE_UNION + && ada_find_parallel_type (type, "___XVU") != NULL)) + return value_zero (to_static_fixed_type (type), not_lval); + } + + value *arg1 = var_value_operation::evaluate (expect_type, exp, noside); + return ada_to_fixed_value (arg1); +} + } /* Implement the evaluate_exp routine in the exp_descriptor structure -- 2.26.2