gdb/core-regset.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Machine independent GDB support for core files on systems using "regsets".

  2.    Copyright (C) 1993-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* This file is used by most systems that use ELF for their core
  15.    dumps.  This includes most systems that have SVR4-ish variant of
  16.    /proc.  For these systems, the registers are laid out the same way
  17.    in core files as in the gregset_t and fpregset_t structures that
  18.    are used in the interaction with /proc (Irix 4 is an exception and
  19.    therefore doesn't use this file).  Quite a few systems without a
  20.    SVR4-ish /proc define these structures too, and can make use of
  21.    this code too.  */

  22. #include "defs.h"
  23. #include "command.h"
  24. #include "gdbcore.h"
  25. #include "inferior.h"
  26. #include "target.h"
  27. #include "regcache.h"

  28. #include <fcntl.h>
  29. #include <time.h>
  30. #ifdef HAVE_SYS_PROCFS_H
  31. #include <sys/procfs.h>
  32. #endif

  33. /* Prototypes for supply_gregset etc.  */
  34. #include "gregset.h"

  35. /* Provide registers to GDB from a core file.

  36.    CORE_REG_SECT points to an array of bytes, which are the contents
  37.    of a `note' from a core file which BFD thinks might contain
  38.    register contents.  CORE_REG_SIZE is its size.

  39.    WHICH says which register set corelow suspects this is:
  40.      0 --- the general-purpose register set, in gregset_t format
  41.      2 --- the floating-point register set, in fpregset_t format

  42.    REG_ADDR is ignored.  */

  43. static void
  44. fetch_core_registers (struct regcache *regcache,
  45.                       char *core_reg_sect,
  46.                       unsigned core_reg_size,
  47.                       int which,
  48.                       CORE_ADDR reg_addr)
  49. {
  50.   gdb_gregset_t gregset;
  51.   gdb_fpregset_t fpregset;
  52.   gdb_gregset_t *gregset_p = &gregset;
  53.   gdb_fpregset_t *fpregset_p = &fpregset;

  54.   switch (which)
  55.     {
  56.     case 0:
  57.       if (core_reg_size != sizeof (gregset))
  58.         warning (_("Wrong size gregset in core file."));
  59.       else
  60.         {
  61.           memcpy (&gregset, core_reg_sect, sizeof (gregset));
  62.           supply_gregset (regcache, (const gdb_gregset_t *) gregset_p);
  63.         }
  64.       break;

  65.     case 2:
  66.       if (core_reg_size != sizeof (fpregset))
  67.         warning (_("Wrong size fpregset in core file."));
  68.       else
  69.         {
  70.           memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
  71.           if (gdbarch_fp0_regnum (get_regcache_arch (regcache)) >= 0)
  72.             supply_fpregset (regcache,
  73.                              (const gdb_fpregset_t *) fpregset_p);
  74.         }
  75.       break;

  76.     default:
  77.       /* We've covered all the kinds of registers we know about here,
  78.          so this must be something we wouldn't know what to do with
  79.          anyway.  Just ignore it.  */
  80.       break;
  81.     }
  82. }


  83. /* Register that we are able to handle ELF core file formats using
  84.    standard procfs "regset" structures.  */

  85. static struct core_fns regset_core_fns =
  86. {
  87.   bfd_target_elf_flavour,                /* core_flavour */
  88.   default_check_format,                        /* check_format */
  89.   default_core_sniffer,                        /* core_sniffer */
  90.   fetch_core_registers,                        /* core_read_registers */
  91.   NULL                                        /* next */
  92. };

  93. /* Provide a prototype to silence -Wmissing-prototypes.  */
  94. extern void _initialize_core_regset (void);

  95. void
  96. _initialize_core_regset (void)
  97. {
  98.   deprecated_add_core_fns (&regset_core_fns);
  99. }