| OLD | NEW |
| 1 /* Native-dependent code for SPARC. | 1 /* Native-dependent code for SPARC. |
| 2 | 2 |
| 3 Copyright (C) 2003-2005, 2007-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2003-2013 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| 11 | 11 |
| 12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 |
| 20 #include "defs.h" | 20 #include "defs.h" |
| 21 #include "inferior.h" | 21 #include "inferior.h" |
| 22 #include "regcache.h" | 22 #include "regcache.h" |
| 23 #include "target.h" | 23 #include "target.h" |
| 24 | 24 |
| 25 #include "gdb_assert.h" | 25 #include "gdb_assert.h" |
| 26 #include <signal.h> | 26 #include <signal.h> |
| 27 #include "gdb_string.h" | 27 #include <string.h> |
| 28 #include <sys/ptrace.h> | 28 #include <sys/ptrace.h> |
| 29 #include "gdb_wait.h" | 29 #include "gdb_wait.h" |
| 30 #ifdef HAVE_MACHINE_REG_H | 30 #ifdef HAVE_MACHINE_REG_H |
| 31 #include <machine/reg.h> | 31 #include <machine/reg.h> |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 #include "sparc-tdep.h" | 34 #include "sparc-tdep.h" |
| 35 #include "sparc-nat.h" | 35 #include "sparc-nat.h" |
| 36 #include "inf-ptrace.h" | 36 #include "inf-ptrace.h" |
| 37 | 37 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 #ifndef PTRACE_GETFPREGS | 75 #ifndef PTRACE_GETFPREGS |
| 76 #define PTRACE_GETFPREGS PT_GETFPREGS | 76 #define PTRACE_GETFPREGS PT_GETFPREGS |
| 77 #endif | 77 #endif |
| 78 | 78 |
| 79 #ifndef PTRACE_SETFPREGS | 79 #ifndef PTRACE_SETFPREGS |
| 80 #define PTRACE_SETFPREGS PT_SETFPREGS | 80 #define PTRACE_SETFPREGS PT_SETFPREGS |
| 81 #endif | 81 #endif |
| 82 | 82 |
| 83 /* Register set description. */ | 83 /* Register set description. */ |
| 84 const struct sparc_gregset *sparc_gregset; | 84 const struct sparc_gregset *sparc_gregset; |
| 85 const struct sparc_fpregset *sparc_fpregset; |
| 85 void (*sparc_supply_gregset) (const struct sparc_gregset *, | 86 void (*sparc_supply_gregset) (const struct sparc_gregset *, |
| 86 struct regcache *, int , const void *); | 87 struct regcache *, int , const void *); |
| 87 void (*sparc_collect_gregset) (const struct sparc_gregset *, | 88 void (*sparc_collect_gregset) (const struct sparc_gregset *, |
| 88 const struct regcache *, int, void *); | 89 const struct regcache *, int, void *); |
| 89 void (*sparc_supply_fpregset) (struct regcache *, int , const void *); | 90 void (*sparc_supply_fpregset) (const struct sparc_fpregset *, |
| 90 void (*sparc_collect_fpregset) (const struct regcache *, int , void *); | 91 » » » struct regcache *, int , const void *); |
| 92 void (*sparc_collect_fpregset) (const struct sparc_fpregset *, |
| 93 » » » » const struct regcache *, int , void *); |
| 91 int (*sparc_gregset_supplies_p) (struct gdbarch *, int); | 94 int (*sparc_gregset_supplies_p) (struct gdbarch *, int); |
| 92 int (*sparc_fpregset_supplies_p) (struct gdbarch *, int); | 95 int (*sparc_fpregset_supplies_p) (struct gdbarch *, int); |
| 93 | 96 |
| 94 /* Determine whether `gregset_t' contains register REGNUM. */ | 97 /* Determine whether `gregset_t' contains register REGNUM. */ |
| 95 | 98 |
| 96 int | 99 int |
| 97 sparc32_gregset_supplies_p (struct gdbarch *gdbarch, int regnum) | 100 sparc32_gregset_supplies_p (struct gdbarch *gdbarch, int regnum) |
| 98 { | 101 { |
| 99 /* Integer registers. */ | 102 /* Integer registers. */ |
| 100 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM) | 103 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_G7_REGNUM) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 fine when given an 1:1 LWP:thread model (such as found on | 148 fine when given an 1:1 LWP:thread model (such as found on |
| 146 GNU/Linux) but will, likely, have problems when used on an N:1 | 149 GNU/Linux) but will, likely, have problems when used on an N:1 |
| 147 (userland threads) or N:M (userland multiple LWP) model. In the | 150 (userland threads) or N:M (userland multiple LWP) model. In the |
| 148 case of the latter two, the LWP's registers do not necessarily | 151 case of the latter two, the LWP's registers do not necessarily |
| 149 belong to the selected thread (the LWP could be in the middle of | 152 belong to the selected thread (the LWP could be in the middle of |
| 150 executing the thread switch code). | 153 executing the thread switch code). |
| 151 | 154 |
| 152 These functions should instead be paramaterized with an explicit | 155 These functions should instead be paramaterized with an explicit |
| 153 object (struct regcache, struct thread_info?) into which the LWPs | 156 object (struct regcache, struct thread_info?) into which the LWPs |
| 154 registers can be written. */ | 157 registers can be written. */ |
| 155 pid = TIDGET (inferior_ptid); | 158 pid = ptid_get_lwp (inferior_ptid); |
| 156 if (pid == 0) | 159 if (pid == 0) |
| 157 pid = PIDGET (inferior_ptid); | 160 pid = ptid_get_pid (inferior_ptid); |
| 158 | 161 |
| 159 if (regnum == SPARC_G0_REGNUM) | 162 if (regnum == SPARC_G0_REGNUM) |
| 160 { | 163 { |
| 161 gdb_byte zero[8] = { 0 }; | 164 gdb_byte zero[8] = { 0 }; |
| 162 | 165 |
| 163 regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero); | 166 regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero); |
| 164 return; | 167 return; |
| 165 } | 168 } |
| 166 | 169 |
| 167 if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum)) | 170 if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum)) |
| 168 { | 171 { |
| 169 gregset_t regs; | 172 gregset_t regs; |
| 170 | 173 |
| 171 if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) | 174 if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
| 172 perror_with_name (_("Couldn't get registers")); | 175 perror_with_name (_("Couldn't get registers")); |
| 173 | 176 |
| 174 sparc_supply_gregset (sparc_gregset, regcache, -1, ®s); | 177 sparc_supply_gregset (sparc_gregset, regcache, -1, ®s); |
| 175 if (regnum != -1) | 178 if (regnum != -1) |
| 176 return; | 179 return; |
| 177 } | 180 } |
| 178 | 181 |
| 179 if (regnum == -1 || sparc_fpregset_supplies_p (gdbarch, regnum)) | 182 if (regnum == -1 || sparc_fpregset_supplies_p (gdbarch, regnum)) |
| 180 { | 183 { |
| 181 fpregset_t fpregs; | 184 fpregset_t fpregs; |
| 182 | 185 |
| 183 if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | 186 if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
| 184 perror_with_name (_("Couldn't get floating point status")); | 187 perror_with_name (_("Couldn't get floating point status")); |
| 185 | 188 |
| 186 sparc_supply_fpregset (regcache, -1, &fpregs); | 189 sparc_supply_fpregset (sparc_fpregset, regcache, -1, &fpregs); |
| 187 } | 190 } |
| 188 } | 191 } |
| 189 | 192 |
| 190 void | 193 void |
| 191 sparc_store_inferior_registers (struct target_ops *ops, | 194 sparc_store_inferior_registers (struct target_ops *ops, |
| 192 struct regcache *regcache, int regnum) | 195 struct regcache *regcache, int regnum) |
| 193 { | 196 { |
| 194 struct gdbarch *gdbarch = get_regcache_arch (regcache); | 197 struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 195 int pid; | 198 int pid; |
| 196 | 199 |
| 197 /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers | 200 /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers |
| 198 about threaded assumptions. */ | 201 about threaded assumptions. */ |
| 199 pid = TIDGET (inferior_ptid); | 202 pid = ptid_get_lwp (inferior_ptid); |
| 200 if (pid == 0) | 203 if (pid == 0) |
| 201 pid = PIDGET (inferior_ptid); | 204 pid = ptid_get_pid (inferior_ptid); |
| 202 | 205 |
| 203 if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum)) | 206 if (regnum == -1 || sparc_gregset_supplies_p (gdbarch, regnum)) |
| 204 { | 207 { |
| 205 gregset_t regs; | 208 gregset_t regs; |
| 206 | 209 |
| 207 if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) | 210 if (ptrace (PTRACE_GETREGS, pid, (PTRACE_TYPE_ARG3) ®s, 0) == -1) |
| 208 perror_with_name (_("Couldn't get registers")); | 211 perror_with_name (_("Couldn't get registers")); |
| 209 | 212 |
| 210 sparc_collect_gregset (sparc_gregset, regcache, regnum, ®s); | 213 sparc_collect_gregset (sparc_gregset, regcache, regnum, ®s); |
| 211 | 214 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 227 } | 230 } |
| 228 | 231 |
| 229 if (regnum == -1 || sparc_fpregset_supplies_p (gdbarch, regnum)) | 232 if (regnum == -1 || sparc_fpregset_supplies_p (gdbarch, regnum)) |
| 230 { | 233 { |
| 231 fpregset_t fpregs, saved_fpregs; | 234 fpregset_t fpregs, saved_fpregs; |
| 232 | 235 |
| 233 if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | 236 if (ptrace (PTRACE_GETFPREGS, pid, (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
| 234 perror_with_name (_("Couldn't get floating-point registers")); | 237 perror_with_name (_("Couldn't get floating-point registers")); |
| 235 | 238 |
| 236 memcpy (&saved_fpregs, &fpregs, sizeof (fpregs)); | 239 memcpy (&saved_fpregs, &fpregs, sizeof (fpregs)); |
| 237 sparc_collect_fpregset (regcache, regnum, &fpregs); | 240 sparc_collect_fpregset (sparc_fpregset, regcache, regnum, &fpregs); |
| 238 | 241 |
| 239 /* Writing the floating-point registers will fail on NetBSD with | 242 /* Writing the floating-point registers will fail on NetBSD with |
| 240 EINVAL if the inferior process doesn't have an FPU state | 243 EINVAL if the inferior process doesn't have an FPU state |
| 241 (i.e. if it didn't use the FPU yet). Therefore we don't try | 244 (i.e. if it didn't use the FPU yet). Therefore we don't try |
| 242 to write the registers if nothing changed. */ | 245 to write the registers if nothing changed. */ |
| 243 if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0) | 246 if (memcmp (&saved_fpregs, &fpregs, sizeof (fpregs)) != 0) |
| 244 { | 247 { |
| 245 if (ptrace (PTRACE_SETFPREGS, pid, | 248 if (ptrace (PTRACE_SETFPREGS, pid, |
| 246 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) | 249 (PTRACE_TYPE_ARG3) &fpregs, 0) == -1) |
| 247 perror_with_name (_("Couldn't write floating-point registers")); | 250 perror_with_name (_("Couldn't write floating-point registers")); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 269 | 272 |
| 270 if (offset == sizeof (unsigned long)) | 273 if (offset == sizeof (unsigned long)) |
| 271 return 0; /* Signal EOF. */ | 274 return 0; /* Signal EOF. */ |
| 272 if (offset > sizeof (unsigned long)) | 275 if (offset > sizeof (unsigned long)) |
| 273 return -1; | 276 return -1; |
| 274 | 277 |
| 275 #ifdef PT_WCOOKIE | 278 #ifdef PT_WCOOKIE |
| 276 /* If PT_WCOOKIE is defined (by <sys/ptrace.h>), assume we're | 279 /* If PT_WCOOKIE is defined (by <sys/ptrace.h>), assume we're |
| 277 running on an OpenBSD release that uses StackGhost (3.1 or | 280 running on an OpenBSD release that uses StackGhost (3.1 or |
| 278 later). Since release 3.6, OpenBSD uses a fully randomized | 281 later). Since release 3.6, OpenBSD uses a fully randomized |
error: old chunk mismatch |
None
| OLD | NEW |