aboutsummaryrefslogtreecommitdiff
path: root/gdb/regcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/regcache.c')
-rw-r--r--gdb/regcache.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 6c91da3..5342586 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -123,6 +123,7 @@ init_regcache_descr (struct gdbarch *gdbarch)
{
long offset = 0;
+
descr->sizeof_register
= GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
descr->register_offset
@@ -161,6 +162,7 @@ struct type *
register_type (struct gdbarch *gdbarch, int regnum)
{
struct regcache_descr *descr = regcache_descr (gdbarch);
+
gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
return descr->register_type[regnum];
}
@@ -173,6 +175,7 @@ register_size (struct gdbarch *gdbarch, int regnum)
{
struct regcache_descr *descr = regcache_descr (gdbarch);
int size;
+
gdb_assert (regnum >= 0
&& regnum < (gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch)));
@@ -216,6 +219,7 @@ regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
{
struct regcache_descr *descr;
struct regcache *regcache;
+
gdb_assert (gdbarch != NULL);
descr = regcache_descr (gdbarch);
regcache = XMALLOC (struct regcache);
@@ -281,6 +285,7 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
struct gdbarch *gdbarch = dst->descr->gdbarch;
gdb_byte buf[MAX_REGISTER_SIZE];
int regnum;
+
/* 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
target. */
@@ -297,6 +302,7 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
{
int valid = cooked_read (src, regnum, buf);
+
if (valid)
{
memcpy (register_buffer (dst, regnum), buf,
@@ -315,6 +321,7 @@ regcache_restore (struct regcache *dst,
struct gdbarch *gdbarch = dst->descr->gdbarch;
gdb_byte buf[MAX_REGISTER_SIZE];
int regnum;
+
/* The dst had better not be read-only. If it is, the `restore'
doesn't make much sense. */
gdb_assert (!dst->readonly_p);
@@ -327,6 +334,7 @@ regcache_restore (struct regcache *dst,
if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
{
int valid = cooked_read (cooked_read_context, regnum, buf);
+
if (valid)
regcache_cooked_write (dst, regnum, buf);
}
@@ -337,6 +345,7 @@ static int
do_cooked_read (void *src, int regnum, gdb_byte *buf)
{
struct regcache *regcache = src;
+
if (!regcache->register_valid_p[regnum] && regcache->readonly_p)
/* 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
@@ -382,6 +391,7 @@ struct regcache *
regcache_dup (struct regcache *src)
{
struct regcache *newbuf;
+
newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
regcache_cpy (newbuf, src);
return newbuf;
@@ -391,6 +401,7 @@ struct regcache *
regcache_dup_no_passthrough (struct regcache *src)
{
struct regcache *newbuf;
+
newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
regcache_cpy_no_passthrough (newbuf, src);
return newbuf;
@@ -573,6 +584,7 @@ regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
if (!regcache_valid_p (regcache, regnum))
{
struct cleanup *old_chain = save_inferior_ptid ();
+
inferior_ptid = regcache->ptid;
target_fetch_registers (regcache, regnum);
do_cleanups (old_chain);
@@ -596,6 +608,7 @@ void
regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
{
gdb_byte *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -610,6 +623,7 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
ULONGEST *val)
{
gdb_byte *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -623,6 +637,7 @@ void
regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
{
void *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -636,6 +651,7 @@ regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
ULONGEST val)
{
void *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -667,6 +683,7 @@ regcache_cooked_read_signed (struct regcache *regcache, int regnum,
LONGEST *val)
{
gdb_byte *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -681,6 +698,7 @@ regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
ULONGEST *val)
{
gdb_byte *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -695,6 +713,7 @@ regcache_cooked_write_signed (struct regcache *regcache, int regnum,
LONGEST val)
{
void *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -708,6 +727,7 @@ regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
ULONGEST val)
{
void *buf;
+
gdb_assert (regcache != NULL);
gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
buf = alloca (regcache->descr->sizeof_register[regnum]);
@@ -781,6 +801,7 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
{
struct regcache_descr *descr = regcache->descr;
gdb_byte reg[MAX_REGISTER_SIZE];
+
gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
/* Something to do? */
@@ -812,6 +833,7 @@ regcache_raw_read_part (struct regcache *regcache, int regnum,
int offset, int len, gdb_byte *buf)
{
struct regcache_descr *descr = regcache->descr;
+
gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
regcache_raw_read, regcache_raw_write);
@@ -822,6 +844,7 @@ regcache_raw_write_part (struct regcache *regcache, int regnum,
int offset, int len, const gdb_byte *buf)
{
struct regcache_descr *descr = regcache->descr;
+
gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
regcache_raw_read, regcache_raw_write);
@@ -832,6 +855,7 @@ regcache_cooked_read_part (struct regcache *regcache, int regnum,
int offset, int len, gdb_byte *buf)
{
struct regcache_descr *descr = regcache->descr;
+
gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
regcache_cooked_read, regcache_cooked_write);
@@ -842,6 +866,7 @@ regcache_cooked_write_part (struct regcache *regcache, int regnum,
int offset, int len, const gdb_byte *buf)
{
struct regcache_descr *descr = regcache->descr;
+
gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
regcache_cooked_read, regcache_cooked_write);
@@ -903,6 +928,7 @@ regcache_read_pc (struct regcache *regcache)
else if (gdbarch_pc_regnum (gdbarch) >= 0)
{
ULONGEST raw_val;
+
regcache_cooked_read_unsigned (regcache,
gdbarch_pc_regnum (gdbarch),
&raw_val);
@@ -948,6 +974,7 @@ dump_endian_bytes (struct ui_file *file, enum bfd_endian endian,
const unsigned char *buf, long len)
{
int i;
+
switch (endian)
{
case BFD_ENDIAN_BIG:
@@ -1009,6 +1036,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
else
{
const char *p = gdbarch_register_name (gdbarch, regnum);
+
if (p == NULL)
p = "";
else if (p[0] == '\0')
@@ -1065,15 +1093,18 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
/* Type. */
{
const char *t;
+
if (regnum < 0)
t = "Type";
else
{
static const char blt[] = "builtin_type";
+
t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
if (t == NULL)
{
char *n;
+
if (!footnote_register_type_name_null)
footnote_register_type_name_null = ++footnote_nr;
n = xstrprintf ("*%d", footnote_register_type_name_null);
@@ -1133,6 +1164,7 @@ regcache_dump (struct regcache *regcache, struct ui_file *file,
{
const char *sep = "";
struct reggroup *group;
+
for (group = reggroup_next (gdbarch, NULL);
group != NULL;
group = reggroup_next (gdbarch, group))
@@ -1171,6 +1203,7 @@ regcache_print (char *args, enum regcache_dump_what what_to_dump)
{
struct cleanup *cleanups;
struct ui_file *file = gdb_fopen (args, "w");
+
if (file == NULL)
perror_with_name (_("maintenance print architecture"));
cleanups = make_cleanup_ui_file_delete (file);