mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
d1c9b20ff9
In preparation for adding the RISC-V gdbserver, this commit restructures the API for looking up target descriptions. The current API is riscv_create_target_description, which creates a target description from a riscv_gdbarch_features, but also caches the created target descriptions so that for a given features object we always get back the same target description object. This is important for GDB due to the way gdbarch objects are reused. As the same target description is always returned to GDB, and can be returned multiple times, it is returned as a const, however, the current cache actually stores a non-const target description. This is improved in this patch so that the cache holds a const target description. For gdbsever, this caching of the target descriptions is not needed, the gdbserver looks up one target description to describe the target it is actually running on and that is it. Further the gdbserver actually needs to modify the target description that is looked up, so for the gdbsever, returning a const target description is not acceptable. This commit aims to address this by creating two parallel target description APIs, on is the old riscv_create_target_description, however, this no longer performs any caching, and just creates a new target description, and returns it as non-const. The second API is riscv_lookup_target_description, this one performs the caching, and calls riscv_create_target_description to create a target description when needed. In order to make sure the correct API is used in the correct place I have guarded the code using the GDBSERVER define. For GDB the riscv_create_target_description is static, and not generally usable throughout GDB, only the lookup API is global. In gdbserver, the lookup functions, and the cache are not defined or created at all, only the riscv_create_target_description API is available. There should be no user visible changes after this commit. gdb/ChangeLog: * arch/riscv.c (struct riscv_gdbarch_features_hasher): Only define if GDBSERVER is not defined. (riscv_tdesc_cache): Likewise, also store const target_desc. (STATIC_IN_GDB): Define. (riscv_create_target_description): Update declaration with STATIC_IN_GDB. (riscv_lookup_target_description): New function, only define if GDBSERVER is not defined. * arch/riscv.h (riscv_create_target_description): Declare only when GDBSERVER is defined. (riscv_lookup_target_description): New declaration when GDBSERVER is not defined. * nat/riscv-linux-tdesc.c (riscv_linux_read_description): Rename to... (riscv_linux_read_features): ...this, and return riscv_gdbarch_features instead of target_desc. * nat/riscv-linux-tdesc.h: Include 'arch/riscv.h'. (riscv_linux_read_description): Rename to... (riscv_linux_read_features): ...this. * riscv-linux-nat.c (riscv_linux_nat_target::read_description): Update to use riscv_gdbarch_features and riscv_lookup_target_description. * riscv-tdep.c (riscv_find_default_target_description): Use riscv_lookup_target_description instead of riscv_create_target_description.
84 lines
2.1 KiB
C
84 lines
2.1 KiB
C
/* 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 <http://www.gnu.org/licenses/>. */
|
|
|
|
#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 <sys/uio.h>
|
|
|
|
/* Work around glibc header breakage causing ELF_NFPREG not to be usable. */
|
|
#ifndef NFPREG
|
|
# define NFPREG 33
|
|
#endif
|
|
|
|
/* See nat/riscv-linux-tdesc.h. */
|
|
|
|
struct riscv_gdbarch_features
|
|
riscv_linux_read_features (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 features;
|
|
}
|