]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/sh-netbsd-nat.c
Re: PR31692, objdump fails .debug_info size check
[thirdparty/binutils-gdb.git] / gdb / sh-netbsd-nat.c
1 /* Native-dependent code for NetBSD/sh.
2
3 Copyright (C) 2002-2024 Free Software Foundation, Inc.
4
5 Contributed by Wasabi Systems, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "inferior.h"
23
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
27
28 #include "sh-tdep.h"
29 #include "inf-ptrace.h"
30 #include "netbsd-nat.h"
31 #include "regcache.h"
32
33 struct sh_nbsd_nat_target final : public nbsd_nat_target
34 {
35 void fetch_registers (struct regcache *, int) override;
36 void store_registers (struct regcache *, int) override;
37 };
38
39 static sh_nbsd_nat_target the_sh_nbsd_nat_target;
40
41 /* Determine if PT_GETREGS fetches this register. */
42 #define GETREGS_SUPPLIES(gdbarch, regno) \
43 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \
44 || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \
45 || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \
46 || (regno) == SR_REGNUM)
47
48 /* Sizeof `struct reg' in <machine/reg.h>. */
49 #define SHNBSD_SIZEOF_GREGS (21 * 4)
50
51 void
52 sh_nbsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
53 {
54 pid_t pid = regcache->ptid ().pid ();
55 int lwp = regcache->ptid ().lwp ();
56
57 if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno))
58 {
59 struct reg inferior_registers;
60
61 if (ptrace (PT_GETREGS, pid,
62 (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1)
63 perror_with_name (_("Couldn't get registers"));
64
65 sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno,
66 (char *) &inferior_registers,
67 SHNBSD_SIZEOF_GREGS);
68
69 if (regno != -1)
70 return;
71 }
72 }
73
74 void
75 sh_nbsd_nat_target::store_registers (struct regcache *regcache, int regno)
76 {
77 pid_t pid = regcache->ptid ().pid ();
78 int lwp = regcache->ptid ().lwp ();
79
80 if (regno == -1 || GETREGS_SUPPLIES (regcache->arch (), regno))
81 {
82 struct reg inferior_registers;
83
84 if (ptrace (PT_GETREGS, pid,
85 (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1)
86 perror_with_name (_("Couldn't get registers"));
87
88 sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno,
89 (char *) &inferior_registers,
90 SHNBSD_SIZEOF_GREGS);
91
92 if (ptrace (PT_SETREGS, pid,
93 (PTRACE_TYPE_ARG3) &inferior_registers, lwp) == -1)
94 perror_with_name (_("Couldn't set registers"));
95
96 if (regno != -1)
97 return;
98 }
99 }
100
101 void _initialize_shnbsd_nat ();
102 void
103 _initialize_shnbsd_nat ()
104 {
105 add_inf_child_target (&the_sh_nbsd_nat_target);
106 }