From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mFN7EdWY71/aTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:49:09 -0500 Received: by simark.ca (Postfix, from userid 112) id 40F601F0C2; Fri, 1 Jan 2021 16:49:09 -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 753891F0BC for ; Fri, 1 Jan 2021 16:49:04 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A03F3896C20; Fri, 1 Jan 2021 21:48:41 +0000 (GMT) Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.130]) by sourceware.org (Postfix) with ESMTPS id 1CC3F3896C18 for ; Fri, 1 Jan 2021 21:48:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1CC3F3896C18 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 cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway33.websitewelcome.com (Postfix) with ESMTP id B2BED10BE636 for ; Fri, 1 Jan 2021 15:48:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHika1iInPrxvSHikle9c; Fri, 01 Jan 2021 15:48:34 -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=b63yTs4ixuV3exJkxz0D/3GApxPQIbtQfRQyNE4SXmo=; b=rPMV4SwQvHRlX5NzV8UVoc4I5+ TmVKNE+MXxqqiSTFela8zDFZ/WV9l/+V+aoNmmCh/kDsyYoI+RhhHaBEMpHsZPNA2i1wIKP3t1psh crHBDalwEpPiX1EKpT5sLTTtF; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60414 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 1kvSHi-0029lU-H6 for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:34 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 143/203] Implement Rust funcall operation Date: Fri, 1 Jan 2021 14:46:23 -0700 Message-Id: <20210101214723.1784144-144-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: 1kvSHi-0029lU-H6 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60414 X-Source-Auth: tom+tromey.com X-Email-Count: 144 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 the special code needed to handle the Rust function call operation. gdb/ChangeLog 2021-01-01 Tom Tromey * rust-lang.c (rust_structop::evaluate_funcall): New method. * rust-exp.h (class rust_structop) : Declare method. --- gdb/ChangeLog | 6 ++++++ gdb/rust-exp.h | 5 +++++ gdb/rust-lang.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/gdb/rust-exp.h b/gdb/rust-exp.h index 6e529f8e600..1019922fe8a 100644 --- a/gdb/rust-exp.h +++ b/gdb/rust-exp.h @@ -203,6 +203,11 @@ class rust_structop std::get<1> (m_storage).c_str ()); } + value *evaluate_funcall (struct type *expect_type, + struct expression *exp, + enum noside noside, + const std::vector &args) override; + enum exp_opcode opcode () const override { return STRUCTOP_STRUCT; } }; diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 992319ffd2b..7605b64b384 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1756,6 +1756,56 @@ rust_aggregate_operation::evaluate (struct type *expect_type, return result; } +value * +rust_structop::evaluate_funcall (struct type *expect_type, + struct expression *exp, + enum noside noside, + const std::vector &ops) +{ + std::vector args (ops.size () + 1); + + /* Evaluate the argument to STRUCTOP_STRUCT, then find its + type in order to look up the method. */ + args[0] = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + /* We don't yet implement real Deref semantics. */ + while (value_type (args[0])->code () == TYPE_CODE_PTR) + args[0] = value_ind (args[0]); + + struct type *type = value_type (args[0]); + if ((type->code () != TYPE_CODE_STRUCT + && type->code () != TYPE_CODE_UNION + && type->code () != TYPE_CODE_ENUM) + || rust_tuple_type_p (type)) + error (_("Method calls only supported on struct or enum types")); + if (type->name () == NULL) + error (_("Method call on nameless type")); + + std::string name = (std::string (type->name ()) + "::" + + std::get<1> (m_storage)); + + const struct block *block = get_selected_block (0); + struct block_symbol sym = lookup_symbol (name.c_str (), block, + VAR_DOMAIN, NULL); + if (sym.symbol == NULL) + error (_("Could not find function named '%s'"), name.c_str ()); + + struct type *fn_type = SYMBOL_TYPE (sym.symbol); + if (fn_type->num_fields () == 0) + error (_("Function '%s' takes no arguments"), name.c_str ()); + + if (fn_type->field (0).type ()->code () == TYPE_CODE_PTR) + args[0] = value_addr (args[0]); + + value *function = address_of_variable (sym.symbol, block); + + for (int i = 0; i < ops.size (); ++i) + args[i + 1] = ops[i]->evaluate (nullptr, exp, noside); + + if (noside == EVAL_AVOID_SIDE_EFFECTS) + return value_zero (TYPE_TARGET_TYPE (fn_type), not_lval); + return call_function_by_hand (function, NULL, args); +} + } /* operator_length implementation for Rust. */ -- 2.26.2