From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gMtKD8SY71/2TAAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:48:52 -0500 Received: by simark.ca (Postfix, from userid 112) id 5F5901F0BC; Fri, 1 Jan 2021 16:48:51 -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 17A8F1F071 for ; Fri, 1 Jan 2021 16:48:50 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F189389680C; Fri, 1 Jan 2021 21:48:27 +0000 (GMT) Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.47]) by sourceware.org (Postfix) with ESMTPS id 44A0F3894C36 for ; Fri, 1 Jan 2021 21:48:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 44A0F3894C36 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 gateway31.websitewelcome.com (Postfix) with ESMTP id DB2583185C for ; Fri, 1 Jan 2021 15:48:23 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHXkJAapuDoAvSHXkccWF; Fri, 01 Jan 2021 15:48:23 -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=LQ/Ej3B1v+wuvua/Y3JfthYwaJd65p2ydLwL+YuuE1A=; b=KC7G1NxRFSZzI3P/rOusqIYypz Oy2VlG4vGw98ERMGAEKn69X9rBXJaMmWrdqELABKPnOr7atLrk0WQdNTtacv2RI2BYX2OWUSFvn6O hZNxYCNKq60MW9abFGxdD+hwZ; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60410 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 1kvSHX-0029f3-NA for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:23 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 117/203] Introduce assign_operation Date: Fri, 1 Jan 2021 14:45:57 -0700 Message-Id: <20210101214723.1784144-118-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: 1kvSHX-0029f3-NA X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60410 X-Source-Auth: tom+tromey.com X-Email-Count: 118 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 assign_operation, which implements BINOP_ASSIGN. gdb/ChangeLog 2021-01-01 Tom Tromey * expop.h (class assign_operation): New. * ax-gdb.c (assign_operation::do_generate_ax): New method. --- gdb/ChangeLog | 5 +++++ gdb/ax-gdb.c | 30 ++++++++++++++++++++++++++++++ gdb/expop.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 98edc6c0727..d8b5ed78a40 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2579,6 +2579,36 @@ op_this_operation::do_generate_ax (struct expression *exp, sym->print_name ()); } +void +assign_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + operation *subop = std::get<0> (m_storage).get (); + if (subop->opcode () != OP_INTERNALVAR) + error (_("May only assign to trace state variables")); + + internalvar_operation *ivarop + = dynamic_cast (subop); + gdb_assert (ivarop != nullptr); + + const char *name = internalvar_name (ivarop->get_internalvar ()); + struct trace_state_variable *tsv; + + std::get<1> (m_storage)->generate_ax (exp, ax, value); + tsv = find_trace_state_variable (name); + if (tsv) + { + ax_tsv (ax, aop_setv, tsv->number); + if (ax->tracing) + ax_tsv (ax, aop_tracev, tsv->number); + } + else + error (_("$%s is not a trace state variable, " + "may not assign to it"), name); +} + } /* This handles the middle-to-right-side of code generation for binary diff --git a/gdb/expop.h b/gdb/expop.h index e172e11a828..5acbca3db61 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -1746,6 +1746,49 @@ class type_instance_operation { return TYPE_INSTANCE; } }; +/* The assignment operator. */ +class assign_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 + { + value *lhs = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + /* Special-case assignments where the left-hand-side is a + convenience variable -- in these, don't bother setting an + expected type. This avoids a weird case where re-assigning a + string or array to an internal variable could error with "Too + many array elements". */ + struct type *xtype = (VALUE_LVAL (lhs) == lval_internalvar + ? nullptr + : value_type (lhs)); + value *rhs = std::get<1> (m_storage)->evaluate (xtype, exp, noside); + + if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) + return lhs; + if (binop_user_defined_p (BINOP_ASSIGN, lhs, rhs)) + return value_x_binop (lhs, rhs, BINOP_ASSIGN, OP_NULL, noside); + else + return value_assign (lhs, rhs); + } + + enum exp_opcode opcode () const override + { return BINOP_ASSIGN; } + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; +}; + } /* namespace expr */ #endif /* EXPOP_H */ -- 2.26.2