From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kE6gIeiY718XTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:28 -0500 Received: by simark.ca (Postfix, from userid 112) id 04A411F0BA; 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.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RDNS_NONE,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 7C0E81E590 for ; Fri, 1 Jan 2021 16:49:26 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 573083938C18; Fri, 1 Jan 2021 21:48:53 +0000 (GMT) Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.152.11]) by sourceware.org (Postfix) with ESMTPS id 106B73899434 for ; Fri, 1 Jan 2021 21:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 106B73899434 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 A707426AE for ; Fri, 1 Jan 2021 15:48:48 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHwkJAqNuDoAvSHwkcclZ; 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=panXcODonQ/FBNVOBclQOeFh2fWxflQLUYpvM5kVOj4=; b=OdpRdB+EprqhGO9WdJWlNCUW1n 1SeACHSWNfY8ifI9JSBEaTqYYxf21C3ojegBsaZ69nO7eEINzKICjgZMjGB3Kr3ZzKC41b8Y3mUvv KsOuhDrzdB709kxiNIMJJjhqK; 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 1kvSHw-0029t6-Do for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:48 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 168/203] Implement function calls for Ada Date: Fri, 1 Jan 2021 14:46:48 -0700 Message-Id: <20210101214723.1784144-169-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: 1kvSHw-0029t6-Do 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: 169 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 implements function calls for Ada. This takes a different approach than that used for other languages, primarily because Ada requires special treatment generally. The "ordinary" special case for just the callee didn't really apply neatly here; there's only one case in Ada needing special callee treatment. gdb/ChangeLog 2021-01-01 Tom Tromey * ada-lang.c (ada_funcall_operation::evaluate): New method. * ada-exp.h (class ada_var_msym_value_operation) : New method. (class ada_funcall_operation): New. --- gdb/ChangeLog | 7 +++ gdb/ada-exp.h | 19 +++++++ gdb/ada-lang.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index 34b9c1d166d..287ed5cc62c 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -320,6 +320,9 @@ class ada_var_value_operation struct expression *exp, enum noside noside) override; + symbol *get_symbol () const + { return std::get<0> (m_storage); } + protected: using operation::do_generate_ax; @@ -387,6 +390,22 @@ class ada_structop_operation { return STRUCTOP_STRUCT; } }; +/* Function calls for Ada. */ +class ada_funcall_operation + : public tuple_holding_operation> +{ +public: + + using tuple_holding_operation::tuple_holding_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + enum exp_opcode opcode () const override + { return OP_FUNCALL; } +}; + } /* namespace expr */ #endif /* ADA_EXP_H */ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c197afe7052..18f250b5a34 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10972,6 +10972,148 @@ ada_structop_operation::evaluate (struct type *expect_type, } } +value * +ada_funcall_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + const std::vector &args_up = std::get<1> (m_storage); + int nargs = args_up.size (); + std::vector argvec (nargs); + operation_up &callee_op = std::get<0> (m_storage); + + ada_var_value_operation *avv + = dynamic_cast (callee_op.get ()); + if (avv != nullptr + && SYMBOL_DOMAIN (avv->get_symbol ()) == UNDEF_DOMAIN) + error (_("Unexpected unresolved symbol, %s, during evaluation"), + avv->get_symbol ()->print_name ()); + + value *callee = callee_op->evaluate (nullptr, exp, noside); + for (int i = 0; i < args_up.size (); ++i) + argvec[i] = args_up[i]->evaluate (nullptr, exp, noside); + + if (ada_is_constrained_packed_array_type + (desc_base_type (value_type (callee)))) + callee = ada_coerce_to_simple_array (callee); + else if (value_type (callee)->code () == TYPE_CODE_ARRAY + && TYPE_FIELD_BITSIZE (value_type (callee), 0) != 0) + /* This is a packed array that has already been fixed, and + therefore already coerced to a simple array. Nothing further + to do. */ + ; + else if (value_type (callee)->code () == TYPE_CODE_REF) + { + /* Make sure we dereference references so that all the code below + feels like it's really handling the referenced value. Wrapping + types (for alignment) may be there, so make sure we strip them as + well. */ + callee = ada_to_fixed_value (coerce_ref (callee)); + } + else if (value_type (callee)->code () == TYPE_CODE_ARRAY + && VALUE_LVAL (callee) == lval_memory) + callee = value_addr (callee); + + struct type *type = ada_check_typedef (value_type (callee)); + + /* Ada allows us to implicitly dereference arrays when subscripting + them. So, if this is an array typedef (encoding use for array + access types encoded as fat pointers), strip it now. */ + if (type->code () == TYPE_CODE_TYPEDEF) + type = ada_typedef_target_type (type); + + if (type->code () == TYPE_CODE_PTR) + { + switch (ada_check_typedef (TYPE_TARGET_TYPE (type))->code ()) + { + case TYPE_CODE_FUNC: + type = ada_check_typedef (TYPE_TARGET_TYPE (type)); + break; + case TYPE_CODE_ARRAY: + break; + case TYPE_CODE_STRUCT: + if (noside != EVAL_AVOID_SIDE_EFFECTS) + callee = ada_value_ind (callee); + type = ada_check_typedef (TYPE_TARGET_TYPE (type)); + break; + default: + error (_("cannot subscript or call something of type `%s'"), + ada_type_name (value_type (callee))); + break; + } + } + + switch (type->code ()) + { + case TYPE_CODE_FUNC: + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + if (TYPE_TARGET_TYPE (type) == NULL) + error_call_unknown_return_type (NULL); + return allocate_value (TYPE_TARGET_TYPE (type)); + } + return call_function_by_hand (callee, NULL, argvec); + case TYPE_CODE_INTERNAL_FUNCTION: + if (noside == EVAL_AVOID_SIDE_EFFECTS) + /* We don't know anything about what the internal + function might return, but we have to return + something. */ + return value_zero (builtin_type (exp->gdbarch)->builtin_int, + not_lval); + else + return call_internal_function (exp->gdbarch, exp->language_defn, + callee, nargs, + argvec.data ()); + + case TYPE_CODE_STRUCT: + { + int arity; + + arity = ada_array_arity (type); + type = ada_array_element_type (type, nargs); + if (type == NULL) + error (_("cannot subscript or call a record")); + if (arity != nargs) + error (_("wrong number of subscripts; expecting %d"), arity); + if (noside == EVAL_AVOID_SIDE_EFFECTS) + return value_zero (ada_aligned_type (type), lval_memory); + return + unwrap_value (ada_value_subscript + (callee, nargs, argvec.data ())); + } + case TYPE_CODE_ARRAY: + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + type = ada_array_element_type (type, nargs); + if (type == NULL) + error (_("element type of array unknown")); + else + return value_zero (ada_aligned_type (type), lval_memory); + } + return + unwrap_value (ada_value_subscript + (ada_coerce_to_simple_array (callee), + nargs, argvec.data ())); + case TYPE_CODE_PTR: /* Pointer to array */ + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1); + type = ada_array_element_type (type, nargs); + if (type == NULL) + error (_("element type of array unknown")); + else + return value_zero (ada_aligned_type (type), lval_memory); + } + return + unwrap_value (ada_value_ptr_subscript (callee, nargs, + argvec.data ())); + + default: + error (_("Attempt to index or call something other than an " + "array or function")); + } +} + } /* Implement the evaluate_exp routine in the exp_descriptor structure -- 2.26.2