From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iFFZJ6aY71/aTQAAWB0awg (envelope-from ) for ; Fri, 01 Jan 2021 16:48:22 -0500 Received: by simark.ca (Postfix, from userid 112) id E23E11F0BA; Fri, 1 Jan 2021 16:48:19 -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, RCVD_IN_BL_SPAMCOP_NET,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no 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 E0CEF1F0B7 for ; Fri, 1 Jan 2021 16:48:18 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB7DE38930D3; Fri, 1 Jan 2021 21:48:06 +0000 (GMT) Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.46.187]) by sourceware.org (Postfix) with ESMTPS id EA3CE3892453 for ; Fri, 1 Jan 2021 21:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EA3CE3892453 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 cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 8CFE53F24 for ; Fri, 1 Jan 2021 15:48:01 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHBkXAkCHPnUvSHBkgzTQ; Fri, 01 Jan 2021 15:48:01 -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=WD+bouWWvexaTzSQ3q5RJsjyPAqgyvl+LF/1A54ChK4=; b=EeKcBYqp550QsHOZaJ+b4RNIDp 3Diw+mTwypCbs1RpMDpMWEXMbj0zTivq33SN9kXQpT//hCQSSudlC8wBL8v9KxjJN4/nS6DTErDQh 9YL4c332v2wPDH9kyoivkpTGa; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:60390 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 1kvSHB-0029Mc-C6 for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:01 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 079/203] Introduce var_msym_value_operation Date: Fri, 1 Jan 2021 14:45:19 -0700 Message-Id: <20210101214723.1784144-80-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: 1kvSHB-0029Mc-C6 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:60390 X-Source-Auth: tom+tromey.com X-Email-Count: 80 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 var_msym_value_operation, which implements OP_VAR_MSYM_VALUE. gdb/ChangeLog 2021-01-01 Tom Tromey * expop.h (class var_msym_value_operation): New. * eval.c (eval_op_var_msym_value): No longer static. (var_msym_value_operation::evaluate_for_address) (var_msym_value_operation::evaluate_for_sizeof) (var_msym_value_operation::evaluate_for_cast): New methods. * ax-gdb.c (var_msym_value_operation::do_generate_ax): New method. --- gdb/ChangeLog | 10 ++++++++ gdb/ax-gdb.c | 17 +++++++++++++ gdb/eval.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++- gdb/expop.h | 43 ++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 7640b1ba925..60281700703 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2324,6 +2324,23 @@ long_const_operation::do_generate_ax (struct expression *exp, std::get<0> (m_storage)); } +void +var_msym_value_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + gen_msym_var_ref (ax, value, std::get<0> (m_storage), + std::get<1> (m_storage)); + + if (value->type->code () == TYPE_CODE_ERROR) + { + if (cast_type == nullptr) + error_unknown_type (std::get<0> (m_storage)->linkage_name ()); + value->type = cast_type; + } +} + } /* This handles the middle-to-right-side of code generation for binary diff --git a/gdb/eval.c b/gdb/eval.c index fe8698342db..38bbb3519ba 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1216,7 +1216,7 @@ eval_op_var_entry_value (struct type *expect_type, struct expression *exp, return SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry (sym, frame); } -static struct value * +struct value * eval_op_var_msym_value (struct type *expect_type, struct expression *exp, enum noside noside, minimal_symbol *msymbol, struct objfile *objfile) @@ -3276,6 +3276,22 @@ scope_operation::evaluate_for_address (struct expression *exp, return x; } +value * +var_msym_value_operation::evaluate_for_address (struct expression *exp, + enum noside noside) +{ + value *val = evaluate_var_msym_value (noside, + std::get<1> (m_storage), + std::get<0> (m_storage)); + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + struct type *type = lookup_pointer_type (value_type (val)); + return value_zero (type, not_lval); + } + else + return value_addr (val); +} + } /* Evaluate like `evaluate_subexp' except coercing arrays to pointers. @@ -3476,6 +3492,25 @@ operation::evaluate_for_sizeof (struct expression *exp, enum noside noside) return evaluate_subexp_for_sizeof_base (exp, value_type (val)); } +value * +var_msym_value_operation::evaluate_for_sizeof (struct expression *exp, + enum noside noside) + +{ + minimal_symbol *msymbol = std::get<0> (m_storage); + value *mval = evaluate_var_msym_value (noside, + std::get<1> (m_storage), + msymbol); + + struct type *type = value_type (mval); + if (type->code () == TYPE_CODE_ERROR) + error_unknown_type (msymbol->print_name ()); + + /* FIXME: This should be size_t. */ + struct type *size_type = builtin_type (exp->gdbarch)->builtin_int; + return value_from_longest (size_type, TYPE_LENGTH (type)); +} + } /* Evaluate a subexpression of EXP, at index *POS, and return a value @@ -3533,6 +3568,38 @@ evaluate_subexp_for_cast (expression *exp, int *pos, return value_cast (to_type, val); } +namespace expr +{ + +value * +var_msym_value_operation::evaluate_for_cast (struct type *to_type, + struct expression *exp, + enum noside noside) +{ + if (noside == EVAL_AVOID_SIDE_EFFECTS) + return value_zero (to_type, not_lval); + + value *val = evaluate_var_msym_value (noside, + std::get<1> (m_storage), + std::get<0> (m_storage)); + + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + + val = value_cast (to_type, val); + + /* Don't allow e.g. '&(int)var_with_no_debug_info'. */ + if (VALUE_LVAL (val) == lval_memory) + { + if (value_lazy (val)) + value_fetch_lazy (val); + VALUE_LVAL (val) = not_lval; + } + return val; +} + +} + /* Parse a type expression in the string [P..P+LENGTH). */ struct type * diff --git a/gdb/expop.h b/gdb/expop.h index ede075b44d8..caa4d329fef 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -45,6 +45,11 @@ extern struct value *eval_op_scope (struct type *expect_type, struct expression *exp, enum noside noside, struct type *type, const char *string); +extern struct value *eval_op_var_msym_value (struct type *expect_type, + struct expression *exp, + enum noside noside, + minimal_symbol *msymbol, + struct objfile *objfile); namespace expr { @@ -479,6 +484,44 @@ class long_const_operation override; }; +class var_msym_value_operation + : public maybe_constant_operation +{ +public: + + using maybe_constant_operation::maybe_constant_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + return eval_op_var_msym_value (expect_type, exp, noside, + std::get<0> (m_storage), + std::get<1> (m_storage)); + } + + value *evaluate_for_sizeof (struct expression *exp, enum noside noside) + override; + + value *evaluate_for_address (struct expression *exp, enum noside noside) + override; + + value *evaluate_for_cast (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + enum exp_opcode opcode () const override + { return OP_VAR_MSYM_VALUE; } + +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