GDB (API)
/home/stan/gdb/src/gdb/core-regset.c
Go to the documentation of this file.
00001 /* Machine independent GDB support for core files on systems using "regsets".
00002 
00003    Copyright (C) 1993-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 /* This file is used by most systems that use ELF for their core
00021    dumps.  This includes most systems that have SVR4-ish variant of
00022    /proc.  For these systems, the registers are laid out the same way
00023    in core files as in the gregset_t and fpregset_t structures that
00024    are used in the interaction with /proc (Irix 4 is an exception and
00025    therefore doesn't use this file).  Quite a few systems without a
00026    SVR4-ish /proc define these structures too, and can make use of
00027    this code too.  */
00028 
00029 #include "defs.h"
00030 #include "command.h"
00031 #include "gdbcore.h"
00032 #include "inferior.h"
00033 #include "target.h"
00034 #include "regcache.h"
00035 
00036 #include <fcntl.h>
00037 #include <errno.h>
00038 #include "gdb_string.h"
00039 #include <time.h>
00040 #ifdef HAVE_SYS_PROCFS_H
00041 #include <sys/procfs.h>
00042 #endif
00043 
00044 /* Prototypes for supply_gregset etc.  */
00045 #include "gregset.h"
00046 
00047 /* Provide registers to GDB from a core file.
00048 
00049    CORE_REG_SECT points to an array of bytes, which are the contents
00050    of a `note' from a core file which BFD thinks might contain
00051    register contents.  CORE_REG_SIZE is its size.
00052 
00053    WHICH says which register set corelow suspects this is:
00054      0 --- the general-purpose register set, in gregset_t format
00055      2 --- the floating-point register set, in fpregset_t format
00056 
00057    REG_ADDR is ignored.  */
00058 
00059 static void
00060 fetch_core_registers (struct regcache *regcache,
00061                       char *core_reg_sect,
00062                       unsigned core_reg_size,
00063                       int which,
00064                       CORE_ADDR reg_addr)
00065 {
00066   gdb_gregset_t gregset;
00067   gdb_fpregset_t fpregset;
00068   gdb_gregset_t *gregset_p = &gregset;
00069   gdb_fpregset_t *fpregset_p = &fpregset;
00070 
00071   switch (which)
00072     {
00073     case 0:
00074       if (core_reg_size != sizeof (gregset))
00075         warning (_("Wrong size gregset in core file."));
00076       else
00077         {
00078           memcpy (&gregset, core_reg_sect, sizeof (gregset));
00079           supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
00080         }
00081       break;
00082 
00083     case 2:
00084       if (core_reg_size != sizeof (fpregset))
00085         warning (_("Wrong size fpregset in core file."));
00086       else
00087         {
00088           memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
00089           if (gdbarch_fp0_regnum (get_regcache_arch (regcache)) >= 0)
00090             supply_fpregset (regcache,
00091                              (const gdb_fpregset_t *) fpregset_p);
00092         }
00093       break;
00094 
00095     default:
00096       /* We've covered all the kinds of registers we know about here,
00097          so this must be something we wouldn't know what to do with
00098          anyway.  Just ignore it.  */
00099       break;
00100     }
00101 }
00102 
00103 
00104 /* Register that we are able to handle ELF core file formats using
00105    standard procfs "regset" structures.  */
00106 
00107 static struct core_fns regset_core_fns =
00108 {
00109   bfd_target_elf_flavour,               /* core_flavour */
00110   default_check_format,                 /* check_format */
00111   default_core_sniffer,                 /* core_sniffer */
00112   fetch_core_registers,                 /* core_read_registers */
00113   NULL                                  /* next */
00114 };
00115 
00116 /* Provide a prototype to silence -Wmissing-prototypes.  */
00117 extern void _initialize_core_regset (void);
00118 
00119 void
00120 _initialize_core_regset (void)
00121 {
00122   deprecated_add_core_fns (&regset_core_fns);
00123 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines