gdb: move some variables to an inner scope in save_waitstatus
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 29 Apr 2021 14:16:28 +0000 (10:16 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 29 Apr 2021 14:16:28 +0000 (10:16 -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.

Change-Id: Ief1463728755b4dcc142c0a0a76896e9d594ae84

gdb/ChangeLog
gdb/infrun.c

index f24075461b64740451e57e7bfe88be508d463fc2..ea65327e6e0c949db824403fd160244ac2d4e4b4 100644 (file)
@@ -1,3 +1,7 @@
+2021-04-29  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * infrun.c (save_waitstatus): Move variables to inner scope.
+
 2021-04-29  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * NEWS: Fix typo and stray full stop.
index cfec07994f4c22b8bedb895d5821f874f9dd7259..90bab8d984f5b1bd557e8cb58faf04c17f38a79e 100644 (file)
@@ -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);
This page took 0.032412 seconds and 4 git commands to generate.