Use get_thread_regcache instead of get_current_regcache in post_create_inferior

Message ID 20191220175006.23147-1-simon.marchi@efficios.com
State New
Headers show
Series
  • Use get_thread_regcache instead of get_current_regcache in post_create_inferior
Related show

Commit Message

Simon Marchi Dec. 20, 2019, 5:50 p.m.
In post_create_inferior, we get the current thread using the
inferior_thread function and store it in `thr`.  We then call
get_current_regcache immediately after, which does:

  return get_thread_regcache (inferior_thread ());

This patch makes post_create_inferior use get_thread_regcache, passing
`thr`, saving an unnecessary inferior_thread call.

gdb/ChangeLog:

	* infcmd.c (post_create_inferior): Use get_thread_regcache
	instead of get_current_regcache.
---
 gdb/infcmd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.24.1

Comments

Simon Marchi Jan. 15, 2020, 5:50 p.m. | #1
On 2019-12-20 12:50 p.m., Simon Marchi wrote:
> In post_create_inferior, we get the current thread using the

> inferior_thread function and store it in `thr`.  We then call

> get_current_regcache immediately after, which does:

> 

>   return get_thread_regcache (inferior_thread ());

> 

> This patch makes post_create_inferior use get_thread_regcache, passing

> `thr`, saving an unnecessary inferior_thread call.

> 

> gdb/ChangeLog:

> 

> 	* infcmd.c (post_create_inferior): Use get_thread_regcache

> 	instead of get_current_regcache.

> ---

>  gdb/infcmd.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/gdb/infcmd.c b/gdb/infcmd.c

> index af66eaffd8a4..7aa1f77af005 100644

> --- a/gdb/infcmd.c

> +++ b/gdb/infcmd.c

> @@ -441,7 +441,8 @@ post_create_inferior (struct target_ops *target, int from_tty)

>    thr->suspend.stop_pc = 0;

>    try

>      {

> -      thr->suspend.stop_pc = regcache_read_pc (get_current_regcache ());

> +      regcache *rc = get_thread_regcache (thr);

> +      thr->suspend.stop_pc = regcache_read_pc (rc);

>      }

>    catch (const gdb_exception_error &ex)

>      {

> -- 

> 2.24.1

> 


I have pushed this patch.

Simon

Patch

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index af66eaffd8a4..7aa1f77af005 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -441,7 +441,8 @@  post_create_inferior (struct target_ops *target, int from_tty)
   thr->suspend.stop_pc = 0;
   try
     {
-      thr->suspend.stop_pc = regcache_read_pc (get_current_regcache ());
+      regcache *rc = get_thread_regcache (thr);
+      thr->suspend.stop_pc = regcache_read_pc (rc);
     }
   catch (const gdb_exception_error &ex)
     {