From patchwork Thu Dec 21 19:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 82695 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 ACCCE3864844 for ; Thu, 21 Dec 2023 19:17:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id AFA983857C51 for ; Thu, 21 Dec 2023 19:17:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFA983857C51 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AFA983857C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703186241; cv=none; b=i45f6mi2mlrhM3ix4Zp/CexaIJbGi8SNeld3UGArtJ0GF49zyhMMAVDoHi0JJBdf2dvA4Ix0lbBjKvBhMcEZds6Di/bZMgmoO/wxMpkjKLq6XWR5CJpzF0NUM2+6yZtSBIgOKLqM9H99uIs1ulR+ld3m+DMd1+NdgFqMHJR8fV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703186241; c=relaxed/simple; bh=xwg9ypg/T4/2WTc6jUlNBA5AjqMokZlMEm7bEpEvQVY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UMYSBaANQze8vS2vcKY9AymHvVrHdDPVOR9dOykIajgaBATieyHPinOQU3D9BNc2sQBZAKw08ZXgXGIIIi62vkT2ss9wWl42GxrB0Pdm2P83T14rY5FqpHhibwnNPaDXLYkgEN20YLx5daqQSv/ERDjfSSAPzbu0j9r1eiEKwT0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 56A601E110; Thu, 21 Dec 2023 14:17:19 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 4/9] gdb: add type parameter to value::allocate_register and add value::allocate_register_lazy Date: Thu, 21 Dec 2023 14:16:25 -0500 Message-ID: <20231221191716.257256-5-simon.marchi@efficios.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231221191716.257256-1-simon.marchi@efficios.com> References: <20231221191716.257256-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3496.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE 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.30 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 Some places that create register struct values don't use register_type to obtain the value type. This prevents them from using the current version of value::allocate_register. One spot (value_of_register_lazy) also creates a lazy register value. Add a value::allocate_register_lazy method. Add some type parameters to value::allocate_register and value::allocate_register_lazy, to let the caller specify the type to use for the value. The parameters default to nullptr, in which case we use register_type to obtain the type. Change-Id: I640ec0a5a0f4a55eba12d515dbfd25933229f8ec --- gdb/findvar.c | 24 ++++++------------------ gdb/rs6000-tdep.c | 13 ++++--------- gdb/value.c | 22 ++++++++++++++++++---- gdb/value.h | 13 +++++++++---- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/gdb/findvar.c b/gdb/findvar.c index 852f42dc176d..7c6c837ae12e 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -281,12 +281,7 @@ value_of_register_lazy (frame_info_ptr next_frame, int regnum) /* We should have a valid next frame. */ gdb_assert (frame_id_p (get_frame_id (next_frame))); - value *reg_val = value::allocate_lazy (register_type (gdbarch, regnum)); - reg_val->set_lval (lval_register); - VALUE_REGNUM (reg_val) = regnum; - VALUE_NEXT_FRAME_ID (reg_val) = get_frame_id (next_frame); - - return reg_val; + return value::allocate_register_lazy (next_frame, regnum); } /* Given a pointer of type TYPE in target form in BUF, return the @@ -751,25 +746,20 @@ value * default_value_from_register (gdbarch *gdbarch, type *type, int regnum, frame_info_ptr this_frame) { - int len = type->length (); - struct value *value = value::allocate (type); - value->set_lval (lval_register); - frame_info_ptr next_frame = get_next_frame_sentinel_okay (this_frame); while (get_frame_type (next_frame) == INLINE_FRAME) next_frame = get_next_frame_sentinel_okay (next_frame); - VALUE_NEXT_FRAME_ID (value) = get_frame_id (next_frame); - VALUE_REGNUM (value) = regnum; + value *value = value::allocate_register (next_frame, regnum, type); /* Any structure stored in more than one register will always be an integral number of registers. Otherwise, you need to do some fiddling with the last register copied here for little endian machines. */ if (type_byte_order (type) == BFD_ENDIAN_BIG - && len < register_size (gdbarch, regnum)) + && type->length () < register_size (gdbarch, regnum)) /* Big-endian, and we want less than full size. */ - value->set_offset (register_size (gdbarch, regnum) - len); + value->set_offset (register_size (gdbarch, regnum) - type->length ()); else value->set_offset (0); @@ -842,10 +832,8 @@ value_from_register (struct type *type, int regnum, frame_info_ptr frame) the corresponding [integer] type (see Alpha). The assumption is that gdbarch_register_to_value populates the entire value including the location. */ - v = value::allocate (type); - v->set_lval (lval_register); - VALUE_NEXT_FRAME_ID (v) = get_frame_id (get_next_frame_sentinel_okay (frame)); - VALUE_REGNUM (v) = regnum; + v = value::allocate_register (get_next_frame_sentinel_okay (frame), + regnum, type); ok = gdbarch_register_to_value (gdbarch, frame, regnum, type1, v->contents_raw ().data (), &optim, &unavail); diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index 478e9078de6f..edf776853e20 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -2751,30 +2751,25 @@ static value * rs6000_value_from_register (gdbarch *gdbarch, type *type, int regnum, frame_info_ptr this_frame) { - int len = type->length (); - struct value *value = value::allocate (type); - /* We have an IEEE 128-bit float -- need to change regnum mapping from fpr to vsr. */ regnum = ieee_128_float_regnum_adjust (gdbarch, type, regnum); - value->set_lval (lval_register); - frame_info_ptr next_frame = get_next_frame_sentinel_okay (this_frame); while (get_frame_type (next_frame) == INLINE_FRAME) next_frame = get_next_frame_sentinel_okay (next_frame); - VALUE_NEXT_FRAME_ID (value) = get_frame_id (next_frame); - VALUE_REGNUM (value) = regnum; + value *value + = value::allocate_register (next_frame, regnum, type); /* Any structure stored in more than one register will always be an integral number of registers. Otherwise, you need to do some fiddling with the last register copied here for little endian machines. */ if (type_byte_order (type) == BFD_ENDIAN_BIG - && len < register_size (gdbarch, regnum)) + && type->length () < register_size (gdbarch, regnum)) /* Big-endian, and we want less than full size. */ - value->set_offset (register_size (gdbarch, regnum) - len); + value->set_offset (register_size (gdbarch, regnum) - type->length ()); else value->set_offset (0); diff --git a/gdb/value.c b/gdb/value.c index 7523af142348..7d51396a0e3a 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -961,11 +961,14 @@ value::allocate (struct type *type) /* See value.h */ -struct value * -value::allocate_register (frame_info_ptr next_frame, int regnum) +value * +value::allocate_register_lazy (frame_info_ptr next_frame, int regnum, + struct type *type) { - value *result - = value::allocate (register_type (frame_unwind_arch (next_frame), regnum)); + if (type == nullptr) + type = register_type (frame_unwind_arch (next_frame), regnum); + + value *result = value::allocate_lazy (type); result->set_lval (lval_register); VALUE_REGNUM (result) = regnum; @@ -974,6 +977,17 @@ value::allocate_register (frame_info_ptr next_frame, int regnum) return result; } +/* See value.h */ + +value * +value::allocate_register (frame_info_ptr next_frame, int regnum, + struct type *type) +{ + value *result = value::allocate_register_lazy (next_frame, regnum, type); + result->set_lazy (false); + return result; +} + /* Allocate a value that has the correct length for COUNT repetitions of type TYPE. */ diff --git a/gdb/value.h b/gdb/value.h index d4244dadb91a..78abcac7e739 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -159,12 +159,17 @@ struct value /* Allocate a value and its contents for type TYPE. */ static struct value *allocate (struct type *type); - /* Allocate a non-lazy value representing register RENUM in the frame previous - to NEXT_FRAME. The type of the value is found using `register_type`. - + /* Allocate a lazy value representing register REGNUM in the frame previous + to NEXT_FRAME. If TYPE is non-nullptr, use it as the value type. + Otherwise, use `register_type` to obtain the type. */ + static struct value *allocate_register_lazy (frame_info_ptr next_frame, + int regnum, type *type = nullptr); + + /* Same as `allocate_register_lazy`, but make the value non-lazy. + The caller is responsible for filling the value's contents. */ static struct value *allocate_register (frame_info_ptr next_frame, - int regnum); + int regnum, type *type = nullptr); /* Create a computed lvalue, with type TYPE, function pointers FUNCS, and closure CLOSURE. */