From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50062.outbound.protection.outlook.com [40.107.5.62]) by sourceware.org (Postfix) with ESMTPS id D93CB3858C2C; Thu, 24 Mar 2022 08:51:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D93CB3858C2C Received: from AM6PR05CA0035.eurprd05.prod.outlook.com (2603:10a6:20b:2e::48) by AM6PR08MB4613.eurprd08.prod.outlook.com (2603:10a6:20b:80::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.16; Thu, 24 Mar 2022 08:51:18 +0000 Received: from AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::72) by AM6PR05CA0035.outlook.office365.com (2603:10a6:20b:2e::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17 via Frontend Transport; Thu, 24 Mar 2022 08:51:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT052.mail.protection.outlook.com (10.152.17.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.18 via Frontend Transport; Thu, 24 Mar 2022 08:51:18 +0000 Received: ("Tessian outbound 31aeb3346a45:v113"); Thu, 24 Mar 2022 08:51:18 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b9dc6db830c1b0de X-CR-MTA-TID: 64aa7808 Received: from bdff98f90da1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D69D8CDB-516F-463A-9B21-F69E15AEF79C.1; Thu, 24 Mar 2022 08:51:12 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id bdff98f90da1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 24 Mar 2022 08:51:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GP2cQZmdIMqn07OP4PClgX59LOTFR/GUM9K6YP7bRy4KJPmZT4Wj/WNqUWtk9Bs2m7UdfmsVfLrOGSWb8OY+JNogwOqvbgF9pkqV42VisTnzHR30to79NkO4i2f7Rf0DXQ2QUisnJfBoFcZeq/vHkClwqPwWSUdYSC4vPw/bSrw8antLC3vrjm9Bs9IXo0cUGVoiBUu7rHgpszHrgf4TuUeFVX0dPPhfPOkKCARRPdaANZIfXUHOGxGUwDutL3sd1ZuqlYkJMsv9STENylF4wyRewI8gva/SSmfRKdAJ2nzNOr+/XXwTCaqaMJRPXHXhu0aFxxcwbwOb2BFwt2zDtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VbYCDeJ0zaqgU7Gy+wae5QkGw47eHLCNiF6XJ9GvBd4=; b=m6n4lU6nJG7Pck+ALBVnmy/5jOuEigLi1lgdHvAgl+ZGBjNCUKfAcz06+a3ThnMmzAlCeuq/UwR7EfOdwCsfde96+zFHgBni0ccNczhi9yxU782eBFeDNDKPx9NScYlqXgKlG8A3rLFBZxnoCdB/RpfxkY3Mz30BJerkBvZwT7h021IuAz7d3b6OcG++yUITQRnwqlaz5ER5oukLtLfhpMH8B7C9o3BhMIvwJjE5j2HvByjcHN8+9qGE8HaAUH1i3UjyM42wPsdDkeiZ8WTWUWZAAABQWd8A/5UISE6CJa0NTzYXiSfV91sUkIMjNt91cXTz0RozBYVpxLLJydlC9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3911.eurprd08.prod.outlook.com (2603:10a6:20b:80::27) by AM9PR08MB6274.eurprd08.prod.outlook.com (2603:10a6:20b:2d5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.17; Thu, 24 Mar 2022 08:51:11 +0000 Received: from AM6PR08MB3911.eurprd08.prod.outlook.com ([fe80::dc42:487e:f59c:706]) by AM6PR08MB3911.eurprd08.prod.outlook.com ([fe80::dc42:487e:f59c:706%6]) with mapi id 15.20.5081.023; Thu, 24 Mar 2022 08:51:10 +0000 Message-ID: Date: Thu, 24 Mar 2022 08:51:08 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH 02/12] fbsd-nat: Add helper routines for register sets using PT_[G]SETREGSET. Content-Language: en-US To: John Baldwin , binutils@sourceware.org, gdb-patches@sourceware.org References: <20220323210048.25525-1-jhb@FreeBSD.org> <20220323210048.25525-3-jhb@FreeBSD.org> From: Luis Machado In-Reply-To: <20220323210048.25525-3-jhb@FreeBSD.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0237.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:b::33) To AM6PR08MB3911.eurprd08.prod.outlook.com (2603:10a6:20b:80::27) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 6b0b0623-5b81-406e-93ef-08da0d73764f X-MS-TrafficTypeDiagnostic: AM9PR08MB6274:EE_|AM5EUR03FT052:EE_|AM6PR08MB4613:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: mCEJ0zBvd3zmw954XRChwT24GdWJkVl6RID+zoeXfTyZtk0owl6xa99Lv1gWDcXQ1WjbLO9cg5GrN+wPHqiGheesMuSuBsExZkS2ntl43TiBl1SVU0/eq0UTxMgVWxFKnpGw6ifOISwvA5T/NaOwiI57mP+gYmD/vNTQtzE5CRm2j2iNmw8QiNz5J4ChrCbB0FjgBTDcWQ4BALXoVr4blPPARpQ3GDLa0VX2l7PFbMRNXAtkiT2Tel/RhQSeYpp4AJVuRPCcOx0c1qlAxb99/XyIEtwQvk5W2+FE+FsWUGdNBJNGg8V09UOncxjf52mywYIFG1rZgXOL1ztmkGtygvv8DaTdirAbYG/7nRrLCknTbR37CKAdHzh3Mj1BwJBW7wDGQVR/OAffEiTpRAPNSA6aotD4lJtUKKb0XGLjvBsVhqy2r+HG0FRM0NTAa31jbHhbNS7elrSTnPlYBqIjb1aGciaydTXXZqyYcX5gmpcAPbZaFkenaHo6n/k2QU6aeMiT+wwtQc/I0edk0wBulGs1n/WRs2U9GO1xPOzOH9ZoeLo+0CXOH8fQ7CR93N2PS0YVb78IVGYCNpf75pefNfV0zKDKuY5ROB9Hq56AtlxauZZWOm2UlzwaCXRKmZ+ckcgq+YcyRmb2j8iTKP0tgRyKe45j2jE7Uk/wlxskqY7KUGtPAs+xLkHI83gnoSsnDC2fs/3h3hK/NbrW2X+Co9Y2iU5qnDgvUA6jHgWPB1A= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3911.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(8936002)(2616005)(316002)(31696002)(66476007)(26005)(66946007)(66556008)(6486002)(508600001)(8676002)(38100700002)(6512007)(86362001)(186003)(53546011)(6506007)(2906002)(44832011)(83380400001)(36756003)(5660300002)(31686004)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6274 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 7c84506a-63a0-425e-71da-08da0d737109 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X1ugH9xa9KVXVXZDHMoH1sksfeZ4XMFRPFGS/YS/ScqMva5/jNl38xmfZsCIgag6ebY/8MwNGYNpQ1jKYtKf8h1gCtnwkzVtCMao5aQw6W6lccc5jM8Qjds3kj3GKPw0CDOXo18UMILPa5xq8+4xUZ6OZ8VZSE/p4uE/FtqMLqIEUHRq++ItDIX0Qg13jlWGZRqVOVCsfNyVW3guHkauncEFfI6NwUgOYIq898egjYYxSS5tPTkT4NUlwgIlx5dPB/1zgkC/kZ4mLaKDVuZID1tHsfNzgXccD7zv7i5l9P/nPWgQtaB/TJtCPBFAanuxa4zOBJ2pprMmWwVRRYUCAn1jTHzJF3fsSfg+o7cm0QAtXdLaUBU+PuP5Qx1/4x1KLzhpob+QvLchPOn8XG2lMCkGXv97CSv7Erq80YgzsfNnVJPSjkPZ3T7ia6vNquLdkl79MkyKNrYsOhSeabi2uET0XkBhtYw1GaGIQc4PakDB3/6fi5G+JGv9awf0FlEdB/Ll5N7h29GZV6QVOsWcN0ihNkMz+hdhZNv9p+lizPYje2QdXt+FNOnCF49pkZtX6tqqCMQQpadnBlsj0qPKzzxsWDQ2pk5XJpyVHffgzXPT33RQBha4rk64RCRYW8nbNoQrc2/Z+fvFJ0HEcca9ysHBbmAZu39R0NhCqM2AJm/CWKKmkEhuzfLyV1C12FiHXOBzd4WuvpAswtuVampSuA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(40460700003)(5660300002)(6512007)(6506007)(8676002)(31696002)(53546011)(44832011)(82310400004)(2906002)(8936002)(6486002)(508600001)(2616005)(86362001)(83380400001)(336012)(36860700001)(186003)(356005)(81166007)(26005)(70586007)(36756003)(450100002)(316002)(47076005)(70206006)(31686004)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2022 08:51:18.2423 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b0b0623-5b81-406e-93ef-08da0d73764f X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4613 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Mar 2022 08:51:23 -0000 On 3/23/22 21:00, John Baldwin wrote: > FreeBSD's kernel has recently added PT_GETREGSET and PT_SETREGSET > operations to fetch a register set named by an ELF note type. These > helper routines provide helpers to check for a register set's > existence, fetch registers for a register set, and store registers to > a register set. > --- > gdb/fbsd-nat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ > gdb/fbsd-nat.h | 42 +++++++++++++++++++++++++++++ > 2 files changed, 114 insertions(+) > > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c > index 934fdbad6ef..84abdd9a322 100644 > --- a/gdb/fbsd-nat.c > +++ b/gdb/fbsd-nat.c > @@ -1772,6 +1772,78 @@ fbsd_nat_target::store_register_set (struct regcache *regcache, int regnum, > return false; > } > > +#ifdef PT_GETREGSET Instead of ifdef-ing the entire block of code, wouldn't it be better to conditionally define the constant and have the code do checks at runtime? If GDB is built on a machine without the proper headers and copied onto a machine with support for PT_GETREGSET, it won't be able to use this improvement. On the other hand, if we build GDB on a machine with the headers, but copy it into a machine without support for PT_GETREGSET, things will break, no? > +/* See fbsd-nat.h. */ > + > +bool > +fbsd_nat_target::have_regset (ptid_t ptid, int note) > +{ > + pid_t pid = get_ptrace_pid (ptid); > + struct iovec iov; > + > + iov.iov_base = nullptr; > + iov.iov_len = 0; > + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) > + return 0; > + return iov.iov_len; > +} > + > +/* See fbsd-nat.h. */ > + > +bool > +fbsd_nat_target::fetch_regset (struct regcache *regcache, int regnum, int note, > + const struct regset *regset, 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)) > + { > + struct iovec iov; > + > + iov.iov_base = regs; > + iov.iov_len = size; > + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) > + perror_with_name (_("Couldn't get registers")); > + > + regcache->supply_regset (regset, regnum, regs, size); > + return true; > + } > + return false; > +} > + > +bool > +fbsd_nat_target::store_regset (struct regcache *regcache, int regnum, int note, > + const struct regset *regset, 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)) > + { > + struct iovec iov; > + > + iov.iov_base = regs; > + iov.iov_len = size; > + if (ptrace (PT_GETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) > + perror_with_name (_("Couldn't get registers")); > + > + regcache->collect_regset (regset, regnum, regs, size); > + > + if (ptrace (PT_SETREGSET, pid, (PTRACE_TYPE_ARG3) &iov, note) == -1) > + perror_with_name (_("Couldn't write registers")); > + return true; > + } > + return false; > +} > +#endif > + > /* See fbsd-nat.h. */ > > bool > diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h > index 82f7ee47949..6a4003627e4 100644 > --- a/gdb/fbsd-nat.h > +++ b/gdb/fbsd-nat.h > @@ -151,6 +151,19 @@ class fbsd_nat_target : public inf_ptrace_target > bool store_register_set (struct regcache *regcache, int regnum, int fetch_op, > int store_op, const struct regset *regset, > void *regs, size_t size); > + > +#ifdef PT_GETREGSET > + /* Helper routines which use PT_GETREGSET and PT_SETREGSET for the > + specified NOTE instead of regset-specific fetch and store > + ops. */ > + > + bool fetch_regset (struct regcache *regcache, int regnum, int note, > + const struct regset *regset, void *regs, size_t size); > + > + bool store_regset (struct regcache *regcache, int regnum, int note, > + const struct regset *regset, void *regs, size_t size); > +#endif > + > protected: > /* Wrapper versions of the above helpers which accept a register set > type such as 'struct reg' or 'struct fpreg'. */ > @@ -172,6 +185,35 @@ class fbsd_nat_target : public inf_ptrace_target > return store_register_set (regcache, regnum, fetch_op, store_op, regset, > ®s, sizeof (regs)); > } > + > +#ifdef PT_GETREGSET > + /* Helper routine for use in read_description in subclasses. This > + routine checks if the register set for the specified NOTE is > + present for a given PTID. If the register set is present, the > + the size of the register set is returned. If the register set is > + not present, zero is returned. */ > + > + bool have_regset (ptid_t ptid, int note); > + > + /* Wrapper versions of the PT_GETREGSET and PT_REGSET helpers which > + accept a register set type. */ > + > + template > + bool fetch_regset (struct regcache *regcache, int regnum, int note, > + const struct regset *regset) > + { > + Regset regs; > + return fetch_regset (regcache, regnum, note, regset, ®s, sizeof (regs)); > + } > + > + template > + bool store_regset (struct regcache *regcache, int regnum, int note, > + const struct regset *regset) > + { > + Regset regs; > + return store_regset (regcache, regnum, note, regset, ®s, sizeof (regs)); > + } > +#endif > }; > > /* Fetch the signal information for PTID and store it in *SIGINFO.