1 /* Native-dependent code for GNU/Linux x86-64.
3 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
5 Contributed by Jiri Smid, SuSE Labs.
7 This file is part of GDB.
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 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
29 #include "gdb_assert.h"
30 #include "gdb_string.h"
31 #include <sys/ptrace.h>
32 #include <sys/debugreg.h>
33 #include <sys/syscall.h>
34 #include <sys/procfs.h>
37 /* Prototypes for supply_gregset etc. */
40 #include "x86-64-tdep.h"
42 /* The register sets used in GNU/Linux ELF core-dumps are identical to
43 the register sets used by `ptrace'. The corresponding types are
44 `elf_gregset_t' for the general-purpose registers (with
45 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
46 for the floating-point registers. */
48 /* Mapping between the general-purpose registers in `struct user'
49 format and GDB's register array layout. */
60 /* Which ptrace request retrieves which registers?
61 These apply to the corresponding SET requests as well. */
63 #define GETREGS_SUPPLIES(regno) \
64 (0 <= (regno) && (regno) < X86_64_NUM_GREGS)
66 #define GETFPREGS_SUPPLIES(regno) \
67 (FP0_REGNUM <= (regno) && (regno) <= MXCSR_REGNUM)
70 /* Transfering the general-purpose registers between GDB, inferiors
73 /* Fill GDB's register array with the general-purpose register values
77 supply_gregset (elf_gregset_t
*gregsetp
)
79 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
82 for (i
= 0; i
< X86_64_NUM_GREGS
; i
++)
83 supply_register (i
, regp
+ regmap
[i
]);
86 /* Fill register REGNO (if it is a general-purpose register) in
87 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
88 do this for all registers. */
91 fill_gregset (elf_gregset_t
*gregsetp
, int regno
)
93 elf_greg_t
*regp
= (elf_greg_t
*) gregsetp
;
96 for (i
= 0; i
< X86_64_NUM_GREGS
; i
++)
97 if (regno
== -1 || regno
== i
)
98 regcache_collect (i
, regp
+ regmap
[i
]);
101 /* Fetch all general-purpose registers from process/thread TID and
102 store their values in GDB's register array. */
109 if (ptrace (PTRACE_GETREGS
, tid
, 0, (long) ®s
) < 0)
110 perror_with_name ("Couldn't get registers");
112 supply_gregset (®s
);
115 /* Store all valid general-purpose registers in GDB's register array
116 into the process/thread specified by TID. */
119 store_regs (int tid
, int regno
)
123 if (ptrace (PTRACE_GETREGS
, tid
, 0, (long) ®s
) < 0)
124 perror_with_name ("Couldn't get registers");
126 fill_gregset (®s
, regno
);
128 if (ptrace (PTRACE_SETREGS
, tid
, 0, (long) ®s
) < 0)
129 perror_with_name ("Couldn't write registers");
133 /* Transfering floating-point registers between GDB, inferiors and cores. */
135 /* Fill GDB's register array with the floating-point and SSE register
136 values in *FPREGSETP. */
139 supply_fpregset (elf_fpregset_t
*fpregsetp
)
141 x86_64_supply_fxsave ((char *) fpregsetp
);
144 /* Fill register REGNUM (if it is a floating-point or SSE register) in
145 *FPREGSETP with the value in GDB's register array. If REGNUM is
146 -1, do this for all registers. */
149 fill_fpregset (elf_fpregset_t
*fpregsetp
, int regnum
)
151 x86_64_fill_fxsave ((char *) fpregsetp
, regnum
);
154 /* Fetch all floating-point registers from process/thread TID and store
155 thier values in GDB's register array. */
158 fetch_fpregs (int tid
)
160 elf_fpregset_t fpregs
;
162 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (long) &fpregs
) < 0)
163 perror_with_name ("Couldn't get floating point status");
165 supply_fpregset (&fpregs
);
168 /* Store all valid floating-point registers in GDB's register array
169 into the process/thread specified by TID. */
172 store_fpregs (int tid
, int regno
)
174 elf_fpregset_t fpregs
;
176 if (ptrace (PTRACE_GETFPREGS
, tid
, 0, (long) &fpregs
) < 0)
177 perror_with_name ("Couldn't get floating point status");
179 fill_fpregset (&fpregs
, regno
);
181 if (ptrace (PTRACE_SETFPREGS
, tid
, 0, (long) &fpregs
) < 0)
182 perror_with_name ("Couldn't write floating point status");
186 /* Transferring arbitrary registers between GDB and inferior. */
188 /* Fetch register REGNO from the child process. If REGNO is -1, do
189 this for all registers (including the floating point and SSE
193 fetch_inferior_registers (int regno
)
197 /* GNU/Linux LWP ID's are process ID's. */
198 tid
= TIDGET (inferior_ptid
);
200 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
209 if (GETREGS_SUPPLIES (regno
))
215 if (GETFPREGS_SUPPLIES (regno
))
221 internal_error (__FILE__
, __LINE__
,
222 "Got request for bad register number %d.", regno
);
225 /* Store register REGNO back into the child process. If REGNO is -1,
226 do this for all registers (including the floating-point and SSE
230 store_inferior_registers (int regno
)
234 /* GNU/Linux LWP ID's are process ID's. */
235 tid
= TIDGET (inferior_ptid
);
237 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
241 store_regs (tid
, regno
);
242 store_fpregs (tid
, regno
);
246 if (GETREGS_SUPPLIES (regno
))
248 store_regs (tid
, regno
);
252 if (GETFPREGS_SUPPLIES (regno
))
254 store_fpregs (tid
, regno
);
258 internal_error (__FILE__
, __LINE__
,
259 "Got request to store bad register number %d.", regno
);
264 x86_64_linux_dr_get (int regnum
)
269 /* FIXME: kettenis/2001-01-29: It's not clear what we should do with
270 multi-threaded processes here. For now, pretend there is just
272 tid
= PIDGET (inferior_ptid
);
274 /* FIXME: kettenis/2001-03-27: Calling perror_with_name if the
275 ptrace call fails breaks debugging remote targets. The correct
276 way to fix this is to add the hardware breakpoint and watchpoint
277 stuff to the target vectore. For now, just return zero if the
278 ptrace call fails. */
280 value
= ptrace (PT_READ_U
, tid
,
281 offsetof (struct user
, u_debugreg
[regnum
]), 0);
284 perror_with_name ("Couldn't read debug register");
293 x86_64_linux_dr_set (int regnum
, unsigned long value
)
297 /* FIXME: kettenis/2001-01-29: It's not clear what we should do with
298 multi-threaded processes here. For now, pretend there is just
300 tid
= PIDGET (inferior_ptid
);
303 ptrace (PT_WRITE_U
, tid
, offsetof (struct user
, u_debugreg
[regnum
]), value
);
305 perror_with_name ("Couldn't write debug register");
309 x86_64_linux_dr_set_control (unsigned long control
)
311 x86_64_linux_dr_set (DR_CONTROL
, control
);
315 x86_64_linux_dr_set_addr (int regnum
, CORE_ADDR addr
)
317 gdb_assert (regnum
>= 0 && regnum
<= DR_LASTADDR
- DR_FIRSTADDR
);
319 x86_64_linux_dr_set (DR_FIRSTADDR
+ regnum
, addr
);
323 x86_64_linux_dr_reset_addr (int regnum
)
325 gdb_assert (regnum
>= 0 && regnum
<= DR_LASTADDR
- DR_FIRSTADDR
);
327 x86_64_linux_dr_set (DR_FIRSTADDR
+ regnum
, 0L);
331 x86_64_linux_dr_get_status (void)
333 return x86_64_linux_dr_get (DR_STATUS
);
This page took 0.035678 seconds and 4 git commands to generate.