GDB (API)
|
00001 /* Native-dependent code for NetBSD/sh. 00002 00003 Copyright (C) 2002-2013 Free Software Foundation, Inc. 00004 00005 Contributed by Wasabi Systems, Inc. 00006 00007 This file is part of GDB. 00008 00009 This program is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00021 00022 #include "defs.h" 00023 #include "inferior.h" 00024 00025 #include <sys/types.h> 00026 #include <sys/ptrace.h> 00027 #include <machine/reg.h> 00028 00029 #include "sh-tdep.h" 00030 #include "inf-ptrace.h" 00031 #include "regcache.h" 00032 00033 00034 /* Determine if PT_GETREGS fetches this register. */ 00035 #define GETREGS_SUPPLIES(gdbarch, regno) \ 00036 (((regno) >= R0_REGNUM && (regno) <= (R0_REGNUM + 15)) \ 00037 || (regno) == gdbarch_pc_regnum (gdbarch) || (regno) == PR_REGNUM \ 00038 || (regno) == MACH_REGNUM || (regno) == MACL_REGNUM \ 00039 || (regno) == SR_REGNUM) 00040 00041 /* Sizeof `struct reg' in <machine/reg.h>. */ 00042 #define SHNBSD_SIZEOF_GREGS (21 * 4) 00043 00044 static void 00045 shnbsd_fetch_inferior_registers (struct target_ops *ops, 00046 struct regcache *regcache, int regno) 00047 { 00048 if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno)) 00049 { 00050 struct reg inferior_registers; 00051 00052 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), 00053 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) 00054 perror_with_name (_("Couldn't get registers")); 00055 00056 sh_corefile_supply_regset (&sh_corefile_gregset, regcache, regno, 00057 (char *) &inferior_registers, 00058 SHNBSD_SIZEOF_GREGS); 00059 00060 if (regno != -1) 00061 return; 00062 } 00063 } 00064 00065 static void 00066 shnbsd_store_inferior_registers (struct target_ops *ops, 00067 struct regcache *regcache, int regno) 00068 { 00069 if (regno == -1 || GETREGS_SUPPLIES (get_regcache_arch (regcache), regno)) 00070 { 00071 struct reg inferior_registers; 00072 00073 if (ptrace (PT_GETREGS, ptid_get_pid (inferior_ptid), 00074 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) 00075 perror_with_name (_("Couldn't get registers")); 00076 00077 sh_corefile_collect_regset (&sh_corefile_gregset, regcache, regno, 00078 (char *) &inferior_registers, 00079 SHNBSD_SIZEOF_GREGS); 00080 00081 if (ptrace (PT_SETREGS, ptid_get_pid (inferior_ptid), 00082 (PTRACE_TYPE_ARG3) &inferior_registers, 0) == -1) 00083 perror_with_name (_("Couldn't set registers")); 00084 00085 if (regno != -1) 00086 return; 00087 } 00088 } 00089 00090 /* Provide a prototype to silence -Wmissing-prototypes. */ 00091 void _initialize_shnbsd_nat (void); 00092 00093 void 00094 _initialize_shnbsd_nat (void) 00095 { 00096 struct target_ops *t; 00097 00098 t = inf_ptrace_target (); 00099 t->to_fetch_registers = shnbsd_fetch_inferior_registers; 00100 t->to_store_registers = shnbsd_store_inferior_registers; 00101 add_target (t); 00102 }