Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: move some variables to an inner scope in save_waitstatus
@ 2021-04-29  3:54 Simon Marchi via Gdb-patches
  2021-04-29  7:46 ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi via Gdb-patches @ 2021-04-29  3:54 UTC (permalink / raw)
  To: gdb-patches

These two variables:

      struct regcache *regcache = get_thread_regcache (tp);
      const address_space *aspace = regcache->aspace ();

are only needed inside the "if".  Getting a thread's regcache is a
somewhat expensive operation, so it's good to avoid it if not necessary.
Move the variable declarations and their initialization to the "if"
scope.

gdb/ChangeLog:

	* infrun.c (save_waitstatus): Move variables to inner scope.

Change-Id: Ief1463728755b4dcc142c0a0a76896e9d594ae84
---
 gdb/infrun.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index cfec07994f4c..90bab8d984f5 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4703,12 +4703,11 @@ save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
   tp->suspend.waitstatus = *ws;
   tp->suspend.waitstatus_pending_p = 1;
 
-  struct regcache *regcache = get_thread_regcache (tp);
-  const address_space *aspace = regcache->aspace ();
-
   if (ws->kind == TARGET_WAITKIND_STOPPED
       && ws->value.sig == GDB_SIGNAL_TRAP)
     {
+      struct regcache *regcache = get_thread_regcache (tp);
+      const address_space *aspace = regcache->aspace ();
       CORE_ADDR pc = regcache_read_pc (regcache);
 
       adjust_pc_after_break (tp, &tp->suspend.waitstatus);
-- 
2.30.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: move some variables to an inner scope in save_waitstatus
  2021-04-29  3:54 [PATCH] gdb: move some variables to an inner scope in save_waitstatus Simon Marchi via Gdb-patches
@ 2021-04-29  7:46 ` Andrew Burgess
  2021-04-29 14:17   ` Simon Marchi via Gdb-patches
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2021-04-29  7:46 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-04-28 23:54:51 -0400]:

> These two variables:
> 
>       struct regcache *regcache = get_thread_regcache (tp);
>       const address_space *aspace = regcache->aspace ();
> 
> are only needed inside the "if".  Getting a thread's regcache is a
> somewhat expensive operation, so it's good to avoid it if not necessary.
> Move the variable declarations and their initialization to the "if"
> scope.
> 
> gdb/ChangeLog:
> 
> 	* infrun.c (save_waitstatus): Move variables to inner scope.

LGTM.

Thanks,
Andrew

> 
> Change-Id: Ief1463728755b4dcc142c0a0a76896e9d594ae84
> ---
>  gdb/infrun.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index cfec07994f4c..90bab8d984f5 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -4703,12 +4703,11 @@ save_waitstatus (struct thread_info *tp, const target_waitstatus *ws)
>    tp->suspend.waitstatus = *ws;
>    tp->suspend.waitstatus_pending_p = 1;
>  
> -  struct regcache *regcache = get_thread_regcache (tp);
> -  const address_space *aspace = regcache->aspace ();
> -
>    if (ws->kind == TARGET_WAITKIND_STOPPED
>        && ws->value.sig == GDB_SIGNAL_TRAP)
>      {
> +      struct regcache *regcache = get_thread_regcache (tp);
> +      const address_space *aspace = regcache->aspace ();
>        CORE_ADDR pc = regcache_read_pc (regcache);
>  
>        adjust_pc_after_break (tp, &tp->suspend.waitstatus);
> -- 
> 2.30.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: move some variables to an inner scope in save_waitstatus
  2021-04-29  7:46 ` Andrew Burgess
@ 2021-04-29 14:17   ` Simon Marchi via Gdb-patches
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi via Gdb-patches @ 2021-04-29 14:17 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On 2021-04-29 3:46 a.m., Andrew Burgess wrote:
> * Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> [2021-04-28 23:54:51 -0400]:
> 
>> These two variables:
>>
>>       struct regcache *regcache = get_thread_regcache (tp);
>>       const address_space *aspace = regcache->aspace ();
>>
>> are only needed inside the "if".  Getting a thread's regcache is a
>> somewhat expensive operation, so it's good to avoid it if not necessary.
>> Move the variable declarations and their initialization to the "if"
>> scope.
>>
>> gdb/ChangeLog:
>>
>> 	* infrun.c (save_waitstatus): Move variables to inner scope.
> 
> LGTM.
> 
> Thanks,
> Andrew

Pushed, thanks.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-29 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-29  3:54 [PATCH] gdb: move some variables to an inner scope in save_waitstatus Simon Marchi via Gdb-patches
2021-04-29  7:46 ` Andrew Burgess
2021-04-29 14:17   ` Simon Marchi via Gdb-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox