From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id E324E3858C1F for ; Tue, 22 Nov 2022 22:25:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E324E3858C1F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4NGzNQ5hJgz3VtY; Tue, 22 Nov 2022 22:25:26 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NGzNQ4RcZz4MBZ; Tue, 22 Nov 2022 22:25:26 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669155926; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=64xaUjLhYIg6V2sMqFEgDYxshQ9zQrCrf5mgC8MDwUY=; b=FHB6jDL6O8hGb5UU62P41QUcVrHHVhE1kSMIAHnB/rv4E7S+76ZWzaxE0BBDsKkDhqZl3s 5o/vq13UwCJyeXULbVAMAT9cp33TMmzO2fstrAY8RdjVmNrHEcdsbbIwFjEx7TnCjOZNto 4rZMxOMZsuMY9ZsiujR8xwaU2VWOXgfH4DnXO4EvDmCC3TIG0OvR3g6KGSVUi4T7ETtoXM gA8DPEwK4RVvIuY47Dhl2mTbnsXMOwGNVjEj5AAEh4QFE6AXZ8yMPKyYyMUjWHIiKr27gD 8oIWTdFO71fbjVeS9S58UUzjfZ2iM3U9ha2vUZb1KMj9hJpofd/RWfoThCzTCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669155926; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=64xaUjLhYIg6V2sMqFEgDYxshQ9zQrCrf5mgC8MDwUY=; b=y0LWpo8/OeHOwplYQnf8jTbZ9IYp4Z4OWt6FzfYGbB+LaL8o1R4V8tM0C8eHjdj0fzwp5H 9TiSQWC1++i77uNjJbuKP0EzFPjo1jtSNnnffnVandspZepXhnn8Yw9Yui0zPsfQIaaDwK 02h4N3+H1ZzVfNJkTmc/VrWYy8wKSYFjGBEXFSdJtlwWZ/Ig6mDYgCHXUwb50eKg+0wR2N jDNExA/YipvCWkbBkwUOFN+q9/yYr01iq5/P3H/5gby2NR/K/A5XcB5d5gxgOwvratk+7x /GIRCDXyXZyyO/JE7xmeT9zvC5MAsNQD98EqzrNGbz7SFi0wDx6TYjXD39eYwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669155926; a=rsa-sha256; cv=none; b=hoTFs9OxRGkDuL/nwsmQf8E9NoudL9sXFm1YC3y+zUKQph5Z4tLAY1powA8Gx8ZjSiV9wX OmRN9XwPVBEti6ktCVNxXnHuQwLAnzUOog3YBK2lx24j4cUjbgHMhoK4FpCiZ0HCu45HGC zKdXres0Hgosx1/GRJcfCUYwbrmDTthZrYxUwnkUiCtXEhrfNd01B1n0zxATOxyt6mGxxM 77PKQxt+BWe46RRscgAbvoEK/pCENz3uk9pAYYpT3KA/yDD5t7vY3Ggjx0EZF4NrqiEBIY ZA/7TqFUeS4dhht+hL5ZUoPk+kwNL6PdpCJ7WSiBJdyAqgQJXCZd6sT5SIqGWA== Received: from [10.0.1.4] (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4NGzNQ1XR4zbHx; Tue, 22 Nov 2022 22:25:26 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <28e7fa75-32df-d378-a2c7-cc3a672d051b@FreeBSD.org> Date: Tue, 22 Nov 2022 14:25:25 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH 3/5] fbsd-nat: Pass an optional register base to the register set helpers. Content-Language: en-US From: John Baldwin To: Simon Marchi , gdb-patches@sourceware.org References: <20220708005816.9408-1-jhb@FreeBSD.org> <20220708005816.9408-4-jhb@FreeBSD.org> <7fc99741-64d8-f213-ea64-aa401bd42d4c@simark.ca> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,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 List-Id: On 11/22/22 2:16 PM, John Baldwin wrote: > On 11/22/22 12:38 PM, Simon Marchi wrote: >> On 7/7/22 20:58, John Baldwin wrote: >>> This is needed to permit using the helpers for register sets with a >>> variable base. In particular regnum needs to be converted into a >>> relative register number before passed to regcache_map_supplies. >>> --- >>> gdb/fbsd-nat.c | 34 +++++++++++++++++++--------------- >>> gdb/fbsd-nat.h | 49 ++++++++++++++++++++++++++++--------------------- >>> 2 files changed, 47 insertions(+), 36 deletions(-) >>> >>> diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c >>> index 9d7383ac0ab..edcd3fc3ed1 100644 >>> --- a/gdb/fbsd-nat.c >>> +++ b/gdb/fbsd-nat.c >>> @@ -1732,14 +1732,15 @@ fbsd_nat_target::supports_disable_randomization () >>> bool >>> fbsd_nat_target::fetch_register_set (struct regcache *regcache, int regnum, >>> int fetch_op, const struct regset *regset, >>> - void *regs, size_t size) >>> + int regbase, void *regs, size_t size) >>> { >>> const struct regcache_map_entry *map >>> = (const struct regcache_map_entry *) regset->regmap; >>> pid_t pid = get_ptrace_pid (regcache->ptid ()); >>> >>> - if (regnum == -1 || regcache_map_supplies (map, regnum, regcache->arch(), >>> - size)) >>> + if (regnum == -1 >>> + || (regnum >= regbase && regcache_map_supplies (map, regnum - regbase, >>> + regcache->arch(), size))) >> >> My understanding is that it would be an internal error if the caller >> passed a regnum that is < regbase. In order words, should you do: >> >> gdb_assert (regnum >= regbase); >> >> ? >> >> Actually, after reading the following patches, I think the answer is >> no. When requesting a single register, we will still go through all the >> fetch functions and we expect them to do nothing if the register is not >> theirs. Leaving the question there in case others wonder about the same >> thing. >> >> I was also wondering if it would be better to do the absolute -> >> relative conversion in the caller. All this function knows is the >> regset-relative view of things. In the end it doesn't matter much, it >> just moves a condition from here to the callers. I'm fine with whatever >> you prefer. > > If you do the adjustment to an absolute value in the caller you have to still > special case for regnum == -1 when fetching all registers. The current approach > here means that the special case for that is handled down in > regcache:transfer_regset which already has a special case for -1. Ah, I think I misunderstood your point. While I could perhaps push the regcache_map_supplies check out to the callers, that would somewhat defeat the point of these helpers which is to reduce duplicated code in callers. -- John Baldwin