[v5,2/5] gdb/infrun: move a 'regcache_read_pc' call down to first use

Message ID 48a722182b3cc68d5d2ebffa7161857087e417e1.1586187408.git.tankut.baris.aktemur@intel.com
State Superseded
Headers show
Series
  • Handling already-exited threads in 'stop_all_threads'
Related show

Commit Message

Pedro Alves via Gdb-patches April 6, 2020, 3:45 p.m.
In infrun.c's resume_1 function, move the definition of the local
variable PC down to its first use.  This is useful if the thread we want
to resume is already gone with a pending exit event, because we avoid
the error we would see otherwise when trying to read the PC.

gdb/ChangeLog:
2020-04-03  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* infrun.c (resume_1): Move a 'regcache_read_pc' call down to first
	use.
---
 gdb/infrun.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.17.1

Comments

Pedro Alves via Gdb-patches April 16, 2020, 4:12 p.m. | #1
On 4/6/20 4:45 PM, Tankut Baris Aktemur via Gdb-patches wrote:
> In infrun.c's resume_1 function, move the definition of the local

> variable PC down to its first use.  This is useful if the thread we want

> to resume is already gone with a pending exit event, because we avoid

> the error we would see otherwise when trying to read the PC.

> 

> gdb/ChangeLog:

> 2020-04-03  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

> 

> 	* infrun.c (resume_1): Move a 'regcache_read_pc' call down to first

> 	use.


OK.

Thanks,
Pedro Alves

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index d6265c6df51..f5d3b79e0d0 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2271,7 +2271,6 @@  resume_1 (enum gdb_signal sig)
   struct regcache *regcache = get_current_regcache ();
   struct gdbarch *gdbarch = regcache->arch ();
   struct thread_info *tp = inferior_thread ();
-  CORE_ADDR pc = regcache_read_pc (regcache);
   const address_space *aspace = regcache->aspace ();
   ptid_t resume_ptid;
   /* This represents the user's step vs continue request.  When
@@ -2350,6 +2349,8 @@  resume_1 (enum gdb_signal sig)
       step = 0;
     }
 
+  CORE_ADDR pc = regcache_read_pc (regcache);
+
   if (debug_infrun)
     fprintf_unfiltered (gdb_stdlog,
 			"infrun: resume (step=%d, signal=%s), "