New gdbserver option --debug-format=timestamp.
[deliverable/binutils-gdb.git] / gdb / gdbserver / thread-db.c
index 795f9267ddb379150300663c192448105f34bb91..df06b9dbbb9d77afb98eac5cc7e467499248e836 100644 (file)
@@ -1,5 +1,5 @@
 /* Thread management interface, for the remote server for GDB.
-   Copyright (C) 2002, 2004-2012 Free Software Foundation, Inc.
+   Copyright (C) 2002-2014 Free Software Foundation, Inc.
 
    Contributed by MontaVista Software.
 
@@ -28,6 +28,7 @@ static int thread_db_use_events;
 
 #include "gdb_proc_service.h"
 #include "gdb_thread_db.h"
+#include "gdb_vecs.h"
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
 #include <dlfcn.h>
@@ -193,7 +194,7 @@ thread_db_create_event (CORE_ADDR where)
     fatal ("unexpected thread_db->td_ta_event_getmsg_p == NULL");
 
   if (debug_threads)
-    fprintf (stderr, "Thread creation event.\n");
+    debug_printf ("Thread creation event.\n");
 
   /* FIXME: This assumes we don't get another event.
      In the LinuxThreads implementation, this is safe,
@@ -288,8 +289,8 @@ find_one_thread (ptid_t ptid)
           lwpid, thread_db_err_str (err));
 
   if (debug_threads)
-    fprintf (stderr, "Found thread %ld (LWP %d)\n",
-            ti.ti_tid, ti.ti_lid);
+    debug_printf ("Found thread %ld (LWP %d)\n",
+                 ti.ti_tid, ti.ti_lid);
 
   if (lwpid != ti.ti_lid)
     {
@@ -325,8 +326,8 @@ attach_thread (const td_thrhandle_t *th_p, td_thrinfo_t *ti_p)
   struct lwp_info *lwp;
 
   if (debug_threads)
-    fprintf (stderr, "Attaching to thread %ld (LWP %d)\n",
-            ti_p->ti_tid, ti_p->ti_lid);
+    debug_printf ("Attaching to thread %ld (LWP %d)\n",
+                 ti_p->ti_tid, ti_p->ti_lid);
   linux_attach_lwp (ti_p->ti_lid);
   lwp = find_lwp_pid (pid_to_ptid (ti_p->ti_lid));
   if (lwp == NULL)
@@ -405,7 +406,7 @@ static void
 thread_db_find_new_threads (void)
 {
   td_err_e err;
-  ptid_t ptid = ((struct inferior_list_entry *) current_inferior)->id;
+  ptid_t ptid = current_ptid;
   struct thread_db *thread_db = current_process ()->private->thread_db;
   int loop, iteration;
 
@@ -431,8 +432,8 @@ thread_db_find_new_threads (void)
                                         TD_THR_LOWEST_PRIORITY,
                                         TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
       if (debug_threads)
-       fprintf (stderr, "Found %d threads in iteration %d.\n",
-                new_thread_count, iteration);
+       debug_printf ("Found %d threads in iteration %d.\n",
+                     new_thread_count, iteration);
 
       if (new_thread_count != 0)
        {
@@ -493,7 +494,7 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
   thread_db = proc->private->thread_db;
 
   /* If the thread layer is not (yet) initialized, fail.  */
-  if (!thread_db->all_symbols_looked_up)
+  if (thread_db == NULL || !thread_db->all_symbols_looked_up)
     return TD_ERR;
 
   if (thread_db->td_thr_tls_get_addr_p == NULL)
@@ -545,7 +546,7 @@ thread_db_load_search (void)
   if (err != TD_OK)
     {
       if (debug_threads)
-       fprintf (stderr, "td_ta_new(): %s\n", thread_db_err_str (err));
+       debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
       free (tdb);
       proc->private->thread_db = NULL;
       return 0;
@@ -594,7 +595,7 @@ try_thread_db_load_1 (void *handle)
       if ((a) == NULL)                                         \
        {                                                       \
          if (debug_threads)                                    \
-           fprintf (stderr, "dlsym: %s\n", dlerror ());        \
+           debug_printf ("dlsym: %s\n", dlerror ());           \
          if (required)                                         \
            {                                                   \
              free (tdb);                                       \
@@ -612,7 +613,7 @@ try_thread_db_load_1 (void *handle)
   if (err != TD_OK)
     {
       if (debug_threads)
-       fprintf (stderr, "td_ta_new(): %s\n", thread_db_err_str (err));
+       debug_printf ("td_ta_new(): %s\n", thread_db_err_str (err));
       free (tdb);
       proc->private->thread_db = NULL;
       return 0;
@@ -662,13 +663,13 @@ try_thread_db_load (const char *library)
   void *handle;
 
   if (debug_threads)
-    fprintf (stderr, "Trying host libthread_db library: %s.\n",
-            library);
+    debug_printf ("Trying host libthread_db library: %s.\n",
+                 library);
   handle = dlopen (library, RTLD_NOW);
   if (handle == NULL)
     {
       if (debug_threads)
-       fprintf (stderr, "dlopen failed: %s.\n", dlerror ());
+       debug_printf ("dlopen failed: %s.\n", dlerror ());
       return 0;
     }
 
@@ -741,39 +742,31 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len)
 static int
 thread_db_load_search (void)
 {
-  const char *search_path;
-  int rc = 0;
+  VEC (char_ptr) *dir_vec;
+  char *this_dir;
+  int i, rc = 0;
 
   if (libthread_db_search_path == NULL)
     libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);
 
-  search_path = libthread_db_search_path;
-  while (*search_path)
+  dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
+
+  for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
     {
-      const char *end = strchr (search_path, ':');
-      const char *this_dir = search_path;
+      const int pdir_len = sizeof ("$pdir") - 1;
       size_t this_dir_len;
 
-      if (end)
-       {
-         this_dir_len = end - search_path;
-         search_path += this_dir_len + 1;
-       }
-      else
-       {
-         this_dir_len = strlen (this_dir);
-         search_path += this_dir_len;
-       }
+      this_dir_len = strlen (this_dir);
 
-      if (this_dir_len == sizeof ("$pdir") - 1
-         && strncmp (this_dir, "$pdir", this_dir_len) == 0)
+      if (strncmp (this_dir, "$pdir", pdir_len) == 0
+         && (this_dir[pdir_len] == '\0'
+             || this_dir[pdir_len] == '/'))
        {
          /* We don't maintain a list of loaded libraries so we don't know
             where libpthread lives.  We *could* fetch the info, but we don't
             do that yet.  Ignore it.  */
        }
-      else if (this_dir_len == sizeof ("$sdir") - 1
-              && strncmp (this_dir, "$sdir", this_dir_len) == 0)
+      else if (strcmp (this_dir, "$sdir") == 0)
        {
          if (try_thread_db_load_from_sdir ())
            {
@@ -791,8 +784,9 @@ thread_db_load_search (void)
        }
     }
 
+  free_char_ptr_vec (dir_vec);
   if (debug_threads)
-    fprintf (stderr, "thread_db_load_search returning %d\n", rc);
+    debug_printf ("thread_db_load_search returning %d\n", rc);
   return rc;
 }
 
This page took 0.028307 seconds and 4 git commands to generate.