]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/ppc-fbsd-nat.c
PR31692, objdump fails .debug_info size check
[thirdparty/binutils-gdb.git] / gdb / ppc-fbsd-nat.c
CommitLineData
dc18f110
AT
1/* Native-dependent code for PowerPC's running FreeBSD, for GDB.
2
1d506c26 3 Copyright (C) 2013-2024 Free Software Foundation, Inc.
dc18f110
AT
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
dc18f110
AT
20#include "gdbcore.h"
21#include "inferior.h"
22#include "regcache.h"
23
dc18f110
AT
24#include <sys/types.h>
25#include <sys/procfs.h>
26#include <sys/ptrace.h>
27#include <sys/signal.h>
28#include <machine/frame.h>
29#include <machine/pcb.h>
30#include <machine/reg.h>
31
32#include "fbsd-nat.h"
33#include "gregset.h"
34#include "ppc-tdep.h"
03b62bbb 35#include "ppc-fbsd-tdep.h"
dc18f110
AT
36#include "inf-ptrace.h"
37#include "bsd-kvm.h"
38
f6ac5f3d
PA
39struct ppc_fbsd_nat_target final : public fbsd_nat_target
40{
41 void fetch_registers (struct regcache *, int) override;
42 void store_registers (struct regcache *, int) override;
43};
44
45static ppc_fbsd_nat_target the_ppc_fbsd_nat_target;
46
dc18f110
AT
47/* Fill GDB's register array with the general-purpose register values
48 in *GREGSETP. */
49
50void
51supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
52{
53 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
54
55 ppc_supply_gregset (regset, regcache, -1, gregsetp, sizeof (*gregsetp));
56}
57
58/* Fill register REGNO (if a gpr) in *GREGSETP with the value in GDB's
59 register array. If REGNO is -1 do it for all registers. */
60
61void
62fill_gregset (const struct regcache *regcache,
63 gdb_gregset_t *gregsetp, int regno)
64{
65 const struct regset *regset = ppc_fbsd_gregset (sizeof (long));
66
67 if (regno == -1)
68 memset (gregsetp, 0, sizeof (*gregsetp));
69 ppc_collect_gregset (regset, regcache, regno, gregsetp, sizeof (*gregsetp));
70}
71
72/* Fill GDB's register array with the floating-point register values
73 in *FPREGSETP. */
74
75void
76supply_fpregset (struct regcache *regcache, const gdb_fpregset_t * fpregsetp)
77{
78 const struct regset *regset = ppc_fbsd_fpregset ();
79
80 ppc_supply_fpregset (regset, regcache, -1,
81 fpregsetp, sizeof (*fpregsetp));
82}
83
84/* Fill register REGNO in *FGREGSETP with the value in GDB's
85 register array. If REGNO is -1 do it for all registers. */
86
87void
88fill_fpregset (const struct regcache *regcache,
89 gdb_fpregset_t *fpregsetp, int regno)
90{
91 const struct regset *regset = ppc_fbsd_fpregset ();
92
93 ppc_collect_fpregset (regset, regcache, regno,
94 fpregsetp, sizeof (*fpregsetp));
95}
96
97/* Returns true if PT_GETFPREGS fetches this register. */
98
99static int
100getfpregs_supplies (struct gdbarch *gdbarch, int regno)
101{
08106042 102 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
dc18f110
AT
103
104 /* FIXME: jimb/2004-05-05: Some PPC variants don't have floating
105 point registers. Traditionally, GDB's register set has still
106 listed the floating point registers for such machines, so this
107 code is harmless. However, the new E500 port actually omits the
108 floating point registers entirely from the register set --- they
109 don't even have register numbers assigned to them.
110
111 It's not clear to me how best to update this code, so this assert
112 will alert the first person to encounter the NetBSD/E500
113 combination to the problem. */
114
115 gdb_assert (ppc_floating_point_unit_p (gdbarch));
116
117 return ((regno >= tdep->ppc_fp0_regnum
118 && regno < tdep->ppc_fp0_regnum + ppc_num_fprs)
119 || regno == tdep->ppc_fpscr_regnum);
120}
121
122/* Fetch register REGNO from the child process. If REGNO is -1, do it
123 for all registers. */
124
f6ac5f3d
PA
125void
126ppc_fbsd_nat_target::fetch_registers (struct regcache *regcache, int regno)
dc18f110
AT
127{
128 gdb_gregset_t regs;
e38504b3 129 pid_t pid = regcache->ptid ().lwp ();
dc18f110 130
bcc0c096 131 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
dc18f110
AT
132 perror_with_name (_("Couldn't get registers"));
133
134 supply_gregset (regcache, &regs);
135
ac7936df 136 if (regno == -1 || getfpregs_supplies (regcache->arch (), regno))
dc18f110
AT
137 {
138 const struct regset *fpregset = ppc_fbsd_fpregset ();
139 gdb_fpregset_t fpregs;
140
bcc0c096 141 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
dc18f110
AT
142 perror_with_name (_("Couldn't get FP registers"));
143
144 ppc_supply_fpregset (fpregset, regcache, regno, &fpregs, sizeof fpregs);
145 }
146}
147
148/* Store register REGNO back into the child process. If REGNO is -1,
149 do this for all registers. */
150
f6ac5f3d
PA
151void
152ppc_fbsd_nat_target::store_registers (struct regcache *regcache, int regno)
dc18f110
AT
153{
154 gdb_gregset_t regs;
e38504b3 155 pid_t pid = regcache->ptid ().lwp ();
dc18f110 156
bcc0c096 157 if (ptrace (PT_GETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
dc18f110
AT
158 perror_with_name (_("Couldn't get registers"));
159
160 fill_gregset (regcache, &regs, regno);
161
bcc0c096 162 if (ptrace (PT_SETREGS, pid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
dc18f110
AT
163 perror_with_name (_("Couldn't write registers"));
164
ac7936df 165 if (regno == -1 || getfpregs_supplies (regcache->arch (), regno))
dc18f110
AT
166 {
167 gdb_fpregset_t fpregs;
168
bcc0c096 169 if (ptrace (PT_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
dc18f110
AT
170 perror_with_name (_("Couldn't get FP registers"));
171
172 fill_fpregset (regcache, &fpregs, regno);
173
bcc0c096 174 if (ptrace (PT_SETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1)
dc18f110
AT
175 perror_with_name (_("Couldn't set FP registers"));
176 }
177}
178
179/* Architecture specific function that reconstructs the
180 register state from PCB (Process Control Block) and supplies it
181 to REGCACHE. */
182
183static int
184ppcfbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
185{
ac7936df 186 struct gdbarch *gdbarch = regcache->arch ();
08106042 187 ppc_gdbarch_tdep *tdep = gdbarch_tdep<ppc_gdbarch_tdep> (gdbarch);
dc18f110
AT
188 int i, regnum;
189
190 /* The stack pointer shouldn't be zero. */
191 if (pcb->pcb_sp == 0)
192 return 0;
193
73e1c03f
SM
194 regcache->raw_supply (gdbarch_sp_regnum (gdbarch), &pcb->pcb_sp);
195 regcache->raw_supply (tdep->ppc_cr_regnum, &pcb->pcb_cr);
196 regcache->raw_supply (tdep->ppc_lr_regnum, &pcb->pcb_lr);
dc18f110 197 for (i = 0, regnum = tdep->ppc_gp0_regnum + 14; i < 20; i++, regnum++)
73e1c03f 198 regcache->raw_supply (regnum, &pcb->pcb_context[i]);
dc18f110
AT
199
200 return 1;
201}
202
6c265988 203void _initialize_ppcfbsd_nat ();
dc18f110 204void
6c265988 205_initialize_ppcfbsd_nat ()
dc18f110 206{
d9f719f1 207 add_inf_child_target (&the_ppc_fbsd_nat_target);
dc18f110
AT
208
209 /* Support debugging kernel virtual memory images. */
210 bsd_kvm_add_target (ppcfbsd_supply_pcb);
211}