From patchwork Wed Jan 29 18:13:44 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: 37613 Received: (qmail 10267 invoked by alias); 29 Jan 2020 18:13:51 -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 10229 invoked by uid 89); 29 Jan 2020 18:13:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.0 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: esa1.hgst.iphmx.com Received: from esa1.hgst.iphmx.com (HELO esa1.hgst.iphmx.com) (68.232.141.245) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Jan 2020 18:13:48 +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=1580321628; x=1611857628; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=14ZG2J1svUO2EezIqDQBeuyUZe0VaNyOcJpqPdD4Be4=; b=ermwiTU5upGZ8274HJozyfy7hkkCTMHRP0LLKOpryuH1aCa05/0GYbvG iV3hxy9UPz48HeDsEGtpP5aztraOyQK7cybeqKimRyxKLITXr6EMg0tM5 p7zEJEFuxAwkSx6lB++8fBswSFXyhPS32uQadXc8D2f3gTZxUUC9GOMgI Qtbrhx4CJr3ZOJHgZaR82hhbMwkbUFFRptMv/WO/5RimpT8UTtngjeE4q eAd4nA1FDZQTGp0LdeZ2j6RdJ1YVTdTDTCQc1ojBB5cgu3r91Lu6x42Yy MPsCdT0WhC4SCQuv9ZTxWTTQW52h74KNzPvPXaoPb3c1FF7lwN5ZWXTBL A==; IronPort-SDR: 52oiYsux9Ss/4QnKe1fudnFfdmz7FlGICJznBgDYoiUyxhCfc2lKB5irpzaTzxpWyqKkDkO0E3 C5I2S9I7V/VtOazHuzB4gqctsFwqV2k8eTEJPHVKceYqHvPMRCYKawctjfJ92Ud177PV3dYXgs 1uxgVRso+sda9tzuVDBuy6BOmzQHUPyCEKHjbPOwTmcgeL41zqV03BqMv8qaysza1ugBM1BHiO TOMkst/tZZjew0I913XcUhbJsmE/tZAMoH3wZl80sJJhbZ0kPpUGRrQ46V/F7ui0kaP2KH4ywE Fz4= Received: from mail-dm6nam11lp2176.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.176]) by ob1.hgst.iphmx.com with ESMTP; 30 Jan 2020 02:13:45 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=idS6qXn0O2kCPFr1/2KU3XD0+ENB30gH9XDvqpCYYEhJKkErRnQpATmrySZjR4rvVLZJ4n0K9Dg3OW9Of0UpzFYs7nQrbUHq59nYHOJNMenDNTmA18bhmS8E+dWaY2tNnWgFvohsVwfgAe8JusHLeXoNwHEGbFIuYehmh46pN9kN5Odk8t1ZmNiV4y1CcnA9lNOZ/R2JMWiWrtkMMLkYowpi4qvHug8XkpRpnA/ORtFfIzPeTv9PaY34VIU6BTqn4cAHEqpRcOTAcLCysHL3wiBEm78JvpFBYc+QNIHBjGabaKjaV4XbRQWQ0003VNdEZf8Ln6OYCRiZZbxvHYLPfg== 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=W+fzTkaCo33FpB4rb6G+rS2A/SoItS+jGk6RDdnmTRA=; b=lruEz2LpOAE7JyxH0SX67yKgmhrlY+cbFvXy2GLPnQb1UgleTOp3cDE1ouXvPoGrL7AHtFUYq3HK+/F7tVEU22IyRVFWDgiFM/VNbnAWubP6YgVefn5n5F5zm11SxFcNQ+b4sa89HGiJaE7/EzLVUmAzqlloonF13X/vkhl1yAeBY/L0X32qmKxCIlzupEqQ+d6aqs1DJTfzRXOVgxWylQy7uMidDnZaX3RKp1hhuBOjp1LcWKxnCWpGqg7kqorRqu4vIrBUKYP56dyCsS28bniIt1g4OFxgX8aKVSDrxjwCA0HL+KmnqoHpRVij3ad7yPcAQD8wS4i+RNsr6BBuyA== 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=W+fzTkaCo33FpB4rb6G+rS2A/SoItS+jGk6RDdnmTRA=; b=UoM6SBlk0KYyWuUh3il8RO+E/6h8OVZsPzOMrXxnJQH7gs+6hjQRVTWXY8/jB8jQjGhT5KcnVrLtwxTKLrzMAhy5efB6hWV0Rc7Oh3I0KQ8XbsxGa3dQKLpdrfSgTVTfPf7JRosuGe/LaQPORgSVBkF91zXi7Xttw90GL3ChvXI= Received: from BY5PR04MB6980.namprd04.prod.outlook.com (10.186.134.11) by BY5PR04MB6328.namprd04.prod.outlook.com (52.133.250.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.20; Wed, 29 Jan 2020 18:13:45 +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.2665.027; Wed, 29 Jan 2020 18:13:45 +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 v2 2/3] RISC-V/Linux/native: Factor out target description determination Date: Wed, 29 Jan 2020 18:13:44 +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: Ln+akzmlNGhDoWgQG8oc2FQvUPDGf4qsJWn9eMIJWud/CL7l+IL5VNvB3H2bo7D5soVs4GdaEmpXjvzAWtFNyA7dUzsGgHs7qCJMw7ct361s+EOFB1/xg0ff7C+7Mqc3b+s/I4d2qfhUgBx76osiAQ== Content-ID: <9A27CC4435C55B4989C68AC2EAF8FF72@namprd04.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ioaLcHRSj+CbJEskdRbT+Tw0ahVPp+8RvCIhbUnKGbeE0ChyIHlFMo99bFyNR0Cu 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. --- New change in v2. --- gdb/configure.nat | 3 + gdb/nat/riscv-linux-tdesc.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ gdb/nat/riscv-linux-tdesc.h | 27 ++++++++++++++ gdb/riscv-linux-nat.c | 50 +------------------------- 4 files changed, 114 insertions(+), 48 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,82 @@ +/* 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 FGR. */ + 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. */ @@ -196,52 +197,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 FGR. */ - 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