/* libthread_db assisted debugging support, generic parts.
- Copyright (C) 1999-2015 Free Software Foundation, Inc.
+ Copyright (C) 1999-2017 Free Software Foundation, Inc.
This file is part of GDB.
#include <signal.h>
#include <ctype.h>
#include "nat/linux-namespaces.h"
+#include <algorithm>
/* GNU/Linux libthread_db support.
created, thread IDs (usually, the result of pthread_self), and
thread-local variables.
- The libthread_db interface originates on Solaris, where it is
- both more powerful and more complicated. This implementation
- only works for LinuxThreads and NPTL, the two glibc threading
- libraries. It assumes that each thread is permanently assigned
- to a single light-weight process (LWP).
+ The libthread_db interface originates on Solaris, where it is both
+ more powerful and more complicated. This implementation only works
+ for NPTL, the glibc threading library. It assumes that each thread
+ is permanently assigned to a single light-weight process (LWP). At
+ some point it also supported the older LinuxThreads library, but it
+ no longer does.
libthread_db-specific information is stored in the "private" field
of struct thread_info. When the field is NULL we do not yet have
td_ta_new_ftype *td_ta_new_p;
td_ta_map_lwp2thr_ftype *td_ta_map_lwp2thr_p;
td_ta_thr_iter_ftype *td_ta_thr_iter_p;
- td_thr_validate_ftype *td_thr_validate_p;
td_thr_get_info_ftype *td_thr_get_info_p;
td_thr_tls_get_addr_ftype *td_thr_tls_get_addr_p;
td_thr_tlsbase_ftype *td_thr_tlsbase_p;
};
\f
-static char *
+static const char *
thread_db_err_str (td_err_e err)
{
static char buf[64];
int
thread_db_notice_clone (ptid_t parent, ptid_t child)
{
- td_thrhandle_t th;
- td_thrinfo_t ti;
- td_err_e err;
struct thread_db_info *info;
info = get_thread_db_info (ptid_get_pid (child));
/* These are essential. */
CHK (TDB_VERBOSE_DLSYM (info, td_ta_map_lwp2thr));
- CHK (TDB_VERBOSE_DLSYM (info, td_ta_thr_iter));
- CHK (TDB_VERBOSE_DLSYM (info, td_thr_validate));
CHK (TDB_VERBOSE_DLSYM (info, td_thr_get_info));
/* These are not essential. */
TDB_DLSYM (info, td_thr_tls_get_addr);
TDB_DLSYM (info, td_thr_tlsbase);
-#undef TDB_VERBOSE_DLSYM
-#undef TDB_DLSYM
-#undef CHK
-
/* It's best to avoid td_ta_thr_iter if possible. That walks data
structures in the inferior's address space that may be corrupted,
or, if the target is running, may change while we walk them. If
currently on core targets, as it uses ptrace directly. */
if (target_has_execution
&& linux_proc_task_list_dir_exists (ptid_get_pid (inferior_ptid)))
+ info->td_ta_thr_iter_p = NULL;
+ else
+ CHK (TDB_VERBOSE_DLSYM (info, td_ta_thr_iter));
+
+#undef TDB_VERBOSE_DLSYM
+#undef TDB_DLSYM
+#undef CHK
+
+ if (info->td_ta_thr_iter_p == NULL)
{
struct lwp_info *lp;
int pid = ptid_get_pid (inferior_ptid);
{
warning (_ ("Target and debugger are in different PID "
"namespaces; thread lists and other data are "
- "likely unreliable"));
+ "likely unreliable. "
+ "Connect to gdbserver inside the container."));
}
}
}
ptid_t ptid, const td_thrhandle_t *th_p,
const td_thrinfo_t *ti_p)
{
- td_err_e err;
struct private_thread_info *priv;
- int new_thread = (tp == NULL);
/* A thread ID of zero may mean the thread library has not
initialized yet. Leave private == NULL until the thread library
ptid = beneath->to_wait (beneath, ptid, ourstatus, options);
- if (ourstatus->kind == TARGET_WAITKIND_IGNORE)
- return ptid;
-
- if (ourstatus->kind == TARGET_WAITKIND_EXITED
- || ourstatus->kind == TARGET_WAITKIND_SIGNALLED)
- return ptid;
+ switch (ourstatus->kind)
+ {
+ case TARGET_WAITKIND_IGNORE:
+ case TARGET_WAITKIND_EXITED:
+ case TARGET_WAITKIND_THREAD_EXITED:
+ case TARGET_WAITKIND_SIGNALLED:
+ return ptid;
+ }
info = get_thread_db_info (ptid_get_pid (ptid));
data.new_threads = 0;
/* See comment in thread_db_update_thread_list. */
- gdb_assert (!target_has_execution);
+ gdb_assert (info->td_ta_thr_iter_p != NULL);
TRY
{
thread_db_find_new_threads_2 (ptid, 0);
}
-static int
-update_thread_core (struct lwp_info *info, void *closure)
-{
- info->core = linux_common_core_of_thread (info->ptid);
- return 0;
-}
-
-/* Update the thread list using td_ta_thr_iter. */
+/* Implement the to_update_thread_list target method for this
+ target. */
static void
-thread_db_update_thread_list_td_ta_thr_iter (struct target_ops *ops)
+thread_db_update_thread_list (struct target_ops *ops)
{
struct thread_db_info *info;
struct inferior *inf;
if (thread == NULL || thread->executing)
continue;
+ /* It's best to avoid td_ta_thr_iter if possible. That walks
+ data structures in the inferior's address space that may be
+ corrupted, or, if the target is running, the list may change
+ while we walk it. In the latter case, it's possible that a
+ thread exits just at the exact time that causes GDB to get
+ stuck in an infinite loop. To avoid pausing all threads
+ whenever the core wants to refresh the thread list, we
+ instead use thread_from_lwp immediately when we see an LWP
+ stop. That uses thread_db entry points that do not walk
+ libpthread's thread list, so should be safe, as well as more
+ efficient. */
+ if (target_has_execution_1 (thread->ptid))
+ continue;
+
thread_db_find_new_threads_1 (thread->ptid);
}
-}
-
-/* Implement the to_update_thread_list target method for this
- target. */
-static void
-thread_db_update_thread_list (struct target_ops *ops)
-{
- /* It's best to avoid td_ta_thr_iter if possible. That walks data
- structures in the inferior's address space that may be corrupted,
- or, if the target is running, the list may change while we walk
- it. In the latter case, it's possible that a thread exits just
- at the exact time that causes GDB to get stuck in an infinite
- loop. To avoid pausing all threads whenever the core wants to
- refresh the thread list, use thread_from_lwp immediately when we
- see an LWP stop. That uses thread_db entry points that do not
- walk libpthread's thread list, so should be safe, as well as
- more efficient. */
- if (target_has_execution)
- ops->beneath->to_update_thread_list (ops->beneath);
- else
- thread_db_update_thread_list_td_ta_thr_iter (ops);
-
- if (target_has_execution)
- iterate_over_lwps (minus_one_ptid /* iterate over all */,
- update_thread_core, NULL);
+ /* Give the beneath target a chance to do extra processing. */
+ ops->beneath->to_update_thread_list (ops->beneath);
}
-static char *
+static const char *
thread_db_pid_to_str (struct target_ops *ops, ptid_t ptid)
{
struct thread_info *thread_info = find_thread_ptid (ptid);
/* Return a string describing the state of the thread specified by
INFO. */
-static char *
+static const char *
thread_db_extra_thread_info (struct target_ops *self,
struct thread_info *info)
{
if (i == 0 || strcmp (array[i - 1]->filename, array[i]->filename) != 0)
{
unique_filenames++;
- max_filename_len = max (max_filename_len,
- strlen (array[i]->filename));
+ max_filename_len = std::max (max_filename_len,
+ strlen (array[i]->filename));
if (i > 0)
{
pids_len -= strlen (", ");
- max_pids_len = max (max_pids_len, pids_len);
+ max_pids_len = std::max (max_pids_len, pids_len);
}
pids_len = 0;
}
if (i)
{
pids_len -= strlen (", ");
- max_pids_len = max (max_pids_len, pids_len);
+ max_pids_len = std::max (max_pids_len, pids_len);
}
/* Table header shifted right by preceding "libthread-db: " would not match
its columns. */
if (info_count > 0 && args == auto_load_info_scripts_pattern_nl)
- ui_out_text (uiout, "\n");
+ uiout->text ("\n");
make_cleanup_ui_out_table_begin_end (uiout, 2, unique_filenames,
"LinuxThreadDbTable");
- ui_out_table_header (uiout, max_filename_len, ui_left, "filename",
- "Filename");
- ui_out_table_header (uiout, pids_len, ui_left, "PIDs", "Pids");
- ui_out_table_body (uiout);
+ uiout->table_header (max_filename_len, ui_left, "filename", "Filename");
+ uiout->table_header (pids_len, ui_left, "PIDs", "Pids");
+ uiout->table_body ();
pids = (char *) xmalloc (max_pids_len + 1);
make_cleanup (xfree, pids);
/* Note I is incremented inside the cycle, not at its end. */
for (i = 0; i < info_count;)
{
- struct cleanup *chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
char *pids_end;
info = array[i];
- ui_out_field_string (uiout, "filename", info->filename);
+ uiout->field_string ("filename", info->filename);
pids_end = pids;
while (i < info_count && strcmp (info->filename, array[i]->filename) == 0)
}
*pids_end = '\0';
- ui_out_field_string (uiout, "pids", pids);
+ uiout->field_string ("pids", pids);
- ui_out_text (uiout, "\n");
- do_cleanups (chain);
+ uiout->text ("\n");
}
do_cleanups (back_to);
if (info_count == 0)
- ui_out_message (uiout, 0, _("No auto-loaded libthread-db.\n"));
+ uiout->message (_("No auto-loaded libthread-db.\n"));
}
static void
/* Defer loading of libthread_db.so until inferior is running.
This allows gdb to load correct libthread_db for a given
- executable -- there could be mutiple versions of glibc,
- compiled with LinuxThreads or NPTL, and until there is
- a running inferior, we can't tell which libthread_db is
- the correct one to load. */
+ executable -- there could be multiple versions of glibc,
+ and until there is a running inferior, we can't tell which
+ libthread_db is the correct one to load. */
libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);