GNU Binutils with patches for OS216
修訂 | f6480e70001df1c8151362cd4621578bcb293224 (tree) |
---|---|
時間 | 2020-02-06 02:21:12 |
作者 | Maciej W. Rozycki <macro@wdc....> |
Commiter | Maciej W. Rozycki |
RISC-V/Linux/native: Factor out target description determination
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 <linux> <riscv*>: Add nat/riscv-linux-tdesc.o to
NATDEPFILES.
@@ -1,3 +1,12 @@ | ||
1 | +2020-02-05 Maciej W. Rozycki <macro@wdc.com> | |
2 | + | |
3 | + * nat/riscv-linux-tdesc.h: New file. | |
4 | + * nat/riscv-linux-tdesc.c: New file, taking code from... | |
5 | + * riscv-linux-nat.c (riscv_linux_nat_target::read_description): | |
6 | + ... here. | |
7 | + * configure.nat <linux> <riscv*>: Add nat/riscv-linux-tdesc.o to | |
8 | + NATDEPFILES. | |
9 | + | |
1 | 10 | 2020-02-04 Andrew Burgess <andrew.burgess@embecosm.com> |
2 | 11 | |
3 | 12 | * remote-sim.c (sim_inferior_data::sim_inferior_data): Assert that |
@@ -276,7 +276,8 @@ case ${gdb_host} in | ||
276 | 276 | ;; |
277 | 277 | riscv*) |
278 | 278 | # Host: RISC-V, running Linux |
279 | - NATDEPFILES="${NATDEPFILES} riscv-linux-nat.o" | |
279 | + NATDEPFILES="${NATDEPFILES} riscv-linux-nat.o \ | |
280 | + nat/riscv-linux-tdesc.o" | |
280 | 281 | ;; |
281 | 282 | s390) |
282 | 283 | # Host: S390, running Linux |
@@ -0,0 +1,83 @@ | ||
1 | +/* GNU/Linux/RISC-V native target description support for GDB. | |
2 | + Copyright (C) 2020 Free Software Foundation, Inc. | |
3 | + | |
4 | + This file is part of GDB. | |
5 | + | |
6 | + This program is free software; you can redistribute it and/or modify | |
7 | + it under the terms of the GNU General Public License as published by | |
8 | + the Free Software Foundation; either version 3 of the License, or | |
9 | + (at your option) any later version. | |
10 | + | |
11 | + This program is distributed in the hope that it will be useful, | |
12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + GNU General Public License for more details. | |
15 | + | |
16 | + You should have received a copy of the GNU General Public License | |
17 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | + | |
19 | +#include "gdbsupport/common-defs.h" | |
20 | + | |
21 | +#include "gdb_proc_service.h" | |
22 | +#include "arch/riscv.h" | |
23 | +#include "elf/common.h" | |
24 | +#include "nat/gdb_ptrace.h" | |
25 | +#include "nat/riscv-linux-tdesc.h" | |
26 | + | |
27 | +#include <sys/uio.h> | |
28 | + | |
29 | +/* Work around glibc header breakage causing ELF_NFPREG not to be usable. */ | |
30 | +#ifndef NFPREG | |
31 | +# define NFPREG 33 | |
32 | +#endif | |
33 | + | |
34 | +/* Determine XLEN and FLEN and return a corresponding target description. */ | |
35 | + | |
36 | +const struct target_desc * | |
37 | +riscv_linux_read_description (int tid) | |
38 | +{ | |
39 | + struct riscv_gdbarch_features features; | |
40 | + elf_fpregset_t regs; | |
41 | + int flen; | |
42 | + | |
43 | + /* Figuring out xlen is easy. */ | |
44 | + features.xlen = sizeof (elf_greg_t); | |
45 | + | |
46 | + /* Start with no f-registers. */ | |
47 | + features.flen = 0; | |
48 | + | |
49 | + /* How much worth of f-registers can we fetch if any? */ | |
50 | + for (flen = sizeof (regs.__f.__f[0]); ; flen *= 2) | |
51 | + { | |
52 | + size_t regset_size; | |
53 | + struct iovec iov; | |
54 | + | |
55 | + /* Regsets have a uniform slot size, so we count FSCR like | |
56 | + an FP data register. */ | |
57 | + regset_size = ELF_NFPREG * flen; | |
58 | + if (regset_size > sizeof (regs)) | |
59 | + break; | |
60 | + | |
61 | + iov.iov_base = ®s; | |
62 | + iov.iov_len = regset_size; | |
63 | + if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, | |
64 | + (PTRACE_TYPE_ARG3) &iov) == -1) | |
65 | + { | |
66 | + switch (errno) | |
67 | + { | |
68 | + case EINVAL: | |
69 | + continue; | |
70 | + case EIO: | |
71 | + break; | |
72 | + default: | |
73 | + perror_with_name (_("Couldn't get registers")); | |
74 | + break; | |
75 | + } | |
76 | + } | |
77 | + else | |
78 | + features.flen = flen; | |
79 | + break; | |
80 | + } | |
81 | + | |
82 | + return riscv_create_target_description (features); | |
83 | +} |
@@ -0,0 +1,27 @@ | ||
1 | +/* GNU/Linux/RISC-V native target description support for GDB. | |
2 | + Copyright (C) 2020 Free Software Foundation, Inc. | |
3 | + | |
4 | + This file is part of GDB. | |
5 | + | |
6 | + This program is free software; you can redistribute it and/or modify | |
7 | + it under the terms of the GNU General Public License as published by | |
8 | + the Free Software Foundation; either version 3 of the License, or | |
9 | + (at your option) any later version. | |
10 | + | |
11 | + This program is distributed in the hope that it will be useful, | |
12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + GNU General Public License for more details. | |
15 | + | |
16 | + You should have received a copy of the GNU General Public License | |
17 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | + | |
19 | +#ifndef NAT_RISCV_LINUX_TDESC_H | |
20 | +#define NAT_RISCV_LINUX_TDESC_H | |
21 | + | |
22 | +struct target_desc; | |
23 | + | |
24 | +/* Return a target description for the LWP identified by TID. */ | |
25 | +const struct target_desc *riscv_linux_read_description (int tid); | |
26 | + | |
27 | +#endif /* NAT_RISCV_LINUX_TDESC_H */ |
@@ -22,10 +22,11 @@ | ||
22 | 22 | #include "linux-nat.h" |
23 | 23 | #include "riscv-tdep.h" |
24 | 24 | #include "inferior.h" |
25 | -#include "target-descriptions.h" | |
26 | 25 | |
27 | 26 | #include "elf/common.h" |
28 | 27 | |
28 | +#include "nat/riscv-linux-tdesc.h" | |
29 | + | |
29 | 30 | #include <sys/ptrace.h> |
30 | 31 | |
31 | 32 | /* Work around glibc header breakage causing ELF_NFPREG not to be usable. */ |
@@ -200,53 +201,7 @@ fill_fpregset (const struct regcache *regcache, prfpregset_t *fpregs, | ||
200 | 201 | const struct target_desc * |
201 | 202 | riscv_linux_nat_target::read_description () |
202 | 203 | { |
203 | - struct riscv_gdbarch_features features; | |
204 | - elf_fpregset_t regs; | |
205 | - int flen; | |
206 | - int tid; | |
207 | - | |
208 | - /* Figuring out xlen is easy. */ | |
209 | - features.xlen = sizeof (elf_greg_t); | |
210 | - | |
211 | - tid = inferior_ptid.lwp (); | |
212 | - | |
213 | - /* Start with no f-registers. */ | |
214 | - features.flen = 0; | |
215 | - | |
216 | - /* How much worth of f-registers can we fetch if any? */ | |
217 | - for (flen = sizeof (regs.__f.__f[0]); ; flen *= 2) | |
218 | - { | |
219 | - size_t regset_size; | |
220 | - struct iovec iov; | |
221 | - | |
222 | - /* Regsets have a uniform slot size, so we count FSCR like | |
223 | - an FP data register. */ | |
224 | - regset_size = ELF_NFPREG * flen; | |
225 | - if (regset_size > sizeof (regs)) | |
226 | - break; | |
227 | - | |
228 | - iov.iov_base = ®s; | |
229 | - iov.iov_len = regset_size; | |
230 | - if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET, | |
231 | - (PTRACE_TYPE_ARG3) &iov) == -1) | |
232 | - { | |
233 | - switch (errno) | |
234 | - { | |
235 | - case EINVAL: | |
236 | - continue; | |
237 | - case EIO: | |
238 | - break; | |
239 | - default: | |
240 | - perror_with_name (_("Couldn't get registers")); | |
241 | - break; | |
242 | - } | |
243 | - } | |
244 | - else | |
245 | - features.flen = flen; | |
246 | - break; | |
247 | - } | |
248 | - | |
249 | - return riscv_create_target_description (features); | |
204 | + return riscv_linux_read_description (inferior_ptid.lwp ()); | |
250 | 205 | } |
251 | 206 | |
252 | 207 | /* Fetch REGNUM (or all registers if REGNUM == -1) from the target |