Rename regcache_cooked_read_ftype and make a function_view

regcache_cooked_read_ftype can be converted to a function_view, which
allows us to use lambda functions and therefore avoid having to pass an
opaque pointer parameter.

Adjusting the fallouts showed that the "const regcache &" passed to the
readonly_detached_regcache constructor is cast to non-const in
do_cooked_read.  I changed the constructor parameter to be non-const.

Finally, I renamed the typedef from regcache_cooked_read_ftype to
register_read_ftype, since there is nothing that forces us to use it
only for regcaches nor cooked registers.

gdb/ChangeLog:

	* regcache.h (regcache_cooked_read_ftype): Rename to...
	(register_read_ftype): ...this, change type to function_view.
	(class reg_buffer) <save>: Remove src parameter.
	(readonly_detached_regcache) <readonly_detached_regcache>: Make
	parameter non-const in first overload.  Remove src parameter in
	second overload.
	* regcache.c (do_cooked_read): Remove.
	(readonly_detached_regcache::readonly_detached_regcache): Make
	parameter non-const, adjust call to other constructor.
	(reg_buffer::save): Remove src parameter.
	* frame.c (do_frame_register_read): Remove.
	(frame_save_as_regcache): Use lambda function.
	* ppc-linux-tdep.c (ppu2spu_unwind_register): Change type of src
	parameter to ppu2spu_data *.
	(ppu2spu_sniffer): Use lambda function.
This commit is contained in:
Simon Marchi
2018-06-20 12:49:03 -04:00
committed by Simon Marchi
parent f00674fe07
commit 302abd6e9f
5 changed files with 47 additions and 38 deletions

View File

@ -205,16 +205,12 @@ regcache::regcache (gdbarch *gdbarch, const address_space *aspace_)
m_ptid = minus_one_ptid;
}
static enum register_status
do_cooked_read (void *src, int regnum, gdb_byte *buf)
{
struct regcache *regcache = (struct regcache *) src;
return regcache->cooked_read (regnum, buf);
}
readonly_detached_regcache::readonly_detached_regcache (const regcache &src)
: readonly_detached_regcache (src.arch (), do_cooked_read, (void *) &src)
readonly_detached_regcache::readonly_detached_regcache (regcache &src)
: readonly_detached_regcache (src.arch (),
[&src] (int regnum, gdb_byte *buf)
{
return src.cooked_read (regnum, buf);
})
{
}
@ -264,8 +260,7 @@ reg_buffer::register_buffer (int regnum) const
}
void
reg_buffer::save (regcache_cooked_read_ftype *cooked_read,
void *src)
reg_buffer::save (register_read_ftype cooked_read)
{
struct gdbarch *gdbarch = m_descr->gdbarch;
int regnum;
@ -284,7 +279,7 @@ reg_buffer::save (regcache_cooked_read_ftype *cooked_read,
if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
{
gdb_byte *dst_buf = register_buffer (regnum);
enum register_status status = cooked_read (src, regnum, dst_buf);
enum register_status status = cooked_read (regnum, dst_buf);
gdb_assert (status != REG_UNKNOWN);