* [PATCH] Simplify regcache::xfer_part
@ 2017-10-16 13:18 Yao Qi
2017-10-16 15:58 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Yao Qi @ 2017-10-16 13:18 UTC (permalink / raw)
To: gdb-patches
Since xfer_part is already a class method, and only
{raw,cooked}_{read,write} are passed to it. We can remove these two
arguments, but add a bool argument is_raw, indicating raw registers or
cooked registers are accessed.
Regression tested on x86_64-linux, both native and gdbserver.
gdb:
2017-10-16 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache::xfer_part): Remove parameters read and
write, add parameter is_raw. All callers are updated.
---
gdb/regcache.c | 30 +++++++++++++-----------------
gdb/regcache.h | 4 +---
2 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index bf448ef..555db57 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -915,12 +915,7 @@ typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
enum register_status
regcache::xfer_part (int regnum, int offset, int len, void *in,
- const void *out,
- enum register_status (*read) (struct regcache *regcache,
- int regnum,
- gdb_byte *buf),
- void (*write) (struct regcache *regcache, int regnum,
- const gdb_byte *buf))
+ const void *out, bool is_raw)
{
struct gdbarch *gdbarch = arch ();
gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
@@ -938,7 +933,10 @@ regcache::xfer_part (int regnum, int offset, int len, void *in,
enum register_status status;
gdb_assert (read != NULL);
- status = read (this, regnum, reg);
+ if (is_raw)
+ status = raw_read (regnum, reg);
+ else
+ status = cooked_read (regnum, reg);
if (status != REG_VALID)
return status;
}
@@ -950,8 +948,10 @@ regcache::xfer_part (int regnum, int offset, int len, void *in,
/* ... write (when needed). */
if (out != NULL)
{
- gdb_assert (write != NULL);
- write (this, regnum, reg);
+ if (is_raw)
+ raw_write (regnum, reg);
+ else
+ cooked_write (regnum, reg);
}
return REG_VALID;
@@ -968,8 +968,7 @@ enum register_status
regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
{
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
- return xfer_part (regnum, offset, len, buf, NULL,
- regcache_raw_read, regcache_raw_write);
+ return xfer_part (regnum, offset, len, buf, NULL, true);
}
void
@@ -984,8 +983,7 @@ regcache::raw_write_part (int regnum, int offset, int len,
const gdb_byte *buf)
{
gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
- xfer_part (regnum, offset, len, NULL, buf, regcache_raw_read,
- regcache_raw_write);
+ xfer_part (regnum, offset, len, NULL, buf, true);
}
enum register_status
@@ -1000,8 +998,7 @@ enum register_status
regcache::cooked_read_part (int regnum, int offset, int len, gdb_byte *buf)
{
gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
- return xfer_part (regnum, offset, len, buf, NULL,
- regcache_cooked_read, regcache_cooked_write);
+ return xfer_part (regnum, offset, len, buf, NULL, false);
}
void
@@ -1016,8 +1013,7 @@ regcache::cooked_write_part (int regnum, int offset, int len,
const gdb_byte *buf)
{
gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
- xfer_part (regnum, offset, len, NULL, buf,
- regcache_cooked_read, regcache_cooked_write);
+ xfer_part (regnum, offset, len, NULL, buf, false);
}
/* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
diff --git a/gdb/regcache.h b/gdb/regcache.h
index 6f42fb9..460d83f 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -354,9 +354,7 @@ private:
void restore (struct regcache *src);
enum register_status xfer_part (int regnum, int offset, int len, void *in,
- const void *out,
- decltype (regcache_raw_read) read,
- decltype (regcache_raw_write) write);
+ const void *out, bool is_raw);
void transfer_regset (const struct regset *regset,
struct regcache *out_regcache,
--
1.9.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Simplify regcache::xfer_part
2017-10-16 13:18 [PATCH] Simplify regcache::xfer_part Yao Qi
@ 2017-10-16 15:58 ` Simon Marchi
2017-10-17 11:33 ` Yao Qi
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2017-10-16 15:58 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches
On 2017-10-16 09:18, Yao Qi wrote:
> Since xfer_part is already a class method, and only
> {raw,cooked}_{read,write} are passed to it. We can remove these two
> arguments, but add a bool argument is_raw, indicating raw registers or
> cooked registers are accessed.
>
> Regression tested on x86_64-linux, both native and gdbserver.
>
> gdb:
>
> 2017-10-16 Yao Qi <yao.qi@linaro.org>
>
> * regcache.c (regcache::xfer_part): Remove parameters read and
> write, add parameter is_raw. All callers are updated.
LGTM, it's a bit simpler to understand this way I think.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Simplify regcache::xfer_part
2017-10-16 15:58 ` Simon Marchi
@ 2017-10-17 11:33 ` Yao Qi
0 siblings, 0 replies; 3+ messages in thread
From: Yao Qi @ 2017-10-17 11:33 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
Simon Marchi <simon.marchi@polymtl.ca> writes:
> LGTM, it's a bit simpler to understand this way I think.
Thanks, patch is pushed in.
--
Yao (齐尧)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-17 11:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-16 13:18 [PATCH] Simplify regcache::xfer_part Yao Qi
2017-10-16 15:58 ` Simon Marchi
2017-10-17 11:33 ` Yao Qi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).