* gdbcore.h (struct regcache): Add forward declaration.
[deliverable/binutils-gdb.git] / gdb / linux-thread-db.c
index d91a894166d5cbc6bc84840d133e34c99e4f414b..7e5e4eb4fd327dc53c5b63eec0404a32b84c4d57 100644 (file)
@@ -1,6 +1,6 @@
 /* libthread_db assisted debugging support, generic parts.
 
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -39,6 +39,8 @@
 #include "gdbcore.h"
 #include "linux-nat.h"
 
+#include <signal.h>
+
 #ifdef HAVE_GNU_LIBC_VERSION_H
 #include <gnu/libc-version.h>
 #endif
@@ -207,6 +209,18 @@ thread_db_err_str (td_err_e err)
       return "only part of register set was written/read";
     case TD_NOXREGS:
       return "X register set not available for this thread";
+#ifdef THREAD_DB_HAS_TD_NOTALLOC
+    case TD_NOTALLOC:
+      return "thread has not yet allocated TLS for given module";
+#endif
+#ifdef THREAD_DB_HAS_TD_VERSION
+    case TD_VERSION:
+      return "versions of libpthread and libthread_db do not match";
+#endif
+#ifdef THREAD_DB_HAS_TD_NOTLS
+    case TD_NOTLS:
+      return "there is no TLS segment in the given module";
+#endif
     default:
       snprintf (buf, sizeof (buf), "unknown thread_db error '%d'", err);
       return buf;
@@ -567,6 +581,10 @@ check_for_thread_db (void)
   td_err_e err;
   static int already_loaded;
 
+  /* Do nothing if we couldn't load libthread_db.so.1.  */
+  if (td_ta_new_p == NULL)
+    return;
+
   /* First time through, report that libthread_db was successfuly
      loaded.  Can't print this in in thread_db_load as, at that stage,
      the interpreter and it's console haven't started.  */
@@ -599,6 +617,10 @@ check_for_thread_db (void)
   if (!target_has_execution)
     return;
 
+  /* Don't attempt to use thread_db for remote targets.  */
+  if (!target_can_run (&current_target))
+    return;
+
   /* Initialize the structure that identifies the child process.  */
   proc_handle.pid = GET_PID (inferior_ptid);
 
@@ -672,6 +694,13 @@ attach_thread (ptid_t ptid, const td_thrhandle_t *th_p,
 
   check_thread_signals ();
 
+  if (ti_p->ti_state == TD_THR_UNKNOWN || ti_p->ti_state == TD_THR_ZOMBIE)
+    return;                    /* A zombie thread -- do not attach.  */
+
+  /* Under GNU/Linux, we have to attach to each and every thread.  */
+  if (lin_lwp_attach_lwp (BUILD_LWP (ti_p->ti_lid, GET_PID (ptid)), 0) < 0)
+    return;
+
   /* Add the thread to GDB's thread list.  */
   tp = add_thread (ptid);
   tp->private = xmalloc (sizeof (struct private_thread_info));
@@ -680,14 +709,6 @@ attach_thread (ptid_t ptid, const td_thrhandle_t *th_p,
   if (verbose)
     printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
 
-  if (ti_p->ti_state == TD_THR_UNKNOWN || ti_p->ti_state == TD_THR_ZOMBIE)
-    return;                    /* A zombie thread -- do not attach.  */
-
-  /* Under GNU/Linux, we have to attach to each and every thread.  */
-#ifdef ATTACH_LWP
-  ATTACH_LWP (BUILD_LWP (ti_p->ti_lid, GET_PID (ptid)), 0);
-#endif
-
   /* Enable thread event reporting for this thread.  */
   err = td_thr_event_enable_p (th_p, 1);
   if (err != TD_OK)
@@ -872,7 +893,8 @@ thread_db_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
        post-processing and bail out early.  */
     return ptid;
 
-  if (ourstatus->kind == TARGET_WAITKIND_EXITED)
+  if (ourstatus->kind == TARGET_WAITKIND_EXITED
+    || ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
     return pid_to_ptid (-1);
 
   if (ourstatus->kind == TARGET_WAITKIND_EXECD)
@@ -1080,7 +1102,8 @@ thread_db_get_thread_local_address (ptid_t ptid,
       thread_db_map_id2thr (thread_info, 1);
 
       /* Finally, get the address of the variable.  */
-      err = td_thr_tls_get_addr_p (&thread_info->private->th, (void *) lm,
+      err = td_thr_tls_get_addr_p (&thread_info->private->th,
+                                  (void *)(size_t) lm,
                                   offset, &address);
 
 #ifdef THREAD_DB_HAS_TD_NOTALLOC
This page took 0.069064 seconds and 4 git commands to generate.