| Index: gdb/gdbserver/thread-db.c | 
| diff --git a/gdb/gdbserver/thread-db.c b/gdb/gdbserver/thread-db.c | 
| index 795f9267ddb379150300663c192448105f34bb91..e8d3481738f2941a89fcb9a4e5f8ef7f96fce2e5 100644 | 
| --- a/gdb/gdbserver/thread-db.c | 
| +++ b/gdb/gdbserver/thread-db.c | 
| @@ -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-2013 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> | 
| @@ -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; | 
|  | 
| @@ -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) | 
| @@ -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,6 +784,7 @@ thread_db_load_search (void) | 
| } | 
| } | 
|  | 
| +  free_char_ptr_vec (dir_vec); | 
| if (debug_threads) | 
| fprintf (stderr, "thread_db_load_search returning %d\n", rc); | 
| return rc; | 
|  |