From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.47]) by sourceware.org (Postfix) with ESMTPS id 1AA383896802 for ; Fri, 1 Jan 2021 21:48:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1AA383896802 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 BA90A3186A for ; Fri, 1 Jan 2021 15:48:24 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id vSHYkJAbMuDoAvSHYkccWn; Fri, 01 Jan 2021 15:48:24 -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=AAC3ZysLxpWWg5ROplnHAoKvR9aHrRDr4zk6sX3XYXI=; b=Sr9zNw/+b5AjFsqCrB/1bS0TEf qmypZN1A6JYa8de9O5Q0f49m7mFbt4Uoy9rUwpbJQvcZnzcId6pBb4LJMCWJWf9lOgfo3BXIdk6ws oF/V2e6LVSFZsLEf43Qf+4a1e; 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 1kvSHY-0029f3-Iu for gdb-patches@sourceware.org; Fri, 01 Jan 2021 14:48:24 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 122/203] Introduce var_value_operation Date: Fri, 1 Jan 2021 14:46:02 -0700 Message-Id: <20210101214723.1784144-123-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: 1kvSHY-0029f3-Iu 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: 123 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 01 Jan 2021 21:48:27 -0000 This adds class var_value_operation, which implements OP_VAR_VALUE. gdb/ChangeLog 2021-01-01 Tom Tromey * expop.h (class var_value_operation): New. * eval.c (var_value_operation::evaluate) (var_value_operation::evaluate_for_address) (var_value_operation::evaluate_with_coercion) (var_value_operation::evaluate_for_sizeof) (var_value_operation::evaluate_for_cast): New methods. * ax-gdb.c (var_value_operation::do_generate_ax): New method. --- gdb/ChangeLog | 10 +++++ gdb/ax-gdb.c | 20 +++++++++ gdb/eval.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ gdb/expop.h | 45 +++++++++++++++++++++ 4 files changed, 185 insertions(+) diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index e0970e87d68..bdf4a6dc39a 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2673,6 +2673,26 @@ unop_cast_type_operation::do_generate_ax (struct expression *exp, std::get<1> (m_storage)->generate_ax (exp, ax, value, value_type (val)); } +void +var_value_operation::do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + gen_var_ref (ax, value, std::get<0> (m_storage)); + + if (value->optimized_out) + error (_("`%s' has been optimized out, cannot use"), + std::get<0> (m_storage)->print_name ()); + + if (value->type->code () == TYPE_CODE_ERROR) + { + if (cast_type == nullptr) + error_unknown_type (std::get<0> (m_storage)->print_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 51a737ac5a5..4b12875f00c 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -683,6 +683,23 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var) return ret; } +namespace expr + +{ + +value * +var_value_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + symbol *var = std::get<0> (m_storage); + if (SYMBOL_TYPE (var)->code () == TYPE_CODE_ERROR) + error_unknown_type (var->print_name ()); + return evaluate_var_value (noside, std::get<1> (m_storage), var); +} + +} /* namespace expr */ + /* Helper for evaluating an OP_VAR_MSYM_VALUE. */ value * @@ -3392,6 +3409,54 @@ evaluate_subexp_with_coercion (struct expression *exp, } } +namespace expr +{ + +value * +var_value_operation::evaluate_for_address (struct expression *exp, + enum noside noside) +{ + symbol *var = std::get<0> (m_storage); + + /* C++: The "address" of a reference should yield the address + * of the object pointed to. Let value_addr() deal with it. */ + if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var))) + return operation::evaluate_for_address (exp, noside); + + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + struct type *type = lookup_pointer_type (SYMBOL_TYPE (var)); + enum address_class sym_class = SYMBOL_CLASS (var); + + if (sym_class == LOC_CONST + || sym_class == LOC_CONST_BYTES + || sym_class == LOC_REGISTER) + error (_("Attempt to take address of register or constant.")); + + return value_zero (type, not_lval); + } + else + return address_of_variable (var, std::get<1> (m_storage)); +} + +value * +var_value_operation::evaluate_with_coercion (struct expression *exp, + enum noside noside) +{ + struct symbol *var = std::get<0> (m_storage); + struct type *type = check_typedef (SYMBOL_TYPE (var)); + if (type->code () == TYPE_CODE_ARRAY + && !type->is_vector () + && CAST_IS_CONVERSION (exp->language_defn)) + { + struct value *val = address_of_variable (var, std::get<1> (m_storage)); + return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), val); + } + return evaluate (nullptr, exp, noside); +} + +} + /* Helper function for evaluating the size of a type. */ static value * @@ -3632,6 +3697,27 @@ unop_memval_type_operation::evaluate_for_sizeof (struct expression *exp, return evaluate_subexp_for_sizeof_base (exp, value_type (typeval)); } +value * +var_value_operation::evaluate_for_sizeof (struct expression *exp, + enum noside noside) +{ + struct type *type = SYMBOL_TYPE (std::get<0> (m_storage)); + if (is_dynamic_type (type)) + { + value *val = evaluate (nullptr, exp, EVAL_NORMAL); + type = value_type (val); + if (type->code () == TYPE_CODE_ARRAY + && is_dynamic_type (type->index_type ()) + && type->bounds ()->high.kind () == PROP_UNDEFINED) + { + /* FIXME: This should be size_t. */ + struct type *size_type = builtin_type (exp->gdbarch)->builtin_int; + return allocate_optimized_out_value (size_type); + } + } + return evaluate_subexp_for_sizeof_base (exp, type); +} + } /* Evaluate a subexpression of EXP, at index *POS, and return a value @@ -3719,6 +3805,30 @@ var_msym_value_operation::evaluate_for_cast (struct type *to_type, return val; } +value * +var_value_operation::evaluate_for_cast (struct type *to_type, + struct expression *exp, + enum noside noside) +{ + value *val = evaluate_var_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). */ diff --git a/gdb/expop.h b/gdb/expop.h index 53ff93c4b83..0c489c77450 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -606,6 +606,51 @@ class scope_operation override; }; +/* Compute the value of a variable. */ +class var_value_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 *evaluate_with_coercion (struct expression *exp, + enum noside noside) override; + + value *evaluate_for_sizeof (struct expression *exp, enum noside noside) + override; + + value *evaluate_for_cast (struct type *expect_type, + struct expression *exp, + enum noside noside) override; + + value *evaluate_for_address (struct expression *exp, enum noside noside) + override; + + enum exp_opcode opcode () const override + { return OP_VAR_VALUE; } + + bool constant_p () const override + { + symbol *sym = std::get<0> (m_storage); + return (SYMBOL_CLASS (sym) == LOC_CONST + || SYMBOL_CLASS (sym) == LOC_CONST_BYTES + || SYMBOL_CLASS (sym) == LOC_LABEL); + } + +protected: + + void do_generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) + override; +}; + class long_const_operation : public tuple_holding_operation { -- 2.26.2