* [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
@ 2017-06-27 7:37 Yao Qi
2017-07-17 9:04 ` Alan Hayward
0 siblings, 1 reply; 5+ messages in thread
From: Yao Qi @ 2017-06-27 7:37 UTC (permalink / raw)
To: gdb-patches
Nowadays, regcache_cpy is used where src is read-only and dst is not
read-only, so the regcache_cpy can be simplified to handle this case only.
As a result, regcache::cpy_no_passthrough, which is about two read-only
regcache copy, is no longer used, remove it as well.
Regression tested on x86_64-linux, both native and gdbserver.
gdb:
2017-06-27 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache_cpy): Simplify it.
(regcache::cpy_no_passthrough): Remove it.
* regcache.h (cpy_no_passthrough): Remove it.
---
gdb/regcache.c | 31 ++-----------------------------
gdb/regcache.h | 2 --
2 files changed, 2 insertions(+), 31 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 7eeb737..e8f92d6 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -388,36 +388,9 @@ 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);
+ gdb_assert (src->m_readonly_p && !dst->m_readonly_p);
- if (!src->m_readonly_p)
- regcache_save (dst, do_cooked_read, src);
- else if (!dst->m_readonly_p)
- dst->restore (src);
- else
- dst->cpy_no_passthrough (src);
-}
-
-/* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
- which is pass-through, this does not go through to the target.
- Only values values already in the cache are transferred. The SRC and DST
- buffers must not overlap. */
-
-void
-regcache::cpy_no_passthrough (struct regcache *src)
-{
- gdb_assert (src != NULL);
- gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
- /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
- move of data into a thread's regcache. Doing this would be silly
- - it would mean that regcache->register_status would be
- completely invalid. */
- gdb_assert (m_readonly_p && src->m_readonly_p);
-
- memcpy (m_registers, src->m_registers,
- m_descr->sizeof_cooked_registers);
- memcpy (m_register_status, src->m_register_status,
- m_descr->sizeof_cooked_register_status);
+ dst->restore (src);
}
struct regcache *
diff --git a/gdb/regcache.h b/gdb/regcache.h
index b416d5e..03c042a 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -369,8 +369,6 @@ private:
void restore (struct regcache *src);
- void cpy_no_passthrough (struct regcache *src);
-
enum register_status xfer_part (int regnum, int offset, int len, void *in,
const void *out,
decltype (regcache_raw_read) read,
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
2017-06-27 7:37 [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough Yao Qi
@ 2017-07-17 9:04 ` Alan Hayward
2017-07-17 11:32 ` Yao Qi
0 siblings, 1 reply; 5+ messages in thread
From: Alan Hayward @ 2017-07-17 9:04 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches, nd
> On 27 Jun 2017, at 08:37, Yao Qi <qiyaoltc@gmail.com> wrote:
>
> Nowadays, regcache_cpy is used where src is read-only and dst is not
> read-only, so the regcache_cpy can be simplified to handle this case only.
> As a result, regcache::cpy_no_passthrough, which is about two read-only
> regcache copy, is no longer used, remove it as well.
>
I like the simplification.
But, I don’t think it’s clear that regcache_cpy now only handles the single case
of read-only src with !read-only dest. It only becomes clear after reading the
gdb_asserts.
Would it be better to remove regcache_cpy completely?
There are only three places that use it, and they would call (for example)
get_current_regcache ()->restore (scratch) instead.
That would make the caller code clearer, and would remove an outside the class
regcache_ function.
If not, then there should be a comment above regcache_cpy stating the
restrictions.
> Regression tested on x86_64-linux, both native and gdbserver.
>
> gdb:
>
> 2017-06-27 Yao Qi <yao.qi@linaro.org>
>
> * regcache.c (regcache_cpy): Simplify it.
> (regcache::cpy_no_passthrough): Remove it.
> * regcache.h (cpy_no_passthrough): Remove it.
> ---
> gdb/regcache.c | 31 ++-----------------------------
> gdb/regcache.h | 2 --
> 2 files changed, 2 insertions(+), 31 deletions(-)
>
> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index 7eeb737..e8f92d6 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -388,36 +388,9 @@ 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);
> + gdb_assert (src->m_readonly_p && !dst->m_readonly_p);
>
> - if (!src->m_readonly_p)
> - regcache_save (dst, do_cooked_read, src);
> - else if (!dst->m_readonly_p)
> - dst->restore (src);
> - else
> - dst->cpy_no_passthrough (src);
> -}
> -
> -/* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
> - which is pass-through, this does not go through to the target.
> - Only values values already in the cache are transferred. The SRC and DST
> - buffers must not overlap. */
> -
> -void
> -regcache::cpy_no_passthrough (struct regcache *src)
> -{
> - gdb_assert (src != NULL);
> - gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
> - /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
> - move of data into a thread's regcache. Doing this would be silly
> - - it would mean that regcache->register_status would be
> - completely invalid. */
> - gdb_assert (m_readonly_p && src->m_readonly_p);
> -
> - memcpy (m_registers, src->m_registers,
> - m_descr->sizeof_cooked_registers);
> - memcpy (m_register_status, src->m_register_status,
> - m_descr->sizeof_cooked_register_status);
> + dst->restore (src);
> }
>
> struct regcache *
> diff --git a/gdb/regcache.h b/gdb/regcache.h
> index b416d5e..03c042a 100644
> --- a/gdb/regcache.h
> +++ b/gdb/regcache.h
> @@ -369,8 +369,6 @@ private:
>
> void restore (struct regcache *src);
>
> - void cpy_no_passthrough (struct regcache *src);
> -
> enum register_status xfer_part (int regnum, int offset, int len, void *in,
> const void *out,
> decltype (regcache_raw_read) read,
> --
> 1.9.1
>
Alan.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
2017-07-17 9:04 ` Alan Hayward
@ 2017-07-17 11:32 ` Yao Qi
2017-07-18 9:01 ` Alan Hayward
0 siblings, 1 reply; 5+ messages in thread
From: Yao Qi @ 2017-07-17 11:32 UTC (permalink / raw)
To: Alan Hayward; +Cc: gdb-patches, nd
Alan Hayward <Alan.Hayward@arm.com> writes:
> If not, then there should be a comment above regcache_cpy stating the
> restrictions.
I updated the comments to regcache_dup and regcache_cpy.
--
Yao (齐尧)
From 4ff91e90cad73f9420f8ca37fc7e22f465ebcb88 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Mon, 19 Jun 2017 22:45:12 +0100
Subject: [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
Nowadays, regcache_cpy is used where src is read-only and dst is not
read-only, so the regcache_cpy can be simplified to handle this case only.
As a result, regcache::cpy_no_passthrough, which is about two read-only
regcache copy, is no longer used, remove it as well.
gdb:
2017-07-17 Yao Qi <yao.qi@linaro.org>
* regcache.c (regcache_cpy): Simplify it.
(regcache::cpy_no_passthrough): Remove it.
* regcache.h (cpy_no_passthrough): Remove it.
(regcache_dup, regcache_cpy): Update comments.
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 7eeb737..e8f92d6 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -388,36 +388,9 @@ 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);
+ gdb_assert (src->m_readonly_p && !dst->m_readonly_p);
- if (!src->m_readonly_p)
- regcache_save (dst, do_cooked_read, src);
- else if (!dst->m_readonly_p)
- dst->restore (src);
- else
- dst->cpy_no_passthrough (src);
-}
-
-/* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
- which is pass-through, this does not go through to the target.
- Only values values already in the cache are transferred. The SRC and DST
- buffers must not overlap. */
-
-void
-regcache::cpy_no_passthrough (struct regcache *src)
-{
- gdb_assert (src != NULL);
- gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
- /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
- move of data into a thread's regcache. Doing this would be silly
- - it would mean that regcache->register_status would be
- completely invalid. */
- gdb_assert (m_readonly_p && src->m_readonly_p);
-
- memcpy (m_registers, src->m_registers,
- m_descr->sizeof_cooked_registers);
- memcpy (m_register_status, src->m_register_status,
- m_descr->sizeof_cooked_register_status);
+ dst->restore (src);
}
struct regcache *
diff --git a/gdb/regcache.h b/gdb/regcache.h
index b416d5e..aa64a00 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -369,8 +369,6 @@ private:
void restore (struct regcache *src);
- void cpy_no_passthrough (struct regcache *src);
-
enum register_status xfer_part (int regnum, int offset, int len, void *in,
const void *out,
decltype (regcache_raw_read) read,
@@ -415,13 +413,12 @@ private:
regcache_cpy (struct regcache *dst, struct regcache *src);
};
-/* Copy/duplicate the contents of a register cache. By default, the
- operation is pass-through. Writes to DST and reads from SRC will
- go through to the target. See also regcache_cpy_no_passthrough.
-
- regcache_cpy can not have overlapping SRC and DST buffers. */
-
+/* 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);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
2017-07-17 11:32 ` Yao Qi
@ 2017-07-18 9:01 ` Alan Hayward
2017-07-18 11:49 ` Yao Qi
0 siblings, 1 reply; 5+ messages in thread
From: Alan Hayward @ 2017-07-18 9:01 UTC (permalink / raw)
To: Yao Qi; +Cc: gdb-patches, nd
> On 17 Jul 2017, at 12:32, Yao Qi <qiyaoltc@gmail.com> wrote:
>
> Alan Hayward <Alan.Hayward@arm.com> writes:
>
>> If not, then there should be a comment above regcache_cpy stating the
>> restrictions.
>
> I updated the comments to regcache_dup and regcache_cpy.
Ok for me.
>
> --
> Yao (齐尧)
> From 4ff91e90cad73f9420f8ca37fc7e22f465ebcb88 Mon Sep 17 00:00:00 2001
> From: Yao Qi <yao.qi@linaro.org>
> Date: Mon, 19 Jun 2017 22:45:12 +0100
> Subject: [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
>
> Nowadays, regcache_cpy is used where src is read-only and dst is not
> read-only, so the regcache_cpy can be simplified to handle this case only.
> As a result, regcache::cpy_no_passthrough, which is about two read-only
> regcache copy, is no longer used, remove it as well.
>
> gdb:
>
> 2017-07-17 Yao Qi <yao.qi@linaro.org>
>
> * regcache.c (regcache_cpy): Simplify it.
> (regcache::cpy_no_passthrough): Remove it.
> * regcache.h (cpy_no_passthrough): Remove it.
> (regcache_dup, regcache_cpy): Update comments.
>
> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index 7eeb737..e8f92d6 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -388,36 +388,9 @@ 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);
> + gdb_assert (src->m_readonly_p && !dst->m_readonly_p);
>
> - if (!src->m_readonly_p)
> - regcache_save (dst, do_cooked_read, src);
> - else if (!dst->m_readonly_p)
> - dst->restore (src);
> - else
> - dst->cpy_no_passthrough (src);
> -}
> -
> -/* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
> - which is pass-through, this does not go through to the target.
> - Only values values already in the cache are transferred. The SRC and DST
> - buffers must not overlap. */
> -
> -void
> -regcache::cpy_no_passthrough (struct regcache *src)
> -{
> - gdb_assert (src != NULL);
> - gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
> - /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
> - move of data into a thread's regcache. Doing this would be silly
> - - it would mean that regcache->register_status would be
> - completely invalid. */
> - gdb_assert (m_readonly_p && src->m_readonly_p);
> -
> - memcpy (m_registers, src->m_registers,
> - m_descr->sizeof_cooked_registers);
> - memcpy (m_register_status, src->m_register_status,
> - m_descr->sizeof_cooked_register_status);
> + dst->restore (src);
> }
>
> struct regcache *
> diff --git a/gdb/regcache.h b/gdb/regcache.h
> index b416d5e..aa64a00 100644
> --- a/gdb/regcache.h
> +++ b/gdb/regcache.h
> @@ -369,8 +369,6 @@ private:
>
> void restore (struct regcache *src);
>
> - void cpy_no_passthrough (struct regcache *src);
> -
> enum register_status xfer_part (int regnum, int offset, int len, void *in,
> const void *out,
> decltype (regcache_raw_read) read,
> @@ -415,13 +413,12 @@ private:
> regcache_cpy (struct regcache *dst, struct regcache *src);
> };
>
> -/* Copy/duplicate the contents of a register cache. By default, the
> - operation is pass-through. Writes to DST and reads from SRC will
> - go through to the target. See also regcache_cpy_no_passthrough.
> -
> - regcache_cpy can not have overlapping SRC and DST buffers. */
> -
> +/* 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);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough
2017-07-18 9:01 ` Alan Hayward
@ 2017-07-18 11:49 ` Yao Qi
0 siblings, 0 replies; 5+ messages in thread
From: Yao Qi @ 2017-07-18 11:49 UTC (permalink / raw)
To: Alan Hayward; +Cc: gdb-patches, nd
Alan Hayward <Alan.Hayward@arm.com> writes:
>> I updated the comments to regcache_dup and regcache_cpy.
>
> Ok for me.
I pushed it in.
--
Yao (齐尧)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-07-18 11:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27 7:37 [PATCH] Simplify regcache_cpy and remove regcache::cpy_no_passthrough Yao Qi
2017-07-17 9:04 ` Alan Hayward
2017-07-17 11:32 ` Yao Qi
2017-07-18 9:01 ` Alan Hayward
2017-07-18 11:49 ` 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).