This is the mail archive of the gdb-patches@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]

[remote/non-stop] Make attaching not rely on querying the remote current thread.


I've applied this patch.  This makes attaching in non-stop mode not rely
on querying the remote current thread (or on the remote stub
setting it).

I've tested this with gdbserver+nonstop, gdbserver+nonstop+multiprocess,
and against DICOS.

-- 
Pedro Alves

2009-03-31  Pedro Alves  <pedro@codesourcery.com>

	* remote.c (remote_notice_new_inferior): Use ptid_is_pid.  Check
	if the thread's ptid without a thread id field is in the list
	before calling thread_change_ptid.
	(extended_remote_attach_1): In non-stop mode, do not rely on
	querying the current thread, instead, query the thread list, and
	select the first thread of the process.
	* gdbthread.h (first_thread_of_process): Declare.
	* thread.c (first_thread_of_process): Define.

---
 gdb/gdbthread.h |    4 ++++
 gdb/remote.c    |   43 +++++++++++++++++++++++++++++++++----------
 gdb/thread.c    |   16 ++++++++++++++++
 3 files changed, 53 insertions(+), 10 deletions(-)

Index: src/gdb/remote.c
===================================================================
--- src.orig/gdb/remote.c	2009-03-31 16:08:38.000000000 +0100
+++ src/gdb/remote.c	2009-03-31 16:09:11.000000000 +0100
@@ -1228,15 +1228,23 @@ remote_notice_new_inferior (ptid_t currt
   if (!in_thread_list (currthread))
     {
       struct inferior *inf = NULL;
+      int pid = ptid_get_pid (currthread);
 
-      if (ptid_equal (pid_to_ptid (ptid_get_pid (currthread)), inferior_ptid))
+      if (ptid_is_pid (inferior_ptid)
+	  && pid == ptid_get_pid (inferior_ptid))
 	{
 	  /* inferior_ptid has no thread member yet.  This can happen
 	     with the vAttach -> remote_wait,"TAAthread:" path if the
 	     stub doesn't support qC.  This is the first stop reported
 	     after an attach, so this is the main thread.  Update the
 	     ptid in the thread list.  */
-  	  thread_change_ptid (inferior_ptid, currthread);
+	  if (in_thread_list (pid_to_ptid (pid)))
+	    thread_change_ptid (inferior_ptid, currthread);
+	  else
+	    {
+	      remote_add_thread (currthread, running);
+	      inferior_ptid = currthread;
+	    }
  	  return;
 	}
 
@@ -3484,19 +3492,34 @@ extended_remote_attach_1 (struct target_
     error (_("Attaching to %s failed"),
 	   target_pid_to_str (pid_to_ptid (pid)));
 
+  remote_add_inferior (pid, 1);
+
   inferior_ptid = pid_to_ptid (pid);
 
-  /* Now, if we have thread information, update inferior_ptid.  */
-  inferior_ptid = remote_current_thread (inferior_ptid);
+  if (non_stop)
+    {
+      struct thread_info *thread;
 
-  remote_add_inferior (pid, 1);
+      /* Get list of threads.  */
+      remote_threads_info (target);
 
-  if (non_stop)
-    /* Get list of threads.  */
-    remote_threads_info (target);
+      thread = first_thread_of_process (pid);
+      if (thread)
+	inferior_ptid = thread->ptid;
+      else
+	inferior_ptid = pid_to_ptid (pid);
+
+      /* Invalidate our notion of the remote current thread.  */
+      record_currthread (minus_one_ptid);
+    }
   else
-    /* Add the main thread to the thread list.  */
-    add_thread_silent (inferior_ptid);
+    {
+      /* Now, if we have thread information, update inferior_ptid.  */
+      inferior_ptid = remote_current_thread (inferior_ptid);
+
+      /* Add the main thread to the thread list.  */
+      add_thread_silent (inferior_ptid);
+    }
 
   /* Next, if the target can specify a description, read it.  We do
      this before anything involving memory or registers.  */
Index: src/gdb/gdbthread.h
===================================================================
--- src.orig/gdb/gdbthread.h	2009-03-31 16:09:00.000000000 +0100
+++ src/gdb/gdbthread.h	2009-03-31 16:09:11.000000000 +0100
@@ -229,6 +229,10 @@ extern struct thread_info *find_thread_p
 /* Find thread by GDB user-visible thread number.  */
 struct thread_info *find_thread_id (int num);
 
+/* Finds the first thread of the inferior given by PID.  If PID is -1,
+   returns the first thread in the list.  */
+struct thread_info *first_thread_of_process (int pid);
+
 /* Change the ptid of thread OLD_PTID to NEW_PTID.  */
 void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
 
Index: src/gdb/thread.c
===================================================================
--- src.orig/gdb/thread.c	2009-03-31 16:08:58.000000000 +0100
+++ src/gdb/thread.c	2009-03-31 16:09:11.000000000 +0100
@@ -401,6 +401,22 @@ in_thread_list (ptid_t ptid)
   return 0;			/* Never heard of 'im */
 }
 
+/* Finds the first thread of the inferior given by PID.  If PID is -1,
+   return the first thread in the list.  */
+
+struct thread_info *
+first_thread_of_process (int pid)
+{
+  struct thread_info *tp, *ret = NULL;
+
+  for (tp = thread_list; tp; tp = tp->next)
+    if (pid == -1 || ptid_get_pid (tp->ptid) == pid)
+      if (ret == NULL || tp->num < ret->num)
+	ret = tp;
+
+  return ret;
+}
+
 /* Print a list of thread ids currently known, and the total number of
    threads. To be used from within catch_errors. */
 static int


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