From patchwork Thu Dec 21 19:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 82693 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 AD812384DEE3 for ; Thu, 21 Dec 2023 19:17:42 +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 7275F3858419 for ; Thu, 21 Dec 2023 19:17:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7275F3858419 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 7275F3858419 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=Xok/tVKrJiRjDj5BEsVQdpurYVThORif285WCbKJ0HORGA/H75m1qELGUyHXpclwMhBpDrFBtf4WkTYrBz7JlC3021F2XaSYBGu6JNavUkuBd2A0vf1pycpkncDDTBtCMLsJLkycdssBYdUnRpAHpygOWQVd9PgYWVBCQMVUbB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703186241; c=relaxed/simple; bh=NHjz9IKHJJoU8BAXNo+rA8kSszu1UZpKnseu7KxSzhM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=V0JXdoUyacnr8Ct+VdaaAp53SVVVilVfgtcENuVD3Ac8tFXhjZH0i+PGS0PxZdxuOiB9bEBzZAaiv6myyWWoU+s7iuQq0IomIWnNP0X2FiGBG5D2XIwgEPf9iM8Yo5m1DiR24tgKmCWg6jz7Hp7RZNMy6j7RKXtlY1XehLhlDYg= 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 CB1091E0C3; Thu, 21 Dec 2023 14:17:18 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/9] gdb: pass frame_info_ptr to gdbarch_value_from_register Date: Thu, 21 Dec 2023 14:16:23 -0500 Message-ID: <20231221191716.257256-3-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 Pass a frame_info_ptr rather than a frame_id. This avoids having to do a frame lookup on the callee side, when we can just pass the frame down directly. I think this fixes a bug in rs6000-tdep.c where the id of the wrong frame was set to `VALUE_NEXT_FRAME_ID (v)`. Change-Id: I77039bc87ea8fc5262f16d0e1446515efa21c565 --- gdb/findvar.c | 24 ++++++++++-------------- gdb/gdbarch-gen.h | 6 +++--- gdb/gdbarch.c | 4 ++-- gdb/gdbarch_components.py | 4 ++-- gdb/rs6000-tdep.c | 16 ++++++++-------- gdb/s390-tdep.c | 10 +++++----- gdb/value.h | 7 +++---- 7 files changed, 33 insertions(+), 38 deletions(-) diff --git a/gdb/findvar.c b/gdb/findvar.c index e6dedf0aadf6..25737c4e3159 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -747,23 +747,21 @@ read_var_value (struct symbol *var, const struct block *var_block, /* Install default attributes for register values. */ -struct value * -default_value_from_register (struct gdbarch *gdbarch, struct type *type, - int regnum, struct frame_id frame_id) +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); - frame_info_ptr frame; - value->set_lval (lval_register); - frame = frame_find_by_id (frame_id); - if (frame == NULL) - frame_id = null_frame_id; + frame_id next_frame_id; + if (this_frame == nullptr) + next_frame_id = null_frame_id; else - frame_id = get_frame_id (get_next_frame_sentinel_okay (frame)); + next_frame_id = get_frame_id (get_next_frame_sentinel_okay (this_frame)); - VALUE_NEXT_FRAME_ID (value) = frame_id; + VALUE_NEXT_FRAME_ID (value) = next_frame_id; VALUE_REGNUM (value) = regnum; /* Any structure stored in more than one register will always be @@ -865,8 +863,7 @@ value_from_register (struct type *type, int regnum, frame_info_ptr frame) else { /* Construct the value. */ - v = gdbarch_value_from_register (gdbarch, type, - regnum, get_frame_id (frame)); + v = gdbarch_value_from_register (gdbarch, type, regnum, frame); /* Get the data. */ read_frame_register_value (v, frame); @@ -883,7 +880,6 @@ address_from_register (int regnum, frame_info_ptr frame) { struct gdbarch *gdbarch = get_frame_arch (frame); struct type *type = builtin_type (gdbarch)->builtin_data_ptr; - struct value *value; CORE_ADDR result; int regnum_max_excl = gdbarch_num_cooked_regs (gdbarch); @@ -919,7 +915,7 @@ address_from_register (int regnum, frame_info_ptr frame) return unpack_long (type, buf); } - value = gdbarch_value_from_register (gdbarch, type, regnum, null_frame_id); + value *value = gdbarch_value_from_register (gdbarch, type, regnum, nullptr); read_frame_register_value (value, frame); if (value->optimized_out ()) diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 80d40136c379..a7761616e032 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -422,12 +422,12 @@ extern void gdbarch_value_to_register (struct gdbarch *gdbarch, frame_info_ptr f extern void set_gdbarch_value_to_register (struct gdbarch *gdbarch, gdbarch_value_to_register_ftype *value_to_register); /* Construct a value representing the contents of register REGNUM in - frame FRAME_ID, interpreted as type TYPE. The routine needs to + frame THIS_FRAME, interpreted as type TYPE. The routine needs to allocate and return a struct value with all value attributes (but not the value contents) filled in. */ -typedef struct value * (gdbarch_value_from_register_ftype) (struct gdbarch *gdbarch, struct type *type, int regnum, struct frame_id frame_id); -extern struct value * gdbarch_value_from_register (struct gdbarch *gdbarch, struct type *type, int regnum, struct frame_id frame_id); +typedef struct value * (gdbarch_value_from_register_ftype) (struct gdbarch *gdbarch, struct type *type, int regnum, frame_info_ptr this_frame); +extern struct value * gdbarch_value_from_register (struct gdbarch *gdbarch, struct type *type, int regnum, frame_info_ptr this_frame); extern void set_gdbarch_value_from_register (struct gdbarch *gdbarch, gdbarch_value_from_register_ftype *value_from_register); typedef CORE_ADDR (gdbarch_pointer_to_address_ftype) (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index d584305fefb2..6d83e17160e6 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -2557,13 +2557,13 @@ set_gdbarch_value_to_register (struct gdbarch *gdbarch, } struct value * -gdbarch_value_from_register (struct gdbarch *gdbarch, struct type *type, int regnum, struct frame_id frame_id) +gdbarch_value_from_register (struct gdbarch *gdbarch, struct type *type, int regnum, frame_info_ptr this_frame) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->value_from_register != NULL); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_value_from_register called\n"); - return gdbarch->value_from_register (gdbarch, type, regnum, frame_id); + return gdbarch->value_from_register (gdbarch, type, regnum, this_frame); } void diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 4352f7066512..432e4b4ea267 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -814,7 +814,7 @@ Function( Method( comment=""" Construct a value representing the contents of register REGNUM in -frame FRAME_ID, interpreted as type TYPE. The routine needs to +frame THIS_FRAME, interpreted as type TYPE. The routine needs to allocate and return a struct value with all value attributes (but not the value contents) filled in. """, @@ -823,7 +823,7 @@ allocate and return a struct value with all value attributes params=[ ("struct type *", "type"), ("int", "regnum"), - ("struct frame_id", "frame_id"), + ("frame_info_ptr", "this_frame"), ], predefault="default_value_from_register", invalid=False, diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index a7e0bf5305b5..a0f3d94f3a11 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -2747,9 +2747,9 @@ rs6000_value_to_register (frame_info_ptr frame, put_frame_register (get_next_frame_sentinel_okay (frame), regnum, to_view); } -static struct value * -rs6000_value_from_register (struct gdbarch *gdbarch, struct type *type, - int regnum, struct frame_id frame_id) +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); @@ -2759,14 +2759,14 @@ rs6000_value_from_register (struct gdbarch *gdbarch, struct type *type, regnum = ieee_128_float_regnum_adjust (gdbarch, type, regnum); value->set_lval (lval_register); - frame_info_ptr frame = frame_find_by_id (frame_id); - if (frame == NULL) - frame_id = null_frame_id; + frame_id next_frame_id; + if (this_frame == nullptr) + next_frame_id = null_frame_id; else - frame_id = get_frame_id (get_next_frame_sentinel_okay (frame)); + next_frame_id = get_frame_id (get_next_frame_sentinel_okay (this_frame)); - VALUE_NEXT_FRAME_ID (value) = frame_id; + VALUE_NEXT_FRAME_ID (value) = next_frame_id; VALUE_REGNUM (value) = regnum; /* Any structure stored in more than one register will always be diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index fcba7a1a5608..ebbcbc153fe1 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -1236,13 +1236,13 @@ regnum_is_vxr_full (s390_gdbarch_tdep *tdep, int regnum) registers, even though we are otherwise a big-endian platform. The same applies to a 'float' value within a vector. */ -static struct value * -s390_value_from_register (struct gdbarch *gdbarch, struct type *type, - int regnum, struct frame_id frame_id) +static value * +s390_value_from_register (gdbarch *gdbarch, type *type, int regnum, + frame_info_ptr this_frame) { s390_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - struct value *value = default_value_from_register (gdbarch, type, - regnum, frame_id); + value *value + = default_value_from_register (gdbarch, type, regnum, this_frame); check_typedef (type); if ((regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM diff --git a/gdb/value.h b/gdb/value.h index d7bda1e8d2c9..d4244dadb91a 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1110,10 +1110,9 @@ extern struct value *value_from_contents_and_address frame_info_ptr frame = nullptr); extern struct value *value_from_contents (struct type *, const gdb_byte *); -extern struct value *default_value_from_register (struct gdbarch *gdbarch, - struct type *type, - int regnum, - struct frame_id frame_id); +extern value *default_value_from_register (gdbarch *gdbarch, type *type, + int regnum, + frame_info_ptr this_frame); extern void read_frame_register_value (struct value *value, frame_info_ptr frame);