+2018-02-21 Yao Qi <yao.qi@linaro.org>
+
+ * frame.c (frame_save_as_regcache): Use regcache method save.
+ (frame_pop): Use regcache method restore.
+ * infrun.c (restore_infcall_suspend_state): Likewise.
+ * linux-fork.c (fork_load_infrun_state): Likewise.
+ * ppc-linux-tdep.c (ppu2spu_sniffer): User regcache method
+ save.
+ * regcache.c (regcache_save): Remove.
+ (regcache::restore): More asserts.
+ (regcache_cpy): Remove.
+ * regcache.h (regcache_save): Remove the declaration.
+ (regcache::restore): Move from private to public.
+ Remove the friend declaration of regcache_cpy.
+ (regcache_cpy): Remove declaration.
+
2018-02-21 Yao Qi <yao.qi@linaro.org>
* aarch64-tdep.c (aarch64_pseudo_register_read_value): Change
std::unique_ptr<struct regcache> regcache
(new struct regcache (get_frame_arch (this_frame)));
- regcache_save (regcache.get (), do_frame_register_read, this_frame);
+ regcache->save (do_frame_register_read, this_frame);
return regcache;
}
Unfortunately, they don't implement it. Their lack of a formal
definition can lead to targets writing back bogus values
(arguably a bug in the target code mind). */
- /* Now copy those saved registers into the current regcache.
- Here, regcache_cpy() calls regcache_restore(). */
- regcache_cpy (get_current_regcache (), scratch.get ());
+ /* Now copy those saved registers into the current regcache. */
+ get_current_regcache ()->restore (scratch.get ());
/* We've made right mess of GDB's local state, just discard
everything. */
(and perhaps other times). */
if (target_has_execution)
/* NB: The register write goes through to the target. */
- regcache_cpy (regcache, inf_state->registers);
+ regcache->restore (inf_state->registers);
discard_infcall_suspend_state (inf_state);
}
linux_nat_switch_fork (fp->ptid);
if (fp->savedregs && fp->clobber_regs)
- regcache_cpy (get_current_regcache (), fp->savedregs);
+ get_current_regcache ()->restore (fp->savedregs);
registers_changed ();
reinit_frame_cache ();
std::unique_ptr<struct regcache> regcache
(new struct regcache (data.gdbarch));
- regcache_save (regcache.get (), ppu2spu_unwind_register, &data);
+ regcache->save (ppu2spu_unwind_register, &data);
cache->frame_id = frame_id_build (base, func);
cache->regcache = regcache.release ();
return m_registers + m_descr->register_offset[regnum];
}
-void
-regcache_save (struct regcache *regcache,
- regcache_cooked_read_ftype *cooked_read, void *src)
-{
- regcache->save (cooked_read, src);
-}
-
void
regcache::save (regcache_cooked_read_ftype *cooked_read,
void *src)
struct gdbarch *gdbarch = m_descr->gdbarch;
int regnum;
+ gdb_assert (src != NULL);
/* The dst had better not be read-only. If it is, the `restore'
doesn't make much sense. */
gdb_assert (!m_readonly_p);
gdb_assert (src->m_readonly_p);
+
+ gdb_assert (gdbarch == src->arch ());
+
/* 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
+ gdbarch_num_pseudo_regs) range is checked since some architectures need
}
}
-void
-regcache_cpy (struct regcache *dst, struct regcache *src)
-{
- gdb_assert (src != NULL && dst != NULL);
- gdb_assert (src->m_descr->gdbarch == dst->m_descr->gdbarch);
- gdb_assert (src != dst);
- gdb_assert (src->m_readonly_p && !dst->m_readonly_p);
-
- dst->restore (src);
-}
-
struct regcache *
regcache_dup (struct regcache *src)
{
extern int register_size (struct gdbarch *gdbarch, int regnum);
-
-/* Save/restore a register cache. The set of registers saved /
- restored into the DST regcache determined by the save_reggroup /
- restore_reggroup respectively. COOKED_READ returns zero iff the
- register's value can't be returned. */
-
typedef enum register_status (regcache_cooked_read_ftype) (void *src,
int regnum,
gdb_byte *buf);
-extern void regcache_save (struct regcache *dst,
- regcache_cooked_read_ftype *cooked_read,
- void *cooked_read_context);
-
enum regcache_dump_what
{
regcache_dump_none, regcache_dump_raw,
return m_aspace;
}
+/* Save/restore 'this' regcache. The set of registers saved /
+ restored into the regcache determined by the save_reggroup /
+ restore_reggroup respectively. COOKED_READ returns zero iff the
+ register's value can't be returned. */
void save (regcache_cooked_read_ftype *cooked_read, void *src);
+ /* Writes to regcache will go through to the target. SRC is a
+ read-only register cache. */
+ void restore (struct regcache *src);
+
void cooked_write (int regnum, const gdb_byte *buf);
void raw_write (int regnum, const gdb_byte *buf);
static std::forward_list<regcache *> current_regcache;
private:
- void restore (struct regcache *src);
void transfer_regset (const struct regset *regset,
struct regcache *out_regcache,
/* 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
call or just before forcing a function return). A read-only
- cache can only be updated via the methods regcache_dup() and
- regcache_cpy(). The actual contents are determined by the
- reggroup_save and reggroup_restore methods. */
+ cache can only be created via a constructor. The actual contents
+ are determined by the save and restore methods. */
const bool m_readonly_p;
/* If this is a read-write cache, which thread's registers is
it connected to? */
friend void
registers_changed_ptid (ptid_t ptid);
-
- friend void
- regcache_cpy (struct regcache *dst, struct regcache *src);
};
/* Duplicate the contents of a register cache to a read-only register
cache. The operation is pass-through. */
extern struct regcache *regcache_dup (struct regcache *regcache);
-/* Writes to DEST will go through to the target. SRC is a read-only
- register cache. */
-extern void regcache_cpy (struct regcache *dest, struct regcache *src);
-
extern void registers_changed (void);
extern void registers_changed_ptid (ptid_t);