/* 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.
#include "gdb_proc_service.h"
#include "gdb_thread_db.h"
+#include "gdb_vecs.h"
#ifndef USE_LIBTHREAD_DB_DIRECTLY
#include <dlfcn.h>
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,
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)
{
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)
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;
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)
{
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)
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;
if ((a) == NULL) \
{ \
if (debug_threads) \
- fprintf (stderr, "dlsym: %s\n", dlerror ()); \
+ debug_printf ("dlsym: %s\n", dlerror ()); \
if (required) \
{ \
free (tdb); \
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;
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;
}
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 ())
{
}
}
+ 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;
}