* gdb.base/remote.exp (get_sizeof): Remove.
[deliverable/binutils-gdb.git] / gdb / linux-thread-db.c
index 650cbaa296a6f43e4448aeac8e8cb8b5852bbff5..d3371d053a402070cdb934e77a9f5720bf87672c 100644 (file)
@@ -1,6 +1,6 @@
 /* libthread_db assisted debugging support, generic parts.
 
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -80,9 +80,6 @@
 /* This module's target vector.  */
 static struct target_ops thread_db_ops;
 
-/* The target vector that we call for things this module can't handle.  */
-static struct target_ops *target_beneath;
-
 /* Non-zero if we're using this module's target vector.  */
 static int using_thread_db;
 
@@ -379,12 +376,6 @@ thread_db_attach_lwp (ptid_t ptid)
   return 1;
 }
 
-void
-thread_db_init (struct target_ops *target)
-{
-  target_beneath = target;
-}
-
 static void *
 verbose_dlsym (void *handle, const char *name)
 {
@@ -780,14 +771,21 @@ detach_thread (ptid_t ptid)
 }
 
 static void
-thread_db_detach (char *args, int from_tty)
+thread_db_detach (struct target_ops *ops, char *args, int from_tty)
 {
+  struct target_ops *target_beneath = find_target_beneath (ops);
+
   disable_thread_event_reporting ();
 
-  target_beneath->to_detach (args, from_tty);
+  /* Forget about the child's process ID.  We shouldn't need it
+     anymore.  */
+  proc_handle.pid = 0;
+
+  /* Detach thread_db target ops.  */
+  unpush_target (&thread_db_ops);
+  using_thread_db = 0;
 
-  /* Should this be done by detach_command?  */
-  target_mourn_inferior ();
+  target_beneath->to_detach (target_beneath, args, from_tty);
 }
 
 /* Check if PID is currently stopped at the location of a thread event
@@ -880,16 +878,19 @@ check_event (ptid_t ptid)
 }
 
 static ptid_t
-thread_db_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
+thread_db_wait (struct target_ops *ops,
+               ptid_t ptid, struct target_waitstatus *ourstatus)
 {
-  ptid = target_beneath->to_wait (ptid, ourstatus);
+  struct target_ops *beneath = find_target_beneath (ops);
+
+  ptid = beneath->to_wait (beneath, ptid, ourstatus);
 
   if (ourstatus->kind == TARGET_WAITKIND_IGNORE)
     return ptid;
 
   if (ourstatus->kind == TARGET_WAITKIND_EXITED
-    || ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
-    return pid_to_ptid (-1);
+      || ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
+    return ptid;
 
   if (ourstatus->kind == TARGET_WAITKIND_EXECD)
     {
@@ -927,48 +928,25 @@ thread_db_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
 }
 
 static void
-thread_db_mourn_inferior (void)
+thread_db_mourn_inferior (struct target_ops *ops)
 {
+  struct target_ops *target_beneath = find_target_beneath (ops);
+
   /* Forget about the child's process ID.  We shouldn't need it
      anymore.  */
   proc_handle.pid = 0;
 
-  target_beneath->to_mourn_inferior ();
+  target_beneath->to_mourn_inferior (target_beneath);
 
   /* Delete the old thread event breakpoints.  Do this after mourning
      the inferior, so that we don't try to uninsert them.  */
   remove_thread_event_breakpoints ();
 
   /* Detach thread_db target ops.  */
-  unpush_target (&thread_db_ops);
+  unpush_target (ops);
   using_thread_db = 0;
 }
 
-static int
-thread_db_can_async_p (void)
-{
-  return target_beneath->to_can_async_p ();
-}
-
-static int
-thread_db_is_async_p (void)
-{
-  return target_beneath->to_is_async_p ();
-}
-
-static void
-thread_db_async (void (*callback) (enum inferior_event_type event_type,
-                                  void *context), void *context)
-{
-  return target_beneath->to_async (callback, context);
-}
-
-static int
-thread_db_async_mask (int mask)
-{
-  return target_beneath->to_async_mask (mask);
-}
-
 static int
 find_new_threads_callback (const td_thrhandle_t *th_p, void *data)
 {
@@ -1040,9 +1018,10 @@ thread_db_find_new_threads (void)
 }
 
 static char *
-thread_db_pid_to_str (ptid_t ptid)
+thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
 {
   struct thread_info *thread_info = find_thread_pid (ptid);
+  struct target_ops *beneath;
 
   if (thread_info != NULL && thread_info->private != NULL)
     {
@@ -1057,8 +1036,9 @@ thread_db_pid_to_str (ptid_t ptid)
       return buf;
     }
 
-  if (target_beneath->to_pid_to_str (ptid))
-    return target_beneath->to_pid_to_str (ptid);
+  beneath = find_target_beneath (ops);
+  if (beneath->to_pid_to_str (beneath, ptid))
+    return beneath->to_pid_to_str (beneath, ptid);
 
   return normal_pid_to_str (ptid);
 }
@@ -1082,11 +1062,13 @@ thread_db_extra_thread_info (struct thread_info *info)
    is stored at OFFSET within the thread local storage for thread PTID.  */
 
 static CORE_ADDR
-thread_db_get_thread_local_address (ptid_t ptid,
+thread_db_get_thread_local_address (struct target_ops *ops,
+                                   ptid_t ptid,
                                    CORE_ADDR lm,
                                    CORE_ADDR offset)
 {
   struct thread_info *thread_info;
+  struct target_ops *beneath;
 
   /* If we have not discovered any threads yet, check now.  */
   if (!have_threads ())
@@ -1136,13 +1118,43 @@ thread_db_get_thread_local_address (ptid_t ptid,
              : (CORE_ADDR) (uintptr_t) address);
     }
 
-  if (target_beneath->to_get_thread_local_address)
-    return target_beneath->to_get_thread_local_address (ptid, lm, offset);
+  beneath = find_target_beneath (ops);
+  if (beneath->to_get_thread_local_address)
+    return beneath->to_get_thread_local_address (beneath, ptid, lm, offset);
   else
     throw_error (TLS_GENERIC_ERROR,
                 _("TLS not supported on this target"));
 }
 
+/* Callback routine used to find a thread based on the TID part of
+   its PTID.  */
+
+static int
+thread_db_find_thread_from_tid (struct thread_info *thread, void *data)
+{
+  long *tid = (long *) data;
+
+  if (thread->private->tid == *tid)
+    return 1;
+
+  return 0;
+}
+
+/* Implement the to_get_ada_task_ptid target method for this target.  */
+
+static ptid_t
+thread_db_get_ada_task_ptid (long lwp, long thread)
+{
+  struct thread_info *thread_info;
+
+  thread_db_find_new_threads ();
+  thread_info = iterate_over_threads (thread_db_find_thread_from_tid, &thread);
+
+  gdb_assert (thread_info != NULL);
+
+  return (thread_info->ptid);
+}
+
 static void
 init_thread_db_ops (void)
 {
@@ -1159,10 +1171,7 @@ init_thread_db_ops (void)
   thread_db_ops.to_get_thread_local_address
     = thread_db_get_thread_local_address;
   thread_db_ops.to_extra_thread_info = thread_db_extra_thread_info;
-  thread_db_ops.to_can_async_p = thread_db_can_async_p;
-  thread_db_ops.to_is_async_p = thread_db_is_async_p;
-  thread_db_ops.to_async = thread_db_async;
-  thread_db_ops.to_async_mask = thread_db_async_mask;
+  thread_db_ops.to_get_ada_task_ptid = thread_db_get_ada_task_ptid;
   thread_db_ops.to_magic = OPS_MAGIC;
 }
 
This page took 0.025843 seconds and 4 git commands to generate.