2011-05-26 Pedro Alves <pedro@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / linux-thread-db.c
index aa8e2c7c44d3ae79dc36131ec60be37ccf9580a2..f43efc74c4898943a36530f254222625012a6981 100644 (file)
@@ -812,6 +812,38 @@ try_thread_db_load (const char *library)
   return 0;
 }
 
+/* Subroutine of try_thread_db_load_from_pdir to simplify it.
+   Try loading libthread_db from the same directory as OBJ.
+   The result is true for success.  */
+
+static int
+try_thread_db_load_from_pdir_1 (struct objfile *obj)
+{
+  struct cleanup *cleanup;
+  char *path, *cp;
+  int result;
+
+  if (obj->name[0] != '/')
+    {
+      warning (_("Expected absolute pathname for libpthread in the"
+                " inferior, but got %s."), obj->name);
+      return 0;
+    }
+
+  path = xmalloc (strlen (obj->name) + 1 + strlen (LIBTHREAD_DB_SO) + 1);
+  cleanup = make_cleanup (xfree, path);
+
+  strcpy (path, obj->name);
+  cp = strrchr (path, '/');
+  /* This should at minimum hit the first character.  */
+  gdb_assert (cp != NULL);
+  strcpy (cp + 1, LIBTHREAD_DB_SO);
+  result = try_thread_db_load (path);
+
+  do_cleanups (cleanup);
+  return result;
+}
+
 /* Handle $pdir in libthread-db-search-path.
    Look for libthread_db in the directory of libpthread.
    The result is true for success.  */
@@ -824,28 +856,15 @@ try_thread_db_load_from_pdir (void)
   ALL_OBJFILES (obj)
     if (libpthread_name_p (obj->name))
       {
-       char path[PATH_MAX], *cp;
-
-       gdb_assert (strlen (obj->name) < sizeof (path));
-       strcpy (path, obj->name);
-       cp = strrchr (path, '/');
-
-       if (cp == NULL)
-         {
-           warning (_("Expected absolute pathname for libpthread in the"
-                      " inferior, but got %s."), path);
-         }
-       else if (cp + 1 + strlen (LIBTHREAD_DB_SO) + 1 > path + sizeof (path))
-         {
-           warning (_("Unexpected: path to libpthread in the inferior is"
-                      " too long: %s"), path);
-         }
-       else
-         {
-           strcpy (cp + 1, LIBTHREAD_DB_SO);
-           if (try_thread_db_load (path))
-             return 1;
-         }
+       if (try_thread_db_load_from_pdir_1 (obj))
+         return 1;
+
+       /* We may have found the separate-debug-info version of
+          libpthread, and it may live in a directory without a matching
+          libthread_db.  */
+       if (obj->separate_debug_objfile_backlink != NULL)
+         return try_thread_db_load_from_pdir_1 (obj->separate_debug_objfile_backlink);
+
        return 0;
       }
 
@@ -869,24 +888,20 @@ try_thread_db_load_from_sdir (void)
 static int
 try_thread_db_load_from_dir (const char *dir, size_t dir_len)
 {
-  char path[PATH_MAX];
+  struct cleanup *cleanup;
+  char *path;
+  int result;
 
-  if (dir_len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof (path))
-    {
-      char *cp = xmalloc (dir_len + 1);
-
-      memcpy (cp, dir, dir_len);
-      cp[dir_len] = '\0';
-      warning (_("libthread-db-search-path component too long,"
-                " ignored: %s."), cp);
-      xfree (cp);
-      return 0;
-    }
+  path = xmalloc (dir_len + 1 + strlen (LIBTHREAD_DB_SO) + 1);
+  cleanup = make_cleanup (xfree, path);
 
   memcpy (path, dir, dir_len);
   path[dir_len] = '/';
   strcpy (path + dir_len + 1, LIBTHREAD_DB_SO);
-  return try_thread_db_load (path);
+  result = try_thread_db_load (path);
+
+  do_cleanups (cleanup);
+  return result;
 }
 
 /* Search libthread_db_search_path for libthread_db which "agrees"
This page took 0.024428 seconds and 4 git commands to generate.