Class readonly_detached_regcache

This patch adds a new class (type) for readonly regcache, which is
created via regcache::save.  readonly_detached_regcache inherits
readable_regcache.

gdb:

2018-02-21  Yao Qi  <yao.qi@linaro.org>

	* dummy-frame.c (dummy_frame_cache) <prev_regcache>: Use
	readonly_detached_regcache.
	(dummy_frame_prev_register): Use regcache->cooked_read.
	* frame.c (frame_save_as_regcache): Change return type.
	(frame_pop): Update.
	* frame.h (frame_save_as_regcache): Update declaration.
	* inferior.h (get_infcall_suspend_state_regcache): Update
	declaration.
	* infrun.c (infcall_suspend_state) <registers>: use
	readonly_detached_regcache.
	(save_infcall_suspend_state): Don't use regcache_dup.
	(get_infcall_suspend_state_regcache): Change return type.
	* linux-fork.c (struct fork_info) <savedregs>: Change to
	readonly_detached_regcache.
	<pc>: New field.
	(fork_save_infrun_state): Don't use regcache_dup.
	(info_checkpoints_command): Adjust.
	* mi/mi-main.c (register_changed_p): Update declaration.
	(mi_cmd_data_list_changed_registers): Use
	readonly_detached_regcache.
	(register_changed_p): Change parameter type to
	readonly_detached_regcache.
	* ppc-linux-tdep.c (ppu2spu_cache) <regcache>: Use
	readonly_detached_regcache.
	(ppu2spu_sniffer): Construct a new readonly_detached_regcache.
	* regcache.c (readonly_detached_regcache::readonly_detached_regcache):
	New.
	(regcache::save): Move it to reg_buffer.
	(regcache::restore): Change parameter type.
	(regcache_dup): Remove.
	* regcache.h (reg_buffer) <save>: New method.
	(readonly_detached_regcache): New class.
	* spu-tdep.c (spu2ppu_cache) <regcache>: Use
	readonly_detached_regcache.
	(spu2ppu_sniffer): Construct a new readonly_detached_regcache.
This commit is contained in:
Yao Qi
2018-02-21 11:20:03 +00:00
parent fc5b873615
commit daf6667d1f
12 changed files with 118 additions and 64 deletions

View File

@@ -226,6 +226,11 @@ regcache::regcache (readonly_t, const regcache &src)
save (do_cooked_read, (void *) &src);
}
readonly_detached_regcache::readonly_detached_regcache (const regcache &src)
: readonly_detached_regcache (src.arch (), do_cooked_read, (void *) &src)
{
}
gdbarch *
reg_buffer::arch () const
{
@@ -282,16 +287,14 @@ reg_buffer::register_buffer (int regnum) const
}
void
regcache::save (regcache_cooked_read_ftype *cooked_read,
void *src)
reg_buffer::save (regcache_cooked_read_ftype *cooked_read,
void *src)
{
struct gdbarch *gdbarch = m_descr->gdbarch;
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. */
gdb_assert (m_readonly_p);
/* It should have pseudo registers. */
gdb_assert (m_has_pseudo);
/* Clear the dest. */
memset (m_registers, 0, m_descr->sizeof_cooked_registers);
memset (m_register_status, 0, m_descr->nr_cooked_registers);
@@ -317,16 +320,14 @@ regcache::save (regcache_cooked_read_ftype *cooked_read,
}
void
regcache::restore (struct regcache *src)
regcache::restore (readonly_detached_regcache *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 (src->m_has_pseudo);
gdb_assert (gdbarch == src->arch ());
@@ -344,12 +345,6 @@ regcache::restore (struct regcache *src)
}
}
struct regcache *
regcache_dup (struct regcache *src)
{
return new regcache (regcache::readonly, *src);
}
enum register_status
regcache_register_status (const struct regcache *regcache, int regnum)
{