core-regset.c revision 39193
1330567Sgordon/* Machine independent GDB support for core files on systems using "regsets". 2275970Scy Copyright 1993-1996 Free Software Foundation, Inc. 3275970Scy 4275970ScyThis file is part of GDB. 5275970Scy 6330567SgordonThis program is free software; you can redistribute it and/or modify 7275970Scyit under the terms of the GNU General Public License as published by 8275970Scythe Free Software Foundation; either version 2 of the License, or 9275970Scy(at your option) any later version. 10275970Scy 11275970ScyThis program is distributed in the hope that it will be useful, 12275970Scybut WITHOUT ANY WARRANTY; without even the implied warranty of 13275970ScyMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14275970ScyGNU General Public License for more details. 15275970Scy 16275970ScyYou should have received a copy of the GNU General Public License 17275970Scyalong with this program; if not, write to the Free Software 18275970ScyFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 19275970Scy 20275970Scy 21275970Scy/* N O T E S 22275970Scy 23275970ScyThis file is used by most systems that implement /proc. For these systems, 24275970Scythe general registers are laid out the same way in both the core file and 25275970Scythe gregset_p structure. The current exception to this is Irix-4.*, where 26275970Scythe gregset_p structure is split up into two pieces in the core file. 27275970Scy 28275970ScyThe general register and floating point register sets are manipulated by 29275970Scyseparate ioctl's. This file makes the assumption that if FP0_REGNUM is 30275970Scydefined, then support for the floating point register set is desired, 31275970Scyregardless of whether or not the actual target has floating point hardware. 32275970Scy 33275970Scy */ 34275970Scy 35275970Scy#include "defs.h" 36275970Scy 37275970Scy#include <time.h> 38275970Scy#ifdef HAVE_SYS_PROCFS_H 39275970Scy#include <sys/procfs.h> 40275970Scy#endif 41275970Scy#include <fcntl.h> 42275970Scy#include <errno.h> 43275970Scy#include "gdb_string.h" 44275970Scy 45275970Scy#include "inferior.h" 46275970Scy#include "target.h" 47275970Scy#include "command.h" 48275970Scy#include "gdbcore.h" 49275970Scy 50275970Scy/* 51275970Scy 52275970ScyGLOBAL FUNCTION 53275970Scy 54275970Scy fetch_core_registers -- fetch current registers from core file 55275970Scy 56275970ScySYNOPSIS 57275970Scy 58275970Scy void fetch_core_registers (char *core_reg_sect, 59275970Scy unsigned core_reg_size, 60275970Scy int which, unsigned in reg_addr) 61275970Scy 62275970ScyDESCRIPTION 63275970Scy 64275970Scy Read the values of either the general register set (WHICH equals 0) 65275970Scy or the floating point register set (WHICH equals 2) from the core 66275970Scy file data (pointed to by CORE_REG_SECT), and update gdb's idea of 67275970Scy their current values. The CORE_REG_SIZE parameter is ignored. 68275970Scy 69275970ScyNOTES 70275970Scy 71275970Scy Use the indicated sizes to validate the gregset and fpregset 72275970Scy structures. 73275970Scy*/ 74275970Scy 75275970Scystatic void 76275970Scyfetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) 77275970Scy char *core_reg_sect; 78275970Scy unsigned core_reg_size; 79275970Scy int which; 80275970Scy unsigned int reg_addr; /* Unused in this version */ 81275970Scy{ 82275970Scy#if defined (HAVE_GREGSET_T) && defined (HAVE_FPREGSET_T) 83275970Scy gregset_t gregset; 84275970Scy fpregset_t fpregset; 85 86 if (which == 0) 87 { 88 if (core_reg_size != sizeof (gregset)) 89 { 90 warning ("wrong size gregset struct in core file"); 91 } 92 else 93 { 94 memcpy ((char *) &gregset, core_reg_sect, sizeof (gregset)); 95 supply_gregset (&gregset); 96 } 97 } 98 else if (which == 2) 99 { 100 if (core_reg_size != sizeof (fpregset)) 101 { 102 warning ("wrong size fpregset struct in core file"); 103 } 104 else 105 { 106 memcpy ((char *) &fpregset, core_reg_sect, sizeof (fpregset)); 107#if defined (FP0_REGNUM) 108 supply_fpregset (&fpregset); 109#endif 110 } 111 } 112#endif /* defined(HAVE_GREGSET_T) && defined (HAVE_FPREGSET_T) */ 113} 114 115 116/* Register that we are able to handle ELF file formats using standard 117 procfs "regset" structures. */ 118 119static struct core_fns regset_core_fns = 120{ 121 bfd_target_elf_flavour, 122 fetch_core_registers, 123 NULL 124}; 125 126void 127_initialize_core_regset () 128{ 129 add_core_fns (®set_core_fns); 130} 131