* win32-i386-low.c: Add 64-bit support.
[deliverable/binutils-gdb.git] / gdb / gdbserver / thread-db.c
index e169a50f3e5517bbe11d08e38ca271a448771ef1..8e7d7a9361a4813b491f6c510e35141ade3ce868 100644 (file)
@@ -1,5 +1,5 @@
 /* Thread management interface, for the remote server for GDB.
-   Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    Contributed by MontaVista Software.
@@ -743,7 +743,7 @@ thread_db_init (int use_events)
       if (use_events && thread_db_enable_reporting () == 0)
        {
          /* Keep trying; maybe event reporting will work later.  */
-         thread_db_free (proc, 0);
+         thread_db_mourn (proc);
          return 0;
        }
       thread_db_find_new_threads ();
@@ -755,35 +755,77 @@ thread_db_init (int use_events)
   return 0;
 }
 
+static int
+any_thread_of (struct inferior_list_entry *entry, void *args)
+{
+  int *pid_p = args;
+
+  if (ptid_get_pid (entry->id) == *pid_p)
+    return 1;
+
+  return 0;
+}
+
 /* Disconnect from libthread_db and free resources.  */
 
-void
-thread_db_free (struct process_info *proc, int detaching)
+static void
+disable_thread_event_reporting (struct process_info *proc)
 {
   struct thread_db *thread_db = proc->private->thread_db;
   if (thread_db)
     {
-      td_err_e (*td_ta_delete_p) (td_thragent_t *);
       td_err_e (*td_ta_clear_event_p) (const td_thragent_t *ta,
                                       td_thr_events_t *event);
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
       td_ta_clear_event_p = dlsym (thread_db->handle, "td_ta_clear_event");
-      td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
 #else
-      td_ta_delete_p = &td_ta_delete;
       td_ta_clear_event_p = &td_ta_clear_event;
 #endif
 
-      if (detaching && td_ta_clear_event_p != NULL)
+      if (td_ta_clear_event_p != NULL)
        {
+         struct thread_info *saved_inferior;
          td_thr_events_t events;
+         int pid;
+
+         pid = pid_of (proc);
+         saved_inferior = current_inferior;
+         current_inferior =
+           (struct thread_info *) find_inferior (&all_threads,
+                                                 any_thread_of, &pid);
 
          /* Set the process wide mask saying we aren't interested
             in any events anymore.  */
          td_event_fillset (&events);
          (*td_ta_clear_event_p) (thread_db->thread_agent, &events);
+
+         current_inferior = saved_inferior;
        }
+    }
+}
+
+void
+thread_db_detach (struct process_info *proc)
+{
+  disable_thread_event_reporting (proc);
+}
+
+/* Disconnect from libthread_db and free resources.  */
+
+void
+thread_db_mourn (struct process_info *proc)
+{
+  struct thread_db *thread_db = proc->private->thread_db;
+  if (thread_db)
+    {
+      td_err_e (*td_ta_delete_p) (td_thragent_t *);
+
+#ifndef USE_LIBTHREAD_DB_DIRECTLY
+      td_ta_delete_p = dlsym (thread_db->handle, "td_ta_delete");
+#else
+      td_ta_delete_p = &td_ta_delete;
+#endif
 
       if (td_ta_delete_p != NULL)
        (*td_ta_delete_p) (thread_db->thread_agent);
This page took 0.02472 seconds and 4 git commands to generate.