Class detached_regcache

jit.c uses the regcache in a slightly different way, the regcache dosen't
write through to target, but it has read and write methods.  If I apply
regcache in record-full.c, it has the similar use pattern.  This patch
adds a new class detached_regcache, a register buffer, but can be
read and written.

Since jit.c doesn't want to write registers through to target, it uses
regcache as a readonly regcache (because only readonly regcache
disconnects from the target), but it adds a hole in regcache
(raw_set_cached_value) in order to modify a readonly regcache.  This patch
fixes this hole completely.

regcache inherits detached_regcache, and detached_regcache inherits
readable_regcache.  The ideal design is that both detached_regcache and
readable_regcache inherit reg_buffer, and regcache inherit
detached_regcache and regcache_read (virtual inheritance).  I concern
about the performance overhead of virtual inheritance, so I don't do it in
the patch.

gdb:

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

	* jit.c (struct jit_unwind_private) <regcache>: Change its type to
	 reg_buffer_rw *.
	(jit_unwind_reg_set_impl): Call raw_supply.
	(jit_frame_sniffer): Use reg_buffer_rw.
	* record-full.c (record_full_core_regbuf): Change its type.
	(record_full_core_open_1): Use reg_buffer_rw.
	(record_full_close): Likewise.
	(record_full_core_fetch_registers): Use regcache->raw_supply.
	(record_full_core_store_registers): Likewise.
	* regcache.c (regcache::get_register_status): Move it to
	reg_buffer.
	(regcache_raw_set_cached_value): Remove.
	(regcache::raw_set_cached_value): Remove.
	(regcache::raw_write): Call raw_supply.
	(regcache::raw_supply): Move it to reg_buffer_rw.
	* regcache.h (regcache_raw_set_cached_value): Remove.
	(reg_buffer_rw): New class.
This commit is contained in:
Yao Qi
2018-02-21 11:20:03 +00:00
parent daf6667d1f
commit c8ec2f334c
5 changed files with 65 additions and 61 deletions

View File

@@ -1097,7 +1097,7 @@ struct jit_unwind_private
{
/* Cached register values. See jit_frame_sniffer to see how this
works. */
struct regcache *regcache;
detached_regcache *regcache;
/* The frame being unwound. */
struct frame_info *this_frame;
@@ -1126,7 +1126,7 @@ jit_unwind_reg_set_impl (struct gdb_unwind_callbacks *cb, int dwarf_regnum,
return;
}
regcache_raw_set_cached_value (priv->regcache, gdb_reg, value->value);
priv->regcache->raw_supply (gdb_reg, value->value);
value->free (value);
}
@@ -1188,7 +1188,6 @@ jit_frame_sniffer (const struct frame_unwind *self,
struct jit_unwind_private *priv_data;
struct gdb_unwind_callbacks callbacks;
struct gdb_reader_funcs *funcs;
struct gdbarch *gdbarch;
callbacks.reg_get = jit_unwind_reg_get_impl;
callbacks.reg_set = jit_unwind_reg_set_impl;
@@ -1201,11 +1200,11 @@ jit_frame_sniffer (const struct frame_unwind *self,
gdb_assert (!*cache);
gdbarch = get_frame_arch (this_frame);
*cache = XCNEW (struct jit_unwind_private);
priv_data = (struct jit_unwind_private *) *cache;
priv_data->regcache = new regcache (gdbarch);
/* Take a snapshot of current regcache. */
priv_data->regcache = new detached_regcache (get_frame_arch (this_frame),
true);
priv_data->this_frame = this_frame;
callbacks.priv_data = priv_data;