From patchwork Fri Dec 1 16:27:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 81144 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 1947E3860002 for ; Fri, 1 Dec 2023 16:30:43 +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 7502B3858C2C for ; Fri, 1 Dec 2023 16:29:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7502B3858C2C 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 7502B3858C2C 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=1701448200; cv=none; b=f9JZdC9IV2vh6jBVBrLQMf8hqlIoCrpH3Q+eU9BJ1mrj7WISOmwvVojt5n7Q76tQYPTMVsnFF5dT6UCLo9T4D5rnBGT2x2CyFy3ztDDjW7jZr4dYxPoy42yRnFvOaZQfs7LFKUSlCIGvSYDhY3PN02WhFR6SRDC4HCam2HdiGpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701448200; c=relaxed/simple; bh=CuDKpQj3haWbgVxRBZuY8UXK6M28nxrW0IoCdGOXX0o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=t7uR/kxWPVBe5SZImVyGfvCEbd35mBKZU6Sh0eUXWb9HoXQhSYtwGM564dB0vsQuBOQ5z4JQGoXQFv78yGpXl0kjUm+OjLfxw+oq/U3/OSpphRvAwublQ477hYQBGYDZUXleQX+XrV4gAmIBSnqWNtDP+ua0tzbELx+I3CN7DgM= 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 4A42D1E1A7; Fri, 1 Dec 2023 11:29:57 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Luis Machado , John Baldwin , "Aktemur, Tankut Baris" , Simon Marchi , John Baldwin Subject: [PATCH 13/24] gdb: add value::allocate_register Date: Fri, 1 Dec 2023 11:27:26 -0500 Message-ID: <20231201162751.741751-14-simon.marchi@efficios.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231201162751.741751-1-simon.marchi@efficios.com> References: <20231201162751.741751-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 Add value::allocate_register, to facilitate allocating a value representing a register in a given frame (or rather, in the given frame's previous frame). It will be used in a subsequent patch. I changed one relatively obvious spot that could use it, to at least exercise the code path. Change-Id: Icd4960f5e471a74b657bb3596c88d89679ef3772 Reviewed-By: John Baldwin --- gdb/regcache.c | 7 ++----- gdb/value.c | 15 +++++++++++++++ gdb/value.h | 7 +++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 19ba353a335c..9b3fd4f060c7 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -775,11 +775,8 @@ readable_regcache::cooked_read_value (int regnum) || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN) || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch)) { - struct value *result; - - result = value::allocate (register_type (m_descr->gdbarch, regnum)); - result->set_lval (lval_register); - VALUE_REGNUM (result) = regnum; + value *result = value::allocate_register + (get_next_frame_sentinel_okay (get_current_frame ()), regnum); /* It is more efficient in general to do this delegation in this direction than in the other one, even though the value-based diff --git a/gdb/value.c b/gdb/value.c index 1a3985582ba5..99af27b98700 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -959,6 +959,21 @@ value::allocate (struct type *type) return allocate (type, true); } +/* See value.h */ + +struct value * +value::allocate_register (frame_info_ptr next_frame, int regnum) +{ + value *result + = value::allocate (register_type (frame_unwind_arch (next_frame), regnum)); + + result->set_lval (lval_register); + VALUE_REGNUM (result) = regnum; + VALUE_NEXT_FRAME_ID (result) = get_frame_id (next_frame); + + 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 3f9b35b589bd..2f3b41e26ea4 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -159,6 +159,13 @@ 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`. + + The caller is responsible for filling the value's contents. */ + static struct value *allocate_register (frame_info_ptr next_frame, + int regnum); + /* Create a computed lvalue, with type TYPE, function pointers FUNCS, and closure CLOSURE. */ static struct value *allocate_computed (struct type *type,