From patchwork Mon Feb 13 03:15:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 64822 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 601A13947406 for ; Mon, 13 Feb 2023 03:18:48 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from qproxy4-pub.mail.unifiedlayer.com (qproxy4-pub.mail.unifiedlayer.com [66.147.248.250]) by sourceware.org (Postfix) with ESMTPS id F3374385B538 for ; Mon, 13 Feb 2023 03:15:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3374385B538 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by qproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 42B1180283E0 for ; Mon, 13 Feb 2023 03:15:59 +0000 (UTC) Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id 3B60110046D5C for ; Mon, 13 Feb 2023 03:15:29 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id RPJRph67BFh3zRPJRp7A5o; Mon, 13 Feb 2023 03:15:29 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=QpabYX+d c=1 sm=1 tr=0 ts=63e9ab51 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=m04uMKEZRckA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=7d_E57ReAAAA:8 a=Oz5qh-HchgrWnQlwOZYA:9 a=QEXdDO2ut3YA:10:nop_charset_2 a=4yiUztQirxb6EpNbXFxf:22 a=jhqOcbufqs7Y1TYCrUUU:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=T0uH8caaKk1Uydg5OEPO9ibXBJCPJG8l4voSNBP4lsg=; b=X+6tdTjViBkFRFaztId2SFyMv4 juZrf83avkTd50KcKW8wDPTGPXCpstaRzLAe9rrsKum1Dl3OuzjZOoBs2DA6Brm9IcvzF5GiD2drj M1pAKWYiEvDuddpfrgOpVUn+T; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:37668 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pRPJQ-001AGJ-VV; Sun, 12 Feb 2023 20:15:28 -0700 From: Tom Tromey Date: Sun, 12 Feb 2023 20:15:38 -0700 Subject: [PATCH v3 22/50] Turn allocate_value_lazy into a static "constructor" MIME-Version: 1.0 Message-Id: <20230209-submit-value-fixups-2023-v3-22-45e91a20c742@tromey.com> References: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com> In-Reply-To: <20230209-submit-value-fixups-2023-v3-0-45e91a20c742@tromey.com> To: gdb-patches@sourceware.org Cc: Simon Marchi X-Mailer: b4 0.12.0 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: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pRPJQ-001AGJ-VV X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net ([192.168.0.21]) [75.166.130.93]:37668 X-Source-Auth: tom+tromey.com X-Email-Count: 47 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This changes allocate_value_lazy to be a static "constructor" of struct value. I considered trying to change value to use ordinary new/delete, but it seems to me that due to reference counting, we may someday want to change these static constructors to return value_ref_ptr instead. Approved-By: Simon Marchi --- gdb/ada-lang.c | 2 +- gdb/findvar.c | 2 +- gdb/rust-lang.c | 2 +- gdb/valops.c | 2 +- gdb/value.c | 30 ++++++++++++++---------------- gdb/value.h | 12 +++++++++++- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index e13359a68f6..ae2f4df5332 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -561,7 +561,7 @@ coerce_unspec_val_to_type (struct value *val, struct type *type) /* Be careful not to make a lazy not_lval value. */ || (VALUE_LVAL (val) != not_lval && type->length () > val->type ()->length ())) - result = allocate_value_lazy (type); + result = value::allocate_lazy (type); else { result = allocate_value (type); diff --git a/gdb/findvar.c b/gdb/findvar.c index 9420286e91c..cb4eb758bf2 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -294,7 +294,7 @@ value_of_register_lazy (frame_info_ptr frame, int regnum) /* We should have a valid next frame. */ gdb_assert (frame_id_p (get_frame_id (next_frame))); - reg_val = allocate_value_lazy (register_type (gdbarch, regnum)); + reg_val = value::allocate_lazy (register_type (gdbarch, regnum)); VALUE_LVAL (reg_val) = lval_register; VALUE_REGNUM (reg_val) = regnum; VALUE_NEXT_FRAME_ID (reg_val) = get_frame_id (next_frame); diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index aa1590078dc..8f0953649ae 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -349,7 +349,7 @@ rust_val_print_slice (struct value *val, struct ui_file *stream, int recurse, struct type *elt_type = base->type ()->target_type (); struct type *array_type = lookup_array_range_type (elt_type, 0, llen - 1); - struct value *array = allocate_value_lazy (array_type); + struct value *array = value::allocate_lazy (array_type); VALUE_LVAL (array) = lval_memory; array->set_address (value_as_address (base)); value_fetch_lazy (array); diff --git a/gdb/valops.c b/gdb/valops.c index cea9d3ce593..5e6095db81f 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -4079,7 +4079,7 @@ value_slice (struct value *array, int lowbound, int length) slice_type->set_code (array_type->code ()); if (VALUE_LVAL (array) == lval_memory && array->lazy ()) - slice = allocate_value_lazy (slice_type); + slice = value::allocate_lazy (slice_type); else { slice = allocate_value (slice_type); diff --git a/gdb/value.c b/gdb/value.c index 471a98f277b..0dccb7307d6 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -744,12 +744,10 @@ static std::vector value_history; static std::vector all_values; -/* Allocate a lazy value for type TYPE. Its actual content is - "lazily" allocated too: the content field of the return value is - NULL; it will be allocated when it is fetched from the target. */ +/* See value.h. */ struct value * -allocate_value_lazy (struct type *type) +value::allocate_lazy (struct type *type) { struct value *val; @@ -963,7 +961,7 @@ allocate_value_contents (struct value *val, bool check_size) static struct value * allocate_value (struct type *type, bool check_size) { - struct value *val = allocate_value_lazy (type); + struct value *val = value::allocate_lazy (type); allocate_value_contents (val, check_size); val->m_lazy = 0; @@ -1001,7 +999,7 @@ allocate_computed_value (struct type *type, const struct lval_funcs *funcs, void *closure) { - struct value *v = allocate_value_lazy (type); + struct value *v = value::allocate_lazy (type); VALUE_LVAL (v) = lval_computed; v->m_location.computed.funcs = funcs; @@ -1015,7 +1013,7 @@ allocate_computed_value (struct type *type, struct value * allocate_optimized_out_value (struct type *type) { - struct value *retval = allocate_value_lazy (type); + struct value *retval = value::allocate_lazy (type); mark_value_bytes_optimized_out (retval, 0, type->length ()); retval->set_lazy (0); @@ -1545,7 +1543,7 @@ value_copy (const value *arg) struct type *encl_type = arg->enclosing_type (); struct value *val; - val = allocate_value_lazy (encl_type); + val = value::allocate_lazy (encl_type); val->m_type = arg->m_type; VALUE_LVAL (val) = arg->m_lval; val->m_location = arg->m_location; @@ -2950,7 +2948,7 @@ value_primitive_field (struct value *arg1, LONGEST offset, LONGEST bitpos = arg_type->field (fieldno).loc_bitpos (); LONGEST container_bitsize = type->length () * 8; - v = allocate_value_lazy (type); + v = value::allocate_lazy (type); v->m_bitsize = TYPE_FIELD_BITSIZE (arg_type, fieldno); if ((bitpos % container_bitsize) + v->m_bitsize <= container_bitsize && type->length () <= (int) sizeof (LONGEST)) @@ -2988,7 +2986,7 @@ value_primitive_field (struct value *arg1, LONGEST offset, boffset = arg_type->field (fieldno).loc_bitpos () / 8; if (arg1->lazy ()) - v = allocate_value_lazy (arg1->enclosing_type ()); + v = value::allocate_lazy (arg1->enclosing_type ()); else { v = allocate_value (arg1->enclosing_type ()); @@ -3008,7 +3006,7 @@ value_primitive_field (struct value *arg1, LONGEST offset, gdb_assert (PROP_CONST == TYPE_DATA_LOCATION_KIND (type)); /* For dynamic data types defer memory allocation until we actual access the value. */ - v = allocate_value_lazy (type); + v = value::allocate_lazy (type); } else { @@ -3021,7 +3019,7 @@ value_primitive_field (struct value *arg1, LONGEST offset, value_fetch_lazy (arg1); if (arg1->lazy ()) - v = allocate_value_lazy (type); + v = value::allocate_lazy (type); else { v = allocate_value (type); @@ -3426,7 +3424,7 @@ pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num) struct value * value_zero (struct type *type, enum lval_type lv) { - struct value *val = allocate_value_lazy (type); + struct value *val = value::allocate_lazy (type); VALUE_LVAL (val) = (lv == lval_computed ? not_lval : lv); val->m_is_zero = true; @@ -3500,7 +3498,7 @@ value_from_contents_and_address_unresolved (struct type *type, struct value *v; if (valaddr == NULL) - v = allocate_value_lazy (type); + v = value::allocate_lazy (type); else v = value_from_contents (type, valaddr); VALUE_LVAL (v) = lval_memory; @@ -3526,7 +3524,7 @@ value_from_contents_and_address (struct type *type, struct value *v; if (valaddr == NULL) - v = allocate_value_lazy (resolved_type); + v = value::allocate_lazy (resolved_type); else v = value_from_contents (resolved_type, valaddr); if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL @@ -3622,7 +3620,7 @@ value_from_component (struct value *whole, struct type *type, LONGEST offset) struct value *v; if (VALUE_LVAL (whole) == lval_memory && whole->lazy ()) - v = allocate_value_lazy (type); + v = value::allocate_lazy (type); else { v = allocate_value (type); diff --git a/gdb/value.h b/gdb/value.h index 788a3d8514e..29ed2a8a3ce 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -144,6 +144,9 @@ typedef gdb::ref_ptr value_ref_ptr; struct value { +private: + + /* Values can only be created via "static constructors". */ explicit value (struct type *type_) : m_modifiable (1), m_lazy (1), @@ -156,6 +159,13 @@ struct value { } +public: + + /* Allocate a lazy value for type TYPE. Its actual content is + "lazily" allocated too: the content field of the return value is + NULL; it will be allocated when it is fetched from the target. */ + static struct value *allocate_lazy (struct type *type); + ~value (); DISABLE_COPY_AND_ASSIGN (value); @@ -1002,7 +1012,7 @@ extern struct value *read_var_value (struct symbol *var, frame_info_ptr frame); extern struct value *allocate_value (struct type *type); -extern struct value *allocate_value_lazy (struct type *type); + extern void value_contents_copy (struct value *dst, LONGEST dst_offset, struct value *src, LONGEST src_offset, LONGEST length);