OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [gdb/] [regcache.c] - Diff between revs 827 and 840

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 827 Rev 840
/* Cache and manage the values of registers for GDB, the GNU debugger.
/* Cache and manage the values of registers for GDB, the GNU debugger.
 
 
   Copyright (C) 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001,
   Copyright (C) 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001,
   2002, 2004, 2007, 2008 Free Software Foundation, Inc.
   2002, 2004, 2007, 2008 Free Software Foundation, Inc.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
#include "defs.h"
#include "defs.h"
#include "inferior.h"
#include "inferior.h"
#include "target.h"
#include "target.h"
#include "gdbarch.h"
#include "gdbarch.h"
#include "gdbcmd.h"
#include "gdbcmd.h"
#include "regcache.h"
#include "regcache.h"
#include "reggroups.h"
#include "reggroups.h"
#include "gdb_assert.h"
#include "gdb_assert.h"
#include "gdb_string.h"
#include "gdb_string.h"
#include "gdbcmd.h"             /* For maintenanceprintlist.  */
#include "gdbcmd.h"             /* For maintenanceprintlist.  */
#include "observer.h"
#include "observer.h"
 
 
/*
/*
 * DATA STRUCTURE
 * DATA STRUCTURE
 *
 *
 * Here is the actual register cache.
 * Here is the actual register cache.
 */
 */
 
 
/* Per-architecture object describing the layout of a register cache.
/* Per-architecture object describing the layout of a register cache.
   Computed once when the architecture is created */
   Computed once when the architecture is created */
 
 
struct gdbarch_data *regcache_descr_handle;
struct gdbarch_data *regcache_descr_handle;
 
 
struct regcache_descr
struct regcache_descr
{
{
  /* The architecture this descriptor belongs to.  */
  /* The architecture this descriptor belongs to.  */
  struct gdbarch *gdbarch;
  struct gdbarch *gdbarch;
 
 
  /* The raw register cache.  Each raw (or hard) register is supplied
  /* The raw register cache.  Each raw (or hard) register is supplied
     by the target interface.  The raw cache should not contain
     by the target interface.  The raw cache should not contain
     redundant information - if the PC is constructed from two
     redundant information - if the PC is constructed from two
     registers then those registers and not the PC lives in the raw
     registers then those registers and not the PC lives in the raw
     cache.  */
     cache.  */
  int nr_raw_registers;
  int nr_raw_registers;
  long sizeof_raw_registers;
  long sizeof_raw_registers;
  long sizeof_raw_register_valid_p;
  long sizeof_raw_register_valid_p;
 
 
  /* The cooked register space.  Each cooked register in the range
  /* The cooked register space.  Each cooked register in the range
     [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
     [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
     register.  The remaining [NR_RAW_REGISTERS
     register.  The remaining [NR_RAW_REGISTERS
     .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
     .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
     both raw registers and memory by the architecture methods
     both raw registers and memory by the architecture methods
     gdbarch_pseudo_register_read and gdbarch_pseudo_register_write.  */
     gdbarch_pseudo_register_read and gdbarch_pseudo_register_write.  */
  int nr_cooked_registers;
  int nr_cooked_registers;
  long sizeof_cooked_registers;
  long sizeof_cooked_registers;
  long sizeof_cooked_register_valid_p;
  long sizeof_cooked_register_valid_p;
 
 
  /* Offset and size (in 8 bit bytes), of reach register in the
  /* Offset and size (in 8 bit bytes), of reach register in the
     register cache.  All registers (including those in the range
     register cache.  All registers (including those in the range
     [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
     [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an offset.
     Assigning all registers an offset makes it possible to keep
     Assigning all registers an offset makes it possible to keep
     legacy code, such as that found in read_register_bytes() and
     legacy code, such as that found in read_register_bytes() and
     write_register_bytes() working.  */
     write_register_bytes() working.  */
  long *register_offset;
  long *register_offset;
  long *sizeof_register;
  long *sizeof_register;
 
 
  /* Cached table containing the type of each register.  */
  /* Cached table containing the type of each register.  */
  struct type **register_type;
  struct type **register_type;
};
};
 
 
static void *
static void *
init_regcache_descr (struct gdbarch *gdbarch)
init_regcache_descr (struct gdbarch *gdbarch)
{
{
  int i;
  int i;
  struct regcache_descr *descr;
  struct regcache_descr *descr;
  gdb_assert (gdbarch != NULL);
  gdb_assert (gdbarch != NULL);
 
 
  /* Create an initial, zero filled, table.  */
  /* Create an initial, zero filled, table.  */
  descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
  descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
  descr->gdbarch = gdbarch;
  descr->gdbarch = gdbarch;
 
 
  /* Total size of the register space.  The raw registers are mapped
  /* Total size of the register space.  The raw registers are mapped
     directly onto the raw register cache while the pseudo's are
     directly onto the raw register cache while the pseudo's are
     either mapped onto raw-registers or memory.  */
     either mapped onto raw-registers or memory.  */
  descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
  descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
                               + gdbarch_num_pseudo_regs (gdbarch);
                               + gdbarch_num_pseudo_regs (gdbarch);
  descr->sizeof_cooked_register_valid_p = gdbarch_num_regs (gdbarch)
  descr->sizeof_cooked_register_valid_p = gdbarch_num_regs (gdbarch)
                                          + gdbarch_num_pseudo_regs
                                          + gdbarch_num_pseudo_regs
                                              (gdbarch);
                                              (gdbarch);
 
 
  /* Fill in a table of register types.  */
  /* Fill in a table of register types.  */
  descr->register_type
  descr->register_type
    = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, struct type *);
    = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, struct type *);
  for (i = 0; i < descr->nr_cooked_registers; i++)
  for (i = 0; i < descr->nr_cooked_registers; i++)
    descr->register_type[i] = gdbarch_register_type (gdbarch, i);
    descr->register_type[i] = gdbarch_register_type (gdbarch, i);
 
 
  /* Construct a strictly RAW register cache.  Don't allow pseudo's
  /* Construct a strictly RAW register cache.  Don't allow pseudo's
     into the register cache.  */
     into the register cache.  */
  descr->nr_raw_registers = gdbarch_num_regs (gdbarch);
  descr->nr_raw_registers = gdbarch_num_regs (gdbarch);
 
 
  /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
  /* FIXME: cagney/2002-08-13: Overallocate the register_valid_p
     array.  This pretects GDB from erant code that accesses elements
     array.  This pretects GDB from erant code that accesses elements
     of the global register_valid_p[] array in the range
     of the global register_valid_p[] array in the range
     [gdbarch_num_regs .. gdbarch_num_regs + gdbarch_num_pseudo_regs).  */
     [gdbarch_num_regs .. gdbarch_num_regs + gdbarch_num_pseudo_regs).  */
  descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
  descr->sizeof_raw_register_valid_p = descr->sizeof_cooked_register_valid_p;
 
 
  /* Lay out the register cache.
  /* Lay out the register cache.
 
 
     NOTE: cagney/2002-05-22: Only register_type() is used when
     NOTE: cagney/2002-05-22: Only register_type() is used when
     constructing the register cache.  It is assumed that the
     constructing the register cache.  It is assumed that the
     register's raw size, virtual size and type length are all the
     register's raw size, virtual size and type length are all the
     same.  */
     same.  */
 
 
  {
  {
    long offset = 0;
    long offset = 0;
    descr->sizeof_register
    descr->sizeof_register
      = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
      = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
    descr->register_offset
    descr->register_offset
      = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
      = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
    for (i = 0; i < descr->nr_cooked_registers; i++)
    for (i = 0; i < descr->nr_cooked_registers; i++)
      {
      {
        descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
        descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
        descr->register_offset[i] = offset;
        descr->register_offset[i] = offset;
        offset += descr->sizeof_register[i];
        offset += descr->sizeof_register[i];
        gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
        gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
      }
      }
    /* Set the real size of the register cache buffer.  */
    /* Set the real size of the register cache buffer.  */
    descr->sizeof_cooked_registers = offset;
    descr->sizeof_cooked_registers = offset;
  }
  }
 
 
  /* FIXME: cagney/2002-05-22: Should only need to allocate space for
  /* FIXME: cagney/2002-05-22: Should only need to allocate space for
     the raw registers.  Unfortunately some code still accesses the
     the raw registers.  Unfortunately some code still accesses the
     register array directly using the global registers[].  Until that
     register array directly using the global registers[].  Until that
     code has been purged, play safe and over allocating the register
     code has been purged, play safe and over allocating the register
     buffer.  Ulgh!  */
     buffer.  Ulgh!  */
  descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
  descr->sizeof_raw_registers = descr->sizeof_cooked_registers;
 
 
  return descr;
  return descr;
}
}
 
 
static struct regcache_descr *
static struct regcache_descr *
regcache_descr (struct gdbarch *gdbarch)
regcache_descr (struct gdbarch *gdbarch)
{
{
  return gdbarch_data (gdbarch, regcache_descr_handle);
  return gdbarch_data (gdbarch, regcache_descr_handle);
}
}
 
 
/* Utility functions returning useful register attributes stored in
/* Utility functions returning useful register attributes stored in
   the regcache descr.  */
   the regcache descr.  */
 
 
struct type *
struct type *
register_type (struct gdbarch *gdbarch, int regnum)
register_type (struct gdbarch *gdbarch, int regnum)
{
{
  struct regcache_descr *descr = regcache_descr (gdbarch);
  struct regcache_descr *descr = regcache_descr (gdbarch);
  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
  return descr->register_type[regnum];
  return descr->register_type[regnum];
}
}
 
 
/* Utility functions returning useful register attributes stored in
/* Utility functions returning useful register attributes stored in
   the regcache descr.  */
   the regcache descr.  */
 
 
int
int
register_size (struct gdbarch *gdbarch, int regnum)
register_size (struct gdbarch *gdbarch, int regnum)
{
{
  struct regcache_descr *descr = regcache_descr (gdbarch);
  struct regcache_descr *descr = regcache_descr (gdbarch);
  int size;
  int size;
  gdb_assert (regnum >= 0
  gdb_assert (regnum >= 0
              && regnum < (gdbarch_num_regs (gdbarch)
              && regnum < (gdbarch_num_regs (gdbarch)
                           + gdbarch_num_pseudo_regs (gdbarch)));
                           + gdbarch_num_pseudo_regs (gdbarch)));
  size = descr->sizeof_register[regnum];
  size = descr->sizeof_register[regnum];
  return size;
  return size;
}
}
 
 
/* The register cache for storing raw register values.  */
/* The register cache for storing raw register values.  */
 
 
struct regcache
struct regcache
{
{
  struct regcache_descr *descr;
  struct regcache_descr *descr;
  /* The register buffers.  A read-only register cache can hold the
  /* The register buffers.  A read-only register cache can hold the
     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
     full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
     register cache can only hold [0 .. gdbarch_num_regs).  */
     register cache can only hold [0 .. gdbarch_num_regs).  */
  gdb_byte *registers;
  gdb_byte *registers;
  /* Register cache status:
  /* Register cache status:
     register_valid_p[REG] == 0 if REG value is not in the cache
     register_valid_p[REG] == 0 if REG value is not in the cache
                            > 0 if REG value is in the cache
                            > 0 if REG value is in the cache
                            < 0 if REG value is permanently unavailable */
                            < 0 if REG value is permanently unavailable */
  signed char *register_valid_p;
  signed char *register_valid_p;
  /* Is this a read-only cache?  A read-only cache is used for saving
  /* Is this a read-only cache?  A read-only cache is used for saving
     the target's register state (e.g, across an inferior function
     the target's register state (e.g, across an inferior function
     call or just before forcing a function return).  A read-only
     call or just before forcing a function return).  A read-only
     cache can only be updated via the methods regcache_dup() and
     cache can only be updated via the methods regcache_dup() and
     regcache_cpy().  The actual contents are determined by the
     regcache_cpy().  The actual contents are determined by the
     reggroup_save and reggroup_restore methods.  */
     reggroup_save and reggroup_restore methods.  */
  int readonly_p;
  int readonly_p;
  /* If this is a read-write cache, which thread's registers is
  /* If this is a read-write cache, which thread's registers is
     it connected to?  */
     it connected to?  */
  ptid_t ptid;
  ptid_t ptid;
};
};
 
 
struct regcache *
struct regcache *
regcache_xmalloc (struct gdbarch *gdbarch)
regcache_xmalloc (struct gdbarch *gdbarch)
{
{
  struct regcache_descr *descr;
  struct regcache_descr *descr;
  struct regcache *regcache;
  struct regcache *regcache;
  gdb_assert (gdbarch != NULL);
  gdb_assert (gdbarch != NULL);
  descr = regcache_descr (gdbarch);
  descr = regcache_descr (gdbarch);
  regcache = XMALLOC (struct regcache);
  regcache = XMALLOC (struct regcache);
  regcache->descr = descr;
  regcache->descr = descr;
  regcache->registers
  regcache->registers
    = XCALLOC (descr->sizeof_raw_registers, gdb_byte);
    = XCALLOC (descr->sizeof_raw_registers, gdb_byte);
  regcache->register_valid_p
  regcache->register_valid_p
    = XCALLOC (descr->sizeof_raw_register_valid_p, gdb_byte);
    = XCALLOC (descr->sizeof_raw_register_valid_p, gdb_byte);
  regcache->readonly_p = 1;
  regcache->readonly_p = 1;
  regcache->ptid = minus_one_ptid;
  regcache->ptid = minus_one_ptid;
  return regcache;
  return regcache;
}
}
 
 
void
void
regcache_xfree (struct regcache *regcache)
regcache_xfree (struct regcache *regcache)
{
{
  if (regcache == NULL)
  if (regcache == NULL)
    return;
    return;
  xfree (regcache->registers);
  xfree (regcache->registers);
  xfree (regcache->register_valid_p);
  xfree (regcache->register_valid_p);
  xfree (regcache);
  xfree (regcache);
}
}
 
 
static void
static void
do_regcache_xfree (void *data)
do_regcache_xfree (void *data)
{
{
  regcache_xfree (data);
  regcache_xfree (data);
}
}
 
 
struct cleanup *
struct cleanup *
make_cleanup_regcache_xfree (struct regcache *regcache)
make_cleanup_regcache_xfree (struct regcache *regcache)
{
{
  return make_cleanup (do_regcache_xfree, regcache);
  return make_cleanup (do_regcache_xfree, regcache);
}
}
 
 
/* Return REGCACHE's architecture.  */
/* Return REGCACHE's architecture.  */
 
 
struct gdbarch *
struct gdbarch *
get_regcache_arch (const struct regcache *regcache)
get_regcache_arch (const struct regcache *regcache)
{
{
  return regcache->descr->gdbarch;
  return regcache->descr->gdbarch;
}
}
 
 
/* Return  a pointer to register REGNUM's buffer cache.  */
/* Return  a pointer to register REGNUM's buffer cache.  */
 
 
static gdb_byte *
static gdb_byte *
register_buffer (const struct regcache *regcache, int regnum)
register_buffer (const struct regcache *regcache, int regnum)
{
{
  return regcache->registers + regcache->descr->register_offset[regnum];
  return regcache->registers + regcache->descr->register_offset[regnum];
}
}
 
 
void
void
regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
               void *src)
               void *src)
{
{
  struct gdbarch *gdbarch = dst->descr->gdbarch;
  struct gdbarch *gdbarch = dst->descr->gdbarch;
  gdb_byte buf[MAX_REGISTER_SIZE];
  gdb_byte buf[MAX_REGISTER_SIZE];
  int regnum;
  int regnum;
  /* The DST should be `read-only', if it wasn't then the save would
  /* The DST should be `read-only', if it wasn't then the save would
     end up trying to write the register values back out to the
     end up trying to write the register values back out to the
     target.  */
     target.  */
  gdb_assert (dst->readonly_p);
  gdb_assert (dst->readonly_p);
  /* Clear the dest.  */
  /* Clear the dest.  */
  memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
  memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
  memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
  memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p);
  /* Copy over any registers (identified by their membership in the
  /* Copy over any registers (identified by their membership in the
     save_reggroup) and mark them as valid.  The full [0 .. gdbarch_num_regs +
     save_reggroup) and mark them as valid.  The full [0 .. gdbarch_num_regs +
     gdbarch_num_pseudo_regs) range is checked since some architectures need
     gdbarch_num_pseudo_regs) range is checked since some architectures need
     to save/restore `cooked' registers that live in memory.  */
     to save/restore `cooked' registers that live in memory.  */
  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
    {
    {
      if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
      if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
        {
        {
          int valid = cooked_read (src, regnum, buf);
          int valid = cooked_read (src, regnum, buf);
          if (valid)
          if (valid)
            {
            {
              memcpy (register_buffer (dst, regnum), buf,
              memcpy (register_buffer (dst, regnum), buf,
                      register_size (gdbarch, regnum));
                      register_size (gdbarch, regnum));
              dst->register_valid_p[regnum] = 1;
              dst->register_valid_p[regnum] = 1;
            }
            }
        }
        }
    }
    }
}
}
 
 
void
void
regcache_restore (struct regcache *dst,
regcache_restore (struct regcache *dst,
                  regcache_cooked_read_ftype *cooked_read,
                  regcache_cooked_read_ftype *cooked_read,
                  void *cooked_read_context)
                  void *cooked_read_context)
{
{
  struct gdbarch *gdbarch = dst->descr->gdbarch;
  struct gdbarch *gdbarch = dst->descr->gdbarch;
  gdb_byte buf[MAX_REGISTER_SIZE];
  gdb_byte buf[MAX_REGISTER_SIZE];
  int regnum;
  int regnum;
  /* The dst had better not be read-only.  If it is, the `restore'
  /* The dst had better not be read-only.  If it is, the `restore'
     doesn't make much sense.  */
     doesn't make much sense.  */
  gdb_assert (!dst->readonly_p);
  gdb_assert (!dst->readonly_p);
  /* Copy over any registers, being careful to only restore those that
  /* Copy over any registers, being careful to only restore those that
     were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
     were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
     + gdbarch_num_pseudo_regs) range is checked since some architectures need
     + gdbarch_num_pseudo_regs) range is checked since some architectures need
     to save/restore `cooked' registers that live in memory.  */
     to save/restore `cooked' registers that live in memory.  */
  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
  for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
    {
    {
      if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
      if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
        {
        {
          int valid = cooked_read (cooked_read_context, regnum, buf);
          int valid = cooked_read (cooked_read_context, regnum, buf);
          if (valid)
          if (valid)
            regcache_cooked_write (dst, regnum, buf);
            regcache_cooked_write (dst, regnum, buf);
        }
        }
    }
    }
}
}
 
 
static int
static int
do_cooked_read (void *src, int regnum, gdb_byte *buf)
do_cooked_read (void *src, int regnum, gdb_byte *buf)
{
{
  struct regcache *regcache = src;
  struct regcache *regcache = src;
  if (!regcache->register_valid_p[regnum] && regcache->readonly_p)
  if (!regcache->register_valid_p[regnum] && regcache->readonly_p)
    /* Don't even think about fetching a register from a read-only
    /* Don't even think about fetching a register from a read-only
       cache when the register isn't yet valid.  There isn't a target
       cache when the register isn't yet valid.  There isn't a target
       from which the register value can be fetched.  */
       from which the register value can be fetched.  */
    return 0;
    return 0;
  regcache_cooked_read (regcache, regnum, buf);
  regcache_cooked_read (regcache, regnum, buf);
  return 1;
  return 1;
}
}
 
 
 
 
void
void
regcache_cpy (struct regcache *dst, struct regcache *src)
regcache_cpy (struct regcache *dst, struct regcache *src)
{
{
  int i;
  int i;
  gdb_byte *buf;
  gdb_byte *buf;
  gdb_assert (src != NULL && dst != NULL);
  gdb_assert (src != NULL && dst != NULL);
  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
  gdb_assert (src != dst);
  gdb_assert (src != dst);
  gdb_assert (src->readonly_p || dst->readonly_p);
  gdb_assert (src->readonly_p || dst->readonly_p);
  if (!src->readonly_p)
  if (!src->readonly_p)
    regcache_save (dst, do_cooked_read, src);
    regcache_save (dst, do_cooked_read, src);
  else if (!dst->readonly_p)
  else if (!dst->readonly_p)
    regcache_restore (dst, do_cooked_read, src);
    regcache_restore (dst, do_cooked_read, src);
  else
  else
    regcache_cpy_no_passthrough (dst, src);
    regcache_cpy_no_passthrough (dst, src);
}
}
 
 
void
void
regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
{
{
  int i;
  int i;
  gdb_assert (src != NULL && dst != NULL);
  gdb_assert (src != NULL && dst != NULL);
  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
  gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
  /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
  /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
     move of data into the current regcache.  Doing this would be
     move of data into the current regcache.  Doing this would be
     silly - it would mean that valid_p would be completely invalid.  */
     silly - it would mean that valid_p would be completely invalid.  */
  gdb_assert (dst->readonly_p);
  gdb_assert (dst->readonly_p);
  memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
  memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers);
  memcpy (dst->register_valid_p, src->register_valid_p,
  memcpy (dst->register_valid_p, src->register_valid_p,
          dst->descr->sizeof_raw_register_valid_p);
          dst->descr->sizeof_raw_register_valid_p);
}
}
 
 
struct regcache *
struct regcache *
regcache_dup (struct regcache *src)
regcache_dup (struct regcache *src)
{
{
  struct regcache *newbuf;
  struct regcache *newbuf;
  newbuf = regcache_xmalloc (src->descr->gdbarch);
  newbuf = regcache_xmalloc (src->descr->gdbarch);
  regcache_cpy (newbuf, src);
  regcache_cpy (newbuf, src);
  return newbuf;
  return newbuf;
}
}
 
 
struct regcache *
struct regcache *
regcache_dup_no_passthrough (struct regcache *src)
regcache_dup_no_passthrough (struct regcache *src)
{
{
  struct regcache *newbuf;
  struct regcache *newbuf;
  newbuf = regcache_xmalloc (src->descr->gdbarch);
  newbuf = regcache_xmalloc (src->descr->gdbarch);
  regcache_cpy_no_passthrough (newbuf, src);
  regcache_cpy_no_passthrough (newbuf, src);
  return newbuf;
  return newbuf;
}
}
 
 
int
int
regcache_valid_p (const struct regcache *regcache, int regnum)
regcache_valid_p (const struct regcache *regcache, int regnum)
{
{
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0);
  gdb_assert (regnum >= 0);
  if (regcache->readonly_p)
  if (regcache->readonly_p)
    gdb_assert (regnum < regcache->descr->nr_cooked_registers);
    gdb_assert (regnum < regcache->descr->nr_cooked_registers);
  else
  else
    gdb_assert (regnum < regcache->descr->nr_raw_registers);
    gdb_assert (regnum < regcache->descr->nr_raw_registers);
 
 
  return regcache->register_valid_p[regnum];
  return regcache->register_valid_p[regnum];
}
}
 
 
void
void
regcache_invalidate (struct regcache *regcache, int regnum)
regcache_invalidate (struct regcache *regcache, int regnum)
{
{
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0);
  gdb_assert (regnum >= 0);
  gdb_assert (!regcache->readonly_p);
  gdb_assert (!regcache->readonly_p);
  gdb_assert (regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum < regcache->descr->nr_raw_registers);
  regcache->register_valid_p[regnum] = 0;
  regcache->register_valid_p[regnum] = 0;
}
}
 
 
 
 
/* Global structure containing the current regcache.  */
/* Global structure containing the current regcache.  */
/* FIXME: cagney/2002-05-11: The two global arrays registers[] and
/* FIXME: cagney/2002-05-11: The two global arrays registers[] and
   deprecated_register_valid[] currently point into this structure.  */
   deprecated_register_valid[] currently point into this structure.  */
static struct regcache *current_regcache;
static struct regcache *current_regcache;
 
 
/* NOTE: this is a write-through cache.  There is no "dirty" bit for
/* NOTE: this is a write-through cache.  There is no "dirty" bit for
   recording if the register values have been changed (eg. by the
   recording if the register values have been changed (eg. by the
   user).  Therefore all registers must be written back to the
   user).  Therefore all registers must be written back to the
   target when appropriate.  */
   target when appropriate.  */
 
 
struct regcache *get_thread_regcache (ptid_t ptid)
struct regcache *get_thread_regcache (ptid_t ptid)
{
{
  /* NOTE: uweigand/2007-05-05:  We need to detect the thread's
  /* NOTE: uweigand/2007-05-05:  We need to detect the thread's
     current architecture at this point.  */
     current architecture at this point.  */
  struct gdbarch *thread_gdbarch = current_gdbarch;
  struct gdbarch *thread_gdbarch = current_gdbarch;
 
 
  if (current_regcache && ptid_equal (current_regcache->ptid, ptid)
  if (current_regcache && ptid_equal (current_regcache->ptid, ptid)
      && get_regcache_arch (current_regcache) == thread_gdbarch)
      && get_regcache_arch (current_regcache) == thread_gdbarch)
    return current_regcache;
    return current_regcache;
 
 
  if (current_regcache)
  if (current_regcache)
    regcache_xfree (current_regcache);
    regcache_xfree (current_regcache);
 
 
  current_regcache = regcache_xmalloc (thread_gdbarch);
  current_regcache = regcache_xmalloc (thread_gdbarch);
  current_regcache->readonly_p = 0;
  current_regcache->readonly_p = 0;
  current_regcache->ptid = ptid;
  current_regcache->ptid = ptid;
 
 
  return current_regcache;
  return current_regcache;
}
}
 
 
struct regcache *get_current_regcache (void)
struct regcache *get_current_regcache (void)
{
{
  return get_thread_regcache (inferior_ptid);
  return get_thread_regcache (inferior_ptid);
}
}
 
 
 
 
/* Observer for the target_changed event.  */
/* Observer for the target_changed event.  */
 
 
void
void
regcache_observer_target_changed (struct target_ops *target)
regcache_observer_target_changed (struct target_ops *target)
{
{
  registers_changed ();
  registers_changed ();
}
}
 
 
/* Low level examining and depositing of registers.
/* Low level examining and depositing of registers.
 
 
   The caller is responsible for making sure that the inferior is
   The caller is responsible for making sure that the inferior is
   stopped before calling the fetching routines, or it will get
   stopped before calling the fetching routines, or it will get
   garbage.  (a change from GDB version 3, in which the caller got the
   garbage.  (a change from GDB version 3, in which the caller got the
   value from the last stop).  */
   value from the last stop).  */
 
 
/* REGISTERS_CHANGED ()
/* REGISTERS_CHANGED ()
 
 
   Indicate that registers may have changed, so invalidate the cache.  */
   Indicate that registers may have changed, so invalidate the cache.  */
 
 
void
void
registers_changed (void)
registers_changed (void)
{
{
  int i;
  int i;
 
 
  regcache_xfree (current_regcache);
  regcache_xfree (current_regcache);
  current_regcache = NULL;
  current_regcache = NULL;
 
 
  /* Need to forget about any frames we have cached, too. */
  /* Need to forget about any frames we have cached, too. */
  reinit_frame_cache ();
  reinit_frame_cache ();
 
 
  /* Force cleanup of any alloca areas if using C alloca instead of
  /* Force cleanup of any alloca areas if using C alloca instead of
     a builtin alloca.  This particular call is used to clean up
     a builtin alloca.  This particular call is used to clean up
     areas allocated by low level target code which may build up
     areas allocated by low level target code which may build up
     during lengthy interactions between gdb and the target before
     during lengthy interactions between gdb and the target before
     gdb gives control to the user (ie watchpoints).  */
     gdb gives control to the user (ie watchpoints).  */
  alloca (0);
  alloca (0);
}
}
 
 
 
 
void
void
regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
{
{
  gdb_assert (regcache != NULL && buf != NULL);
  gdb_assert (regcache != NULL && buf != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  /* Make certain that the register cache is up-to-date with respect
  /* Make certain that the register cache is up-to-date with respect
     to the current thread.  This switching shouldn't be necessary
     to the current thread.  This switching shouldn't be necessary
     only there is still only one target side register cache.  Sigh!
     only there is still only one target side register cache.  Sigh!
     On the bright side, at least there is a regcache object.  */
     On the bright side, at least there is a regcache object.  */
  if (!regcache->readonly_p)
  if (!regcache->readonly_p)
    {
    {
      if (!regcache_valid_p (regcache, regnum))
      if (!regcache_valid_p (regcache, regnum))
        {
        {
          struct cleanup *old_chain = save_inferior_ptid ();
          struct cleanup *old_chain = save_inferior_ptid ();
          inferior_ptid = regcache->ptid;
          inferior_ptid = regcache->ptid;
          target_fetch_registers (regcache, regnum);
          target_fetch_registers (regcache, regnum);
          do_cleanups (old_chain);
          do_cleanups (old_chain);
        }
        }
#if 0
#if 0
      /* FIXME: cagney/2004-08-07: At present a number of targets
      /* FIXME: cagney/2004-08-07: At present a number of targets
         forget (or didn't know that they needed) to set this leading to
         forget (or didn't know that they needed) to set this leading to
         panics.  Also is the problem that targets need to indicate
         panics.  Also is the problem that targets need to indicate
         that a register is in one of the possible states: valid,
         that a register is in one of the possible states: valid,
         undefined, unknown.  The last of which isn't yet
         undefined, unknown.  The last of which isn't yet
         possible.  */
         possible.  */
      gdb_assert (regcache_valid_p (regcache, regnum));
      gdb_assert (regcache_valid_p (regcache, regnum));
#endif
#endif
    }
    }
  /* Copy the value directly into the register cache.  */
  /* Copy the value directly into the register cache.  */
  memcpy (buf, register_buffer (regcache, regnum),
  memcpy (buf, register_buffer (regcache, regnum),
          regcache->descr->sizeof_register[regnum]);
          regcache->descr->sizeof_register[regnum]);
}
}
 
 
void
void
regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
{
{
  gdb_byte *buf;
  gdb_byte *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  regcache_raw_read (regcache, regnum, buf);
  regcache_raw_read (regcache, regnum, buf);
  (*val) = extract_signed_integer (buf,
  (*val) = extract_signed_integer (buf,
                                   regcache->descr->sizeof_register[regnum]);
                                   regcache->descr->sizeof_register[regnum]);
}
}
 
 
void
void
regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
                            ULONGEST *val)
                            ULONGEST *val)
{
{
  gdb_byte *buf;
  gdb_byte *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  regcache_raw_read (regcache, regnum, buf);
  regcache_raw_read (regcache, regnum, buf);
  (*val) = extract_unsigned_integer (buf,
  (*val) = extract_unsigned_integer (buf,
                                     regcache->descr->sizeof_register[regnum]);
                                     regcache->descr->sizeof_register[regnum]);
}
}
 
 
void
void
regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
{
{
  void *buf;
  void *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
  store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
  regcache_raw_write (regcache, regnum, buf);
  regcache_raw_write (regcache, regnum, buf);
}
}
 
 
void
void
regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
                             ULONGEST val)
                             ULONGEST val)
{
{
  void *buf;
  void *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
  regcache_raw_write (regcache, regnum, buf);
  regcache_raw_write (regcache, regnum, buf);
}
}
 
 
void
void
regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
{
{
  gdb_assert (regnum >= 0);
  gdb_assert (regnum >= 0);
  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
  if (regnum < regcache->descr->nr_raw_registers)
  if (regnum < regcache->descr->nr_raw_registers)
    regcache_raw_read (regcache, regnum, buf);
    regcache_raw_read (regcache, regnum, buf);
  else if (regcache->readonly_p
  else if (regcache->readonly_p
           && regnum < regcache->descr->nr_cooked_registers
           && regnum < regcache->descr->nr_cooked_registers
           && regcache->register_valid_p[regnum])
           && regcache->register_valid_p[regnum])
    /* Read-only register cache, perhaps the cooked value was cached?  */
    /* Read-only register cache, perhaps the cooked value was cached?  */
    memcpy (buf, register_buffer (regcache, regnum),
    memcpy (buf, register_buffer (regcache, regnum),
            regcache->descr->sizeof_register[regnum]);
            regcache->descr->sizeof_register[regnum]);
  else
  else
    gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
    gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
                                  regnum, buf);
                                  regnum, buf);
}
}
 
 
void
void
regcache_cooked_read_signed (struct regcache *regcache, int regnum,
regcache_cooked_read_signed (struct regcache *regcache, int regnum,
                             LONGEST *val)
                             LONGEST *val)
{
{
  gdb_byte *buf;
  gdb_byte *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  regcache_cooked_read (regcache, regnum, buf);
  regcache_cooked_read (regcache, regnum, buf);
  (*val) = extract_signed_integer (buf,
  (*val) = extract_signed_integer (buf,
                                   regcache->descr->sizeof_register[regnum]);
                                   regcache->descr->sizeof_register[regnum]);
}
}
 
 
void
void
regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
                               ULONGEST *val)
                               ULONGEST *val)
{
{
  gdb_byte *buf;
  gdb_byte *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  regcache_cooked_read (regcache, regnum, buf);
  regcache_cooked_read (regcache, regnum, buf);
  (*val) = extract_unsigned_integer (buf,
  (*val) = extract_unsigned_integer (buf,
                                     regcache->descr->sizeof_register[regnum]);
                                     regcache->descr->sizeof_register[regnum]);
}
}
 
 
void
void
regcache_cooked_write_signed (struct regcache *regcache, int regnum,
regcache_cooked_write_signed (struct regcache *regcache, int regnum,
                              LONGEST val)
                              LONGEST val)
{
{
  void *buf;
  void *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
  store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val);
  regcache_cooked_write (regcache, regnum, buf);
  regcache_cooked_write (regcache, regnum, buf);
}
}
 
 
void
void
regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
                                ULONGEST val)
                                ULONGEST val)
{
{
  void *buf;
  void *buf;
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
  gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  buf = alloca (regcache->descr->sizeof_register[regnum]);
  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
  store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val);
  regcache_cooked_write (regcache, regnum, buf);
  regcache_cooked_write (regcache, regnum, buf);
}
}
 
 
void
void
regcache_raw_write (struct regcache *regcache, int regnum,
regcache_raw_write (struct regcache *regcache, int regnum,
                    const gdb_byte *buf)
                    const gdb_byte *buf)
{
{
  struct cleanup *old_chain;
  struct cleanup *old_chain;
 
 
  gdb_assert (regcache != NULL && buf != NULL);
  gdb_assert (regcache != NULL && buf != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (!regcache->readonly_p);
  gdb_assert (!regcache->readonly_p);
 
 
  /* On the sparc, writing %g0 is a no-op, so we don't even want to
  /* On the sparc, writing %g0 is a no-op, so we don't even want to
     change the registers array if something writes to this register.  */
     change the registers array if something writes to this register.  */
  if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
  if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
    return;
    return;
 
 
  /* If we have a valid copy of the register, and new value == old
  /* If we have a valid copy of the register, and new value == old
     value, then don't bother doing the actual store. */
     value, then don't bother doing the actual store. */
  if (regcache_valid_p (regcache, regnum)
  if (regcache_valid_p (regcache, regnum)
      && (memcmp (register_buffer (regcache, regnum), buf,
      && (memcmp (register_buffer (regcache, regnum), buf,
                  regcache->descr->sizeof_register[regnum]) == 0))
                  regcache->descr->sizeof_register[regnum]) == 0))
    return;
    return;
 
 
  old_chain = save_inferior_ptid ();
  old_chain = save_inferior_ptid ();
  inferior_ptid = regcache->ptid;
  inferior_ptid = regcache->ptid;
 
 
  target_prepare_to_store (regcache);
  target_prepare_to_store (regcache);
  memcpy (register_buffer (regcache, regnum), buf,
  memcpy (register_buffer (regcache, regnum), buf,
          regcache->descr->sizeof_register[regnum]);
          regcache->descr->sizeof_register[regnum]);
  regcache->register_valid_p[regnum] = 1;
  regcache->register_valid_p[regnum] = 1;
  target_store_registers (regcache, regnum);
  target_store_registers (regcache, regnum);
 
 
  do_cleanups (old_chain);
  do_cleanups (old_chain);
}
}
 
 
void
void
regcache_cooked_write (struct regcache *regcache, int regnum,
regcache_cooked_write (struct regcache *regcache, int regnum,
                       const gdb_byte *buf)
                       const gdb_byte *buf)
{
{
  gdb_assert (regnum >= 0);
  gdb_assert (regnum >= 0);
  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
  gdb_assert (regnum < regcache->descr->nr_cooked_registers);
  if (regnum < regcache->descr->nr_raw_registers)
  if (regnum < regcache->descr->nr_raw_registers)
    regcache_raw_write (regcache, regnum, buf);
    regcache_raw_write (regcache, regnum, buf);
  else
  else
    gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
    gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
                                   regnum, buf);
                                   regnum, buf);
}
}
 
 
/* Perform a partial register transfer using a read, modify, write
/* Perform a partial register transfer using a read, modify, write
   operation.  */
   operation.  */
 
 
typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
                                    void *buf);
                                    void *buf);
typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
                                     const void *buf);
                                     const void *buf);
 
 
static void
static void
regcache_xfer_part (struct regcache *regcache, int regnum,
regcache_xfer_part (struct regcache *regcache, int regnum,
                    int offset, int len, void *in, const void *out,
                    int offset, int len, void *in, const void *out,
                    void (*read) (struct regcache *regcache, int regnum,
                    void (*read) (struct regcache *regcache, int regnum,
                                  gdb_byte *buf),
                                  gdb_byte *buf),
                    void (*write) (struct regcache *regcache, int regnum,
                    void (*write) (struct regcache *regcache, int regnum,
                                   const gdb_byte *buf))
                                   const gdb_byte *buf))
{
{
  struct regcache_descr *descr = regcache->descr;
  struct regcache_descr *descr = regcache->descr;
  gdb_byte reg[MAX_REGISTER_SIZE];
  gdb_byte reg[MAX_REGISTER_SIZE];
  gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
  gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
  gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
  gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
  /* Something to do?  */
  /* Something to do?  */
  if (offset + len == 0)
  if (offset + len == 0)
    return;
    return;
  /* Read (when needed) ... */
  /* Read (when needed) ... */
  if (in != NULL
  if (in != NULL
      || offset > 0
      || offset > 0
      || offset + len < descr->sizeof_register[regnum])
      || offset + len < descr->sizeof_register[regnum])
    {
    {
      gdb_assert (read != NULL);
      gdb_assert (read != NULL);
      read (regcache, regnum, reg);
      read (regcache, regnum, reg);
    }
    }
  /* ... modify ... */
  /* ... modify ... */
  if (in != NULL)
  if (in != NULL)
    memcpy (in, reg + offset, len);
    memcpy (in, reg + offset, len);
  if (out != NULL)
  if (out != NULL)
    memcpy (reg + offset, out, len);
    memcpy (reg + offset, out, len);
  /* ... write (when needed).  */
  /* ... write (when needed).  */
  if (out != NULL)
  if (out != NULL)
    {
    {
      gdb_assert (write != NULL);
      gdb_assert (write != NULL);
      write (regcache, regnum, reg);
      write (regcache, regnum, reg);
    }
    }
}
}
 
 
void
void
regcache_raw_read_part (struct regcache *regcache, int regnum,
regcache_raw_read_part (struct regcache *regcache, int regnum,
                        int offset, int len, gdb_byte *buf)
                        int offset, int len, gdb_byte *buf)
{
{
  struct regcache_descr *descr = regcache->descr;
  struct regcache_descr *descr = regcache->descr;
  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
  regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
  regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
                      regcache_raw_read, regcache_raw_write);
                      regcache_raw_read, regcache_raw_write);
}
}
 
 
void
void
regcache_raw_write_part (struct regcache *regcache, int regnum,
regcache_raw_write_part (struct regcache *regcache, int regnum,
                         int offset, int len, const gdb_byte *buf)
                         int offset, int len, const gdb_byte *buf)
{
{
  struct regcache_descr *descr = regcache->descr;
  struct regcache_descr *descr = regcache->descr;
  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
                      regcache_raw_read, regcache_raw_write);
                      regcache_raw_read, regcache_raw_write);
}
}
 
 
void
void
regcache_cooked_read_part (struct regcache *regcache, int regnum,
regcache_cooked_read_part (struct regcache *regcache, int regnum,
                           int offset, int len, gdb_byte *buf)
                           int offset, int len, gdb_byte *buf)
{
{
  struct regcache_descr *descr = regcache->descr;
  struct regcache_descr *descr = regcache->descr;
  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
  regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
  regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
                      regcache_cooked_read, regcache_cooked_write);
                      regcache_cooked_read, regcache_cooked_write);
}
}
 
 
void
void
regcache_cooked_write_part (struct regcache *regcache, int regnum,
regcache_cooked_write_part (struct regcache *regcache, int regnum,
                            int offset, int len, const gdb_byte *buf)
                            int offset, int len, const gdb_byte *buf)
{
{
  struct regcache_descr *descr = regcache->descr;
  struct regcache_descr *descr = regcache->descr;
  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
  gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
  regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
                      regcache_cooked_read, regcache_cooked_write);
                      regcache_cooked_read, regcache_cooked_write);
}
}
 
 
/* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
/* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
 
 
void
void
regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
{
{
  void *regbuf;
  void *regbuf;
  size_t size;
  size_t size;
 
 
  gdb_assert (regcache != NULL);
  gdb_assert (regcache != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (!regcache->readonly_p);
  gdb_assert (!regcache->readonly_p);
 
 
  regbuf = register_buffer (regcache, regnum);
  regbuf = register_buffer (regcache, regnum);
  size = regcache->descr->sizeof_register[regnum];
  size = regcache->descr->sizeof_register[regnum];
 
 
  if (buf)
  if (buf)
    memcpy (regbuf, buf, size);
    memcpy (regbuf, buf, size);
  else
  else
    memset (regbuf, 0, size);
    memset (regbuf, 0, size);
 
 
  /* Mark the register as cached.  */
  /* Mark the register as cached.  */
  regcache->register_valid_p[regnum] = 1;
  regcache->register_valid_p[regnum] = 1;
}
}
 
 
/* Collect register REGNUM from REGCACHE and store its contents in BUF.  */
/* Collect register REGNUM from REGCACHE and store its contents in BUF.  */
 
 
void
void
regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
{
{
  const void *regbuf;
  const void *regbuf;
  size_t size;
  size_t size;
 
 
  gdb_assert (regcache != NULL && buf != NULL);
  gdb_assert (regcache != NULL && buf != NULL);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
  gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
 
 
  regbuf = register_buffer (regcache, regnum);
  regbuf = register_buffer (regcache, regnum);
  size = regcache->descr->sizeof_register[regnum];
  size = regcache->descr->sizeof_register[regnum];
  memcpy (buf, regbuf, size);
  memcpy (buf, regbuf, size);
}
}
 
 
 
 
/* read_pc, write_pc, etc.  Special handling for register PC.  */
/* read_pc, write_pc, etc.  Special handling for register PC.  */
 
 
/* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc() and
/* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc() and
   read_sp(), will eventually be replaced by per-frame methods.
   read_sp(), will eventually be replaced by per-frame methods.
   Instead of relying on the global INFERIOR_PTID, they will use the
   Instead of relying on the global INFERIOR_PTID, they will use the
   contextual information provided by the FRAME.  These functions do
   contextual information provided by the FRAME.  These functions do
   not belong in the register cache.  */
   not belong in the register cache.  */
 
 
/* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
/* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
   write_pc_pid() and write_pc(), all need to be replaced by something
   write_pc_pid() and write_pc(), all need to be replaced by something
   that does not rely on global state.  But what?  */
   that does not rely on global state.  But what?  */
 
 
CORE_ADDR
CORE_ADDR
read_pc_pid (ptid_t ptid)
read_pc_pid (ptid_t ptid)
{
{
  struct regcache *regcache = get_thread_regcache (ptid);
  struct regcache *regcache = get_thread_regcache (ptid);
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
 
 
  CORE_ADDR pc_val;
  CORE_ADDR pc_val;
 
 
  if (gdbarch_read_pc_p (gdbarch))
  if (gdbarch_read_pc_p (gdbarch))
    pc_val = gdbarch_read_pc (gdbarch, regcache);
    pc_val = gdbarch_read_pc (gdbarch, regcache);
  /* Else use per-frame method on get_current_frame.  */
  /* Else use per-frame method on get_current_frame.  */
  else if (gdbarch_pc_regnum (gdbarch) >= 0)
  else if (gdbarch_pc_regnum (gdbarch) >= 0)
    {
    {
      ULONGEST raw_val;
      ULONGEST raw_val;
      regcache_cooked_read_unsigned (regcache,
      regcache_cooked_read_unsigned (regcache,
                                     gdbarch_pc_regnum (gdbarch),
                                     gdbarch_pc_regnum (gdbarch),
                                     &raw_val);
                                     &raw_val);
      pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
      pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
    }
    }
  else
  else
    internal_error (__FILE__, __LINE__, _("read_pc_pid: Unable to find PC"));
    internal_error (__FILE__, __LINE__, _("read_pc_pid: Unable to find PC"));
 
 
  return pc_val;
  return pc_val;
}
}
 
 
CORE_ADDR
CORE_ADDR
read_pc (void)
read_pc (void)
{
{
  return read_pc_pid (inferior_ptid);
  return read_pc_pid (inferior_ptid);
}
}
 
 
void
void
write_pc_pid (CORE_ADDR pc, ptid_t ptid)
write_pc_pid (CORE_ADDR pc, ptid_t ptid)
{
{
  struct regcache *regcache = get_thread_regcache (ptid);
  struct regcache *regcache = get_thread_regcache (ptid);
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
 
 
  if (gdbarch_write_pc_p (gdbarch))
  if (gdbarch_write_pc_p (gdbarch))
    gdbarch_write_pc (gdbarch, regcache, pc);
    gdbarch_write_pc (gdbarch, regcache, pc);
  else if (gdbarch_pc_regnum (gdbarch) >= 0)
  else if (gdbarch_pc_regnum (gdbarch) >= 0)
    regcache_cooked_write_unsigned (regcache,
    regcache_cooked_write_unsigned (regcache,
                                    gdbarch_pc_regnum (gdbarch), pc);
                                    gdbarch_pc_regnum (gdbarch), pc);
  else
  else
    internal_error (__FILE__, __LINE__,
    internal_error (__FILE__, __LINE__,
                    _("write_pc_pid: Unable to update PC"));
                    _("write_pc_pid: Unable to update PC"));
}
}
 
 
void
void
write_pc (CORE_ADDR pc)
write_pc (CORE_ADDR pc)
{
{
  write_pc_pid (pc, inferior_ptid);
  write_pc_pid (pc, inferior_ptid);
}
}
 
 
 
 
static void
static void
reg_flush_command (char *command, int from_tty)
reg_flush_command (char *command, int from_tty)
{
{
  /* Force-flush the register cache.  */
  /* Force-flush the register cache.  */
  registers_changed ();
  registers_changed ();
  if (from_tty)
  if (from_tty)
    printf_filtered (_("Register cache flushed.\n"));
    printf_filtered (_("Register cache flushed.\n"));
}
}
 
 
static void
static void
dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
                   const unsigned char *buf, long len)
                   const unsigned char *buf, long len)
{
{
  int i;
  int i;
  switch (endian)
  switch (endian)
    {
    {
    case BFD_ENDIAN_BIG:
    case BFD_ENDIAN_BIG:
      for (i = 0; i < len; i++)
      for (i = 0; i < len; i++)
        fprintf_unfiltered (file, "%02x", buf[i]);
        fprintf_unfiltered (file, "%02x", buf[i]);
      break;
      break;
    case BFD_ENDIAN_LITTLE:
    case BFD_ENDIAN_LITTLE:
      for (i = len - 1; i >= 0; i--)
      for (i = len - 1; i >= 0; i--)
        fprintf_unfiltered (file, "%02x", buf[i]);
        fprintf_unfiltered (file, "%02x", buf[i]);
      break;
      break;
    default:
    default:
      internal_error (__FILE__, __LINE__, _("Bad switch"));
      internal_error (__FILE__, __LINE__, _("Bad switch"));
    }
    }
}
}
 
 
enum regcache_dump_what
enum regcache_dump_what
{
{
  regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
  regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups
};
};
 
 
static void
static void
regcache_dump (struct regcache *regcache, struct ui_file *file,
regcache_dump (struct regcache *regcache, struct ui_file *file,
               enum regcache_dump_what what_to_dump)
               enum regcache_dump_what what_to_dump)
{
{
  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
  struct gdbarch *gdbarch = regcache->descr->gdbarch;
  struct gdbarch *gdbarch = regcache->descr->gdbarch;
  int regnum;
  int regnum;
  int footnote_nr = 0;
  int footnote_nr = 0;
  int footnote_register_size = 0;
  int footnote_register_size = 0;
  int footnote_register_offset = 0;
  int footnote_register_offset = 0;
  int footnote_register_type_name_null = 0;
  int footnote_register_type_name_null = 0;
  long register_offset = 0;
  long register_offset = 0;
  unsigned char buf[MAX_REGISTER_SIZE];
  unsigned char buf[MAX_REGISTER_SIZE];
 
 
#if 0
#if 0
  fprintf_unfiltered (file, "nr_raw_registers %d\n",
  fprintf_unfiltered (file, "nr_raw_registers %d\n",
                      regcache->descr->nr_raw_registers);
                      regcache->descr->nr_raw_registers);
  fprintf_unfiltered (file, "nr_cooked_registers %d\n",
  fprintf_unfiltered (file, "nr_cooked_registers %d\n",
                      regcache->descr->nr_cooked_registers);
                      regcache->descr->nr_cooked_registers);
  fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
  fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
                      regcache->descr->sizeof_raw_registers);
                      regcache->descr->sizeof_raw_registers);
  fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
  fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n",
                      regcache->descr->sizeof_raw_register_valid_p);
                      regcache->descr->sizeof_raw_register_valid_p);
  fprintf_unfiltered (file, "gdbarch_num_regs %d\n",
  fprintf_unfiltered (file, "gdbarch_num_regs %d\n",
                      gdbarch_num_regs (gdbarch));
                      gdbarch_num_regs (gdbarch));
  fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
  fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
                      gdbarch_num_pseudo_regs (gdbarch));
                      gdbarch_num_pseudo_regs (gdbarch));
#endif
#endif
 
 
  gdb_assert (regcache->descr->nr_cooked_registers
  gdb_assert (regcache->descr->nr_cooked_registers
              == (gdbarch_num_regs (gdbarch)
              == (gdbarch_num_regs (gdbarch)
                  + gdbarch_num_pseudo_regs (gdbarch)));
                  + gdbarch_num_pseudo_regs (gdbarch)));
 
 
  for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
  for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
    {
    {
      /* Name.  */
      /* Name.  */
      if (regnum < 0)
      if (regnum < 0)
        fprintf_unfiltered (file, " %-10s", "Name");
        fprintf_unfiltered (file, " %-10s", "Name");
      else
      else
        {
        {
          const char *p = gdbarch_register_name (gdbarch, regnum);
          const char *p = gdbarch_register_name (gdbarch, regnum);
          if (p == NULL)
          if (p == NULL)
            p = "";
            p = "";
          else if (p[0] == '\0')
          else if (p[0] == '\0')
            p = "''";
            p = "''";
          fprintf_unfiltered (file, " %-10s", p);
          fprintf_unfiltered (file, " %-10s", p);
        }
        }
 
 
      /* Number.  */
      /* Number.  */
      if (regnum < 0)
      if (regnum < 0)
        fprintf_unfiltered (file, " %4s", "Nr");
        fprintf_unfiltered (file, " %4s", "Nr");
      else
      else
        fprintf_unfiltered (file, " %4d", regnum);
        fprintf_unfiltered (file, " %4d", regnum);
 
 
      /* Relative number.  */
      /* Relative number.  */
      if (regnum < 0)
      if (regnum < 0)
        fprintf_unfiltered (file, " %4s", "Rel");
        fprintf_unfiltered (file, " %4s", "Rel");
      else if (regnum < gdbarch_num_regs (gdbarch))
      else if (regnum < gdbarch_num_regs (gdbarch))
        fprintf_unfiltered (file, " %4d", regnum);
        fprintf_unfiltered (file, " %4d", regnum);
      else
      else
        fprintf_unfiltered (file, " %4d",
        fprintf_unfiltered (file, " %4d",
                            (regnum - gdbarch_num_regs (gdbarch)));
                            (regnum - gdbarch_num_regs (gdbarch)));
 
 
      /* Offset.  */
      /* Offset.  */
      if (regnum < 0)
      if (regnum < 0)
        fprintf_unfiltered (file, " %6s  ", "Offset");
        fprintf_unfiltered (file, " %6s  ", "Offset");
      else
      else
        {
        {
          fprintf_unfiltered (file, " %6ld",
          fprintf_unfiltered (file, " %6ld",
                              regcache->descr->register_offset[regnum]);
                              regcache->descr->register_offset[regnum]);
          if (register_offset != regcache->descr->register_offset[regnum]
          if (register_offset != regcache->descr->register_offset[regnum]
              || (regnum > 0
              || (regnum > 0
                  && (regcache->descr->register_offset[regnum]
                  && (regcache->descr->register_offset[regnum]
                      != (regcache->descr->register_offset[regnum - 1]
                      != (regcache->descr->register_offset[regnum - 1]
                          + regcache->descr->sizeof_register[regnum - 1])))
                          + regcache->descr->sizeof_register[regnum - 1])))
              )
              )
            {
            {
              if (!footnote_register_offset)
              if (!footnote_register_offset)
                footnote_register_offset = ++footnote_nr;
                footnote_register_offset = ++footnote_nr;
              fprintf_unfiltered (file, "*%d", footnote_register_offset);
              fprintf_unfiltered (file, "*%d", footnote_register_offset);
            }
            }
          else
          else
            fprintf_unfiltered (file, "  ");
            fprintf_unfiltered (file, "  ");
          register_offset = (regcache->descr->register_offset[regnum]
          register_offset = (regcache->descr->register_offset[regnum]
                             + regcache->descr->sizeof_register[regnum]);
                             + regcache->descr->sizeof_register[regnum]);
        }
        }
 
 
      /* Size.  */
      /* Size.  */
      if (regnum < 0)
      if (regnum < 0)
        fprintf_unfiltered (file, " %5s ", "Size");
        fprintf_unfiltered (file, " %5s ", "Size");
      else
      else
        fprintf_unfiltered (file, " %5ld",
        fprintf_unfiltered (file, " %5ld",
                            regcache->descr->sizeof_register[regnum]);
                            regcache->descr->sizeof_register[regnum]);
 
 
      /* Type.  */
      /* Type.  */
      {
      {
        const char *t;
        const char *t;
        if (regnum < 0)
        if (regnum < 0)
          t = "Type";
          t = "Type";
        else
        else
          {
          {
            static const char blt[] = "builtin_type";
            static const char blt[] = "builtin_type";
            t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
            t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
            if (t == NULL)
            if (t == NULL)
              {
              {
                char *n;
                char *n;
                if (!footnote_register_type_name_null)
                if (!footnote_register_type_name_null)
                  footnote_register_type_name_null = ++footnote_nr;
                  footnote_register_type_name_null = ++footnote_nr;
                n = xstrprintf ("*%d", footnote_register_type_name_null);
                n = xstrprintf ("*%d", footnote_register_type_name_null);
                make_cleanup (xfree, n);
                make_cleanup (xfree, n);
                t = n;
                t = n;
              }
              }
            /* Chop a leading builtin_type.  */
            /* Chop a leading builtin_type.  */
            if (strncmp (t, blt, strlen (blt)) == 0)
            if (strncmp (t, blt, strlen (blt)) == 0)
              t += strlen (blt);
              t += strlen (blt);
          }
          }
        fprintf_unfiltered (file, " %-15s", t);
        fprintf_unfiltered (file, " %-15s", t);
      }
      }
 
 
      /* Leading space always present.  */
      /* Leading space always present.  */
      fprintf_unfiltered (file, " ");
      fprintf_unfiltered (file, " ");
 
 
      /* Value, raw.  */
      /* Value, raw.  */
      if (what_to_dump == regcache_dump_raw)
      if (what_to_dump == regcache_dump_raw)
        {
        {
          if (regnum < 0)
          if (regnum < 0)
            fprintf_unfiltered (file, "Raw value");
            fprintf_unfiltered (file, "Raw value");
          else if (regnum >= regcache->descr->nr_raw_registers)
          else if (regnum >= regcache->descr->nr_raw_registers)
            fprintf_unfiltered (file, "<cooked>");
            fprintf_unfiltered (file, "<cooked>");
          else if (!regcache_valid_p (regcache, regnum))
          else if (!regcache_valid_p (regcache, regnum))
            fprintf_unfiltered (file, "<invalid>");
            fprintf_unfiltered (file, "<invalid>");
          else
          else
            {
            {
              regcache_raw_read (regcache, regnum, buf);
              regcache_raw_read (regcache, regnum, buf);
              fprintf_unfiltered (file, "0x");
              fprintf_unfiltered (file, "0x");
              dump_endian_bytes (file,
              dump_endian_bytes (file,
                                 gdbarch_byte_order (gdbarch), buf,
                                 gdbarch_byte_order (gdbarch), buf,
                                 regcache->descr->sizeof_register[regnum]);
                                 regcache->descr->sizeof_register[regnum]);
            }
            }
        }
        }
 
 
      /* Value, cooked.  */
      /* Value, cooked.  */
      if (what_to_dump == regcache_dump_cooked)
      if (what_to_dump == regcache_dump_cooked)
        {
        {
          if (regnum < 0)
          if (regnum < 0)
            fprintf_unfiltered (file, "Cooked value");
            fprintf_unfiltered (file, "Cooked value");
          else
          else
            {
            {
              regcache_cooked_read (regcache, regnum, buf);
              regcache_cooked_read (regcache, regnum, buf);
              fprintf_unfiltered (file, "0x");
              fprintf_unfiltered (file, "0x");
              dump_endian_bytes (file,
              dump_endian_bytes (file,
                                 gdbarch_byte_order (gdbarch), buf,
                                 gdbarch_byte_order (gdbarch), buf,
                                 regcache->descr->sizeof_register[regnum]);
                                 regcache->descr->sizeof_register[regnum]);
            }
            }
        }
        }
 
 
      /* Group members.  */
      /* Group members.  */
      if (what_to_dump == regcache_dump_groups)
      if (what_to_dump == regcache_dump_groups)
        {
        {
          if (regnum < 0)
          if (regnum < 0)
            fprintf_unfiltered (file, "Groups");
            fprintf_unfiltered (file, "Groups");
          else
          else
            {
            {
              const char *sep = "";
              const char *sep = "";
              struct reggroup *group;
              struct reggroup *group;
              for (group = reggroup_next (gdbarch, NULL);
              for (group = reggroup_next (gdbarch, NULL);
                   group != NULL;
                   group != NULL;
                   group = reggroup_next (gdbarch, group))
                   group = reggroup_next (gdbarch, group))
                {
                {
                  if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
                  if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
                    {
                    {
                      fprintf_unfiltered (file, "%s%s", sep, reggroup_name (group));
                      fprintf_unfiltered (file, "%s%s", sep, reggroup_name (group));
                      sep = ",";
                      sep = ",";
                    }
                    }
                }
                }
            }
            }
        }
        }
 
 
      fprintf_unfiltered (file, "\n");
      fprintf_unfiltered (file, "\n");
    }
    }
 
 
  if (footnote_register_size)
  if (footnote_register_size)
    fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
    fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
                        footnote_register_size);
                        footnote_register_size);
  if (footnote_register_offset)
  if (footnote_register_offset)
    fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
    fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
                        footnote_register_offset);
                        footnote_register_offset);
  if (footnote_register_type_name_null)
  if (footnote_register_type_name_null)
    fprintf_unfiltered (file,
    fprintf_unfiltered (file,
                        "*%d: Register type's name NULL.\n",
                        "*%d: Register type's name NULL.\n",
                        footnote_register_type_name_null);
                        footnote_register_type_name_null);
  do_cleanups (cleanups);
  do_cleanups (cleanups);
}
}
 
 
static void
static void
regcache_print (char *args, enum regcache_dump_what what_to_dump)
regcache_print (char *args, enum regcache_dump_what what_to_dump)
{
{
  if (args == NULL)
  if (args == NULL)
    regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
    regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
  else
  else
    {
    {
      struct ui_file *file = gdb_fopen (args, "w");
      struct ui_file *file = gdb_fopen (args, "w");
      if (file == NULL)
      if (file == NULL)
        perror_with_name (_("maintenance print architecture"));
        perror_with_name (_("maintenance print architecture"));
      regcache_dump (get_current_regcache (), file, what_to_dump);
      regcache_dump (get_current_regcache (), file, what_to_dump);
      ui_file_delete (file);
      ui_file_delete (file);
    }
    }
}
}
 
 
static void
static void
maintenance_print_registers (char *args, int from_tty)
maintenance_print_registers (char *args, int from_tty)
{
{
  regcache_print (args, regcache_dump_none);
  regcache_print (args, regcache_dump_none);
}
}
 
 
static void
static void
maintenance_print_raw_registers (char *args, int from_tty)
maintenance_print_raw_registers (char *args, int from_tty)
{
{
  regcache_print (args, regcache_dump_raw);
  regcache_print (args, regcache_dump_raw);
}
}
 
 
static void
static void
maintenance_print_cooked_registers (char *args, int from_tty)
maintenance_print_cooked_registers (char *args, int from_tty)
{
{
  regcache_print (args, regcache_dump_cooked);
  regcache_print (args, regcache_dump_cooked);
}
}
 
 
static void
static void
maintenance_print_register_groups (char *args, int from_tty)
maintenance_print_register_groups (char *args, int from_tty)
{
{
  regcache_print (args, regcache_dump_groups);
  regcache_print (args, regcache_dump_groups);
}
}
 
 
extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
 
 
void
void
_initialize_regcache (void)
_initialize_regcache (void)
{
{
  regcache_descr_handle = gdbarch_data_register_post_init (init_regcache_descr);
  regcache_descr_handle = gdbarch_data_register_post_init (init_regcache_descr);
 
 
  observer_attach_target_changed (regcache_observer_target_changed);
  observer_attach_target_changed (regcache_observer_target_changed);
 
 
  add_com ("flushregs", class_maintenance, reg_flush_command,
  add_com ("flushregs", class_maintenance, reg_flush_command,
           _("Force gdb to flush its register cache (maintainer command)"));
           _("Force gdb to flush its register cache (maintainer command)"));
 
 
  add_cmd ("registers", class_maintenance, maintenance_print_registers, _("\
  add_cmd ("registers", class_maintenance, maintenance_print_registers, _("\
Print the internal register configuration.\n\
Print the internal register configuration.\n\
Takes an optional file parameter."), &maintenanceprintlist);
Takes an optional file parameter."), &maintenanceprintlist);
  add_cmd ("raw-registers", class_maintenance,
  add_cmd ("raw-registers", class_maintenance,
           maintenance_print_raw_registers, _("\
           maintenance_print_raw_registers, _("\
Print the internal register configuration including raw values.\n\
Print the internal register configuration including raw values.\n\
Takes an optional file parameter."), &maintenanceprintlist);
Takes an optional file parameter."), &maintenanceprintlist);
  add_cmd ("cooked-registers", class_maintenance,
  add_cmd ("cooked-registers", class_maintenance,
           maintenance_print_cooked_registers, _("\
           maintenance_print_cooked_registers, _("\
Print the internal register configuration including cooked values.\n\
Print the internal register configuration including cooked values.\n\
Takes an optional file parameter."), &maintenanceprintlist);
Takes an optional file parameter."), &maintenanceprintlist);
  add_cmd ("register-groups", class_maintenance,
  add_cmd ("register-groups", class_maintenance,
           maintenance_print_register_groups, _("\
           maintenance_print_register_groups, _("\
Print the internal register configuration including each register's group.\n\
Print the internal register configuration including each register's group.\n\
Takes an optional file parameter."),
Takes an optional file parameter."),
           &maintenanceprintlist);
           &maintenanceprintlist);
 
 
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.