This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Switch current_thread to lwp's thread in install_software_single_step_breakpoints


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=984a2c042e82f2306183d9d165c5cb99e4341503

commit 984a2c042e82f2306183d9d165c5cb99e4341503
Author: Yao Qi <yao.qi@linaro.org>
Date:   Thu Jul 21 12:12:18 2016 +0100

    Switch current_thread to lwp's thread in install_software_single_step_breakpoints
    
    install_software_single_step_breakpoints has parameter lwp, but still
    need to switch to current_thread.  In order to simplify its caller,
    we do the current_thread save/restore inside install_software_single_step_breakpoints.
    
    gdb/gdbserver:
    
    2016-07-21  Yao Qi  <yao.qi@linaro.org>
    
    	* gdbthread.h (make_cleanup_restore_current_thread): Declare.
    	* inferiors.c (do_restore_current_thread_cleanup): New function.
    	(make_cleanup_restore_current_thread): Likewise.
    	* linux-low.c (install_software_single_step_breakpoints): Call
    	make_cleanup_restore_current_thread.  Switch current_thread to
    	thread.

Diff:
---
 gdb/gdbserver/ChangeLog   |  9 +++++++++
 gdb/gdbserver/gdbthread.h |  3 +++
 gdb/gdbserver/inferiors.c | 12 ++++++++++++
 gdb/gdbserver/linux-low.c |  8 ++++++--
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index b5e9c96..867a5a2 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,14 @@
 2016-07-21  Yao Qi  <yao.qi@linaro.org>
 
+	* gdbthread.h (make_cleanup_restore_current_thread): Declare.
+	* inferiors.c (do_restore_current_thread_cleanup): New function.
+	(make_cleanup_restore_current_thread): Likewise.
+	* linux-low.c (install_software_single_step_breakpoints): Call
+	make_cleanup_restore_current_thread.  Switch current_thread to
+	thread.
+
+2016-07-21  Yao Qi  <yao.qi@linaro.org>
+
 	* mem-break.c (struct reinsert_breakpoint) <ptid>: New field.
 	(set_reinsert_breakpoint): New parameter ptid.  Callers updated.
 	(clone_one_breakpoint): Likewise.
diff --git a/gdb/gdbserver/gdbthread.h b/gdb/gdbserver/gdbthread.h
index 4dcb1b7..d2326fb 100644
--- a/gdb/gdbserver/gdbthread.h
+++ b/gdb/gdbserver/gdbthread.h
@@ -87,4 +87,7 @@ struct thread_info *find_any_thread_of_pid (int pid);
 /* Get current thread ID (Linux task ID).  */
 #define current_ptid (current_thread->entry.id)
 
+/* Create a cleanup to restore current_thread.  */
+struct cleanup *make_cleanup_restore_current_thread (void);
+
 #endif /* GDB_THREAD_H */
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 1f5149f..7888f3c 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -411,3 +411,15 @@ current_process (void)
   gdb_assert (current_thread != NULL);
   return get_thread_process (current_thread);
 }
+
+static void
+do_restore_current_thread_cleanup (void *arg)
+{
+  current_thread = (struct thread_info *) arg;
+}
+
+struct cleanup *
+make_cleanup_restore_current_thread (void)
+{
+  return make_cleanup (do_restore_current_thread_cleanup, current_thread);
+}
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index c0b2ac0..9c675a4 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -4202,10 +4202,14 @@ install_software_single_step_breakpoints (struct lwp_info *lwp)
 {
   int i;
   CORE_ADDR pc;
-  struct regcache *regcache = get_thread_regcache (current_thread, 1);
+  struct thread_info *thread = get_lwp_thread (lwp);
+  struct regcache *regcache = get_thread_regcache (thread, 1);
   VEC (CORE_ADDR) *next_pcs = NULL;
-  struct cleanup *old_chain = make_cleanup (VEC_cleanup (CORE_ADDR), &next_pcs);
+  struct cleanup *old_chain = make_cleanup_restore_current_thread ();
+
+  make_cleanup (VEC_cleanup (CORE_ADDR), &next_pcs);
 
+  current_thread = thread;
   next_pcs = (*the_low_target.get_next_pcs) (regcache);
 
   for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); ++i)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]