From patchwork Sat Feb 1 00:06:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 37636 Received: (qmail 33793 invoked by alias); 1 Feb 2020 00:07:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33781 invoked by uid 89); 1 Feb 2020 00:07:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT autolearn=ham version=3.3.1 spammy= X-HELO: esa2.hgst.iphmx.com Received: from esa2.hgst.iphmx.com (HELO esa2.hgst.iphmx.com) (68.232.143.124) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 01 Feb 2020 00:07:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580515655; x=1612051655; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=ZQ8wtlFcdK5PW76ciESJIz8ptUflMS9PX/3ujjIFUA4=; b=SqFq+3rjyK/aAqCLbOrsjxKM/6IkYMK9IKSwyT6IrY6Q3iLGGSfwKIGi czmb2V2ULSKood6Un2MHtOjIqY2XzOHc6cv2hLocXy8XHzhi4oM+aYBQT aUyyf+SoS/8kYsE9BMK4laIUI4sI0KJ2gGTGgtjLVUDfzHkg9bOYPymbb 66gofMDcyrQtxyqaLqLfcfze+ReAwjAJggGKbx0d4q3Kfl9GcwlfQloz6 5xJVV8Ivxt8DHOu91MW6pi0uRPYMoli2T3YhEPkePWBxib8EkrRI+JKuE PKf8gfPlyE6e7Q9WQhKGlTV3tGEdg4fsiN4/kpg+mMYytH47776+gBRQ5 g==; IronPort-SDR: OYv1MM1GxFAGU113uHWXsFPkNeEAjH+h6fLGuyGokoVsxm/DRSLPsMvwgYqJh1yozCX8CP4X1v kDAl9uSZ1XnZPuhbd9CXzANBWTAt0NgcyA83455RGb60rZPFrKa6qZNI5SQgQco6HcCA0fZU7T pgF3PAhjXfTsozlrUExK2Y6hcm+0vgLnpQc7dXFf5OWbjMHX973H1VXjhGu8/Pqq+IKoQ6k2Rf xn8DznFIPPznororsJd8erON6ZonSjYDKCA77pO1Jvm8J7h8QyqrYlPIk9B32zWuAMqPDUyGKN SMw= Received: from mail-dm6nam12lp2174.outbound.protection.outlook.com (HELO NAM12-DM6-obe.outbound.protection.outlook.com) ([104.47.59.174]) by ob1.hgst.iphmx.com with ESMTP; 01 Feb 2020 08:07:31 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ko6ornymo3tee93jvybbFm1ExJWaOAhHLlB4HoQywtit0dTTjFRo/ZaciTaddaNfK9L7NzbqZUiIT44NxPizfHGaYP4NgRkkDfwVQDAb1DY6uohQuKRpBdwCFHAx9N1QXh3/Z45hEaOZ2ZOKyZ3poW4DBcGd4ZdLKoq0NrktBkuGSeOT5gG2BwfXrjrhZTT2yjQ0Sd56sNu8iKMQ0/nfdsCZ2zZ4Ng5E2JGjTgHTncBoQhiegT3xSvnYXUypNJJ2hiXFZQLvqeLipioIuRV4SwJ64FA9MwhQH7JPf//H4K+zgrRGoZIFU/bKpgsL574mTGQGSW+BT3DziIjAIjYKFg== 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-SenderADCheck; bh=97oWzqmQcQxgrn203RQag69WjXjGMfwMhnQLNUuzs4Q=; b=YagKykosYZWYvm6rrLKE2b7G2uaaiAf1eORLk0vnPnhpYZtf72G9SAld7LJdS6GaYiSq2+JkqaIT+xTacm0Gv+ldgm1Qyh88KVq4VcLlVdH+Iwq3uruIDRxdtfYR2FqibhHE04xXpH3EwwXHaxSkk4vr+7ST2aqKC8oXOcr/86KOxYnXn3jzBqVIpdJ4gETbgUJxnPdiYeU20Z7iVS/kWplhPgJ9GFtWIlswjEtasLFsFEKleBR4BW+xyKSva3Y4CwEptxxLAJJdJu9rk9C6iJJinWghPvJB72MyxmktuLa/hPxzkbvA2A9RlLNVx82p1/sgpy5s+H7/3jV/bBK0Pg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=97oWzqmQcQxgrn203RQag69WjXjGMfwMhnQLNUuzs4Q=; b=XVczepVChmQ6/leFD4lJVR5Ttr6gcu8RysCiS9JRKT6hgNUFjNHRlR2TJadEpxm5AbqHGyQLFLZFT5MwwtPhEpGDNvevGduSvJb5gwZKx4bVbqTvpfXJyE0+o9IU/Fa4K9dek5JvKY84EcSSDY2ocb2KKFX5H5zQgHdbc/igeA4= Received: from BY5PR04MB6980.namprd04.prod.outlook.com (10.186.134.11) by BY5PR04MB6581.namprd04.prod.outlook.com (52.135.41.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.29; Sat, 1 Feb 2020 00:06:56 +0000 Received: from BY5PR04MB6980.namprd04.prod.outlook.com ([fe80::d068:7819:b5cf:353]) by BY5PR04MB6980.namprd04.prod.outlook.com ([fe80::d068:7819:b5cf:353%5]) with mapi id 15.20.2686.028; Sat, 1 Feb 2020 00:06:56 +0000 From: "Maciej W. Rozycki" To: "gdb-patches@sourceware.org" CC: Jim Wilson , Andrew Burgess , Palmer Dabbelt , Tom Tromey , "guoren@kernel.org" , "lifang_xia@c-sky.com" , "yunhai_shang@c-sky.com" , "jiangshuai_li@c-sky.com" Subject: [PATCH v4 2/3] RISC-V/Linux/native: Factor out target description determination Date: Sat, 1 Feb 2020 00:06:56 +0000 Message-ID: References: In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=macro@wdc.com; x-ms-exchange-transport-forked: True wdcipoutbound: EOP-TRUE x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-messagedata: inwSDm0VpU7GVFZho0/XsMTWhf2di6Qu4D89SkQdt24NujDqGDXoU01NMPZkrXwVbbnZxwDd08HQOScIyRl/oxOknfzyd6AiPtcAUMP4JPolf3/6y3kkKmHNr55XwR7qEKjm43KLyE44iSALMWSqpA== Content-ID: <11E08015BE3A614F9A8F455DEABBB236@namprd04.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3zCxutnV+1MuAPpV3XHJSVF6IJ72WOUpuuZewAFDjDpVX3946VCGYq/YRv0qi2FN In preparation for RISC-V/Linux `gdbserver' support factor out parts of native target description determination code that can be shared between the programs. gdb/ * nat/riscv-linux-tdesc.h: New file. * nat/riscv-linux-tdesc.c: New file, taking code from... * riscv-linux-nat.c (riscv_linux_nat_target::read_description): ... here. * configure.nat : Add nat/riscv-linux-tdesc.o to NATDEPFILES. --- No changes from v3. Changes from v2: - Carry the change to the FGR reference over from 1/3. New change in v2. --- gdb/configure.nat | 3 + gdb/nat/riscv-linux-tdesc.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ gdb/nat/riscv-linux-tdesc.h | 27 ++++++++++++++ gdb/riscv-linux-nat.c | 51 +-------------------------- 4 files changed, 115 insertions(+), 49 deletions(-) gdb-riscv-linux-nat-tdesc.diff Index: binutils-gdb/gdb/configure.nat =================================================================== --- binutils-gdb.orig/gdb/configure.nat +++ binutils-gdb/gdb/configure.nat @@ -276,7 +276,8 @@ case ${gdb_host} in ;; riscv*) # Host: RISC-V, running Linux - NATDEPFILES="${NATDEPFILES} riscv-linux-nat.o" + NATDEPFILES="${NATDEPFILES} riscv-linux-nat.o \ + nat/riscv-linux-tdesc.o" ;; s390) # Host: S390, running Linux Index: binutils-gdb/gdb/nat/riscv-linux-tdesc.c =================================================================== --- /dev/null +++ binutils-gdb/gdb/nat/riscv-linux-tdesc.c @@ -0,0 +1,83 @@ +/* GNU/Linux/RISC-V native target description support for GDB. + Copyright (C) 2020 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "gdbsupport/common-defs.h" + +#include "gdb_proc_service.h" +#include "arch/riscv.h" +#include "elf/common.h" +#include "nat/gdb_ptrace.h" +#include "nat/riscv-linux-tdesc.h" + +#include + +/* Work around glibc header breakage causing ELF_NFPREG not to be usable. */ +#ifndef NFPREG +# define NFPREG 33 +#endif + +/* Determine XLEN and FLEN and return a corresponding target description. */ + +const struct target_desc * +riscv_linux_read_description (int tid) +{ + struct riscv_gdbarch_features features; + elf_fpregset_t regs; + int flen; + + /* Figuring out xlen is easy. */ + features.xlen = sizeof (elf_greg_t); + + /* Start with no f-registers. */ + features.flen = 0; + + /* How much worth of f-registers can we fetch if any? */ + for (flen = sizeof (regs.__f.__f[0]); ; flen *= 2) + { + size_t regset_size; + struct iovec iov; + + /* Regsets have a uniform slot size, so we count FSCR like + an FP data register. */ + regset_size = ELF_NFPREG * flen; + if (regset_size > sizeof (regs)) + break; + + iov.iov_base = ®s; + iov.iov_len = regset_size; + if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, + (PTRACE_TYPE_ARG3) &iov) == -1) + { + switch (errno) + { + case EINVAL: + continue; + case EIO: + break; + default: + perror_with_name (_("Couldn't get registers")); + break; + } + } + else + features.flen = flen; + break; + } + + return riscv_create_target_description (features); +} Index: binutils-gdb/gdb/nat/riscv-linux-tdesc.h =================================================================== --- /dev/null +++ binutils-gdb/gdb/nat/riscv-linux-tdesc.h @@ -0,0 +1,27 @@ +/* GNU/Linux/RISC-V native target description support for GDB. + Copyright (C) 2020 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef NAT_RISCV_LINUX_TDESC_H +#define NAT_RISCV_LINUX_TDESC_H + +struct target_desc; + +/* Return a target description for the LWP identified by TID. */ +const struct target_desc *riscv_linux_read_description (int tid); + +#endif /* NAT_RISCV_LINUX_TDESC_H */ Index: binutils-gdb/gdb/riscv-linux-nat.c =================================================================== --- binutils-gdb.orig/gdb/riscv-linux-nat.c +++ binutils-gdb/gdb/riscv-linux-nat.c @@ -22,10 +22,11 @@ #include "linux-nat.h" #include "riscv-tdep.h" #include "inferior.h" -#include "target-descriptions.h" #include "elf/common.h" +#include "nat/riscv-linux-tdesc.h" + #include /* Work around glibc header breakage causing ELF_NFPREG not to be usable. */ @@ -200,53 +201,7 @@ fill_fpregset (const struct regcache *re const struct target_desc * riscv_linux_nat_target::read_description () { - struct riscv_gdbarch_features features; - elf_fpregset_t regs; - int flen; - int tid; - - /* Figuring out xlen is easy. */ - features.xlen = sizeof (elf_greg_t); - - tid = inferior_ptid.lwp (); - - /* Start with no f-registers. */ - features.flen = 0; - - /* How much worth of f-registers can we fetch if any? */ - for (flen = sizeof (regs.__f.__f[0]); ; flen *= 2) - { - size_t regset_size; - struct iovec iov; - - /* Regsets have a uniform slot size, so we count FSCR like - an FP data register. */ - regset_size = ELF_NFPREG * flen; - if (regset_size > sizeof (regs)) - break; - - iov.iov_base = ®s; - iov.iov_len = regset_size; - if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, - (PTRACE_TYPE_ARG3) &iov) == -1) - { - switch (errno) - { - case EINVAL: - continue; - case EIO: - break; - default: - perror_with_name (_("Couldn't get registers")); - break; - } - } - else - features.flen = flen; - break; - } - - return riscv_create_target_description (features); + return riscv_linux_read_description (inferior_ptid.lwp ()); } /* Fetch REGNUM (or all registers if REGNUM == -1) from the target