/* libthread_db assisted debugging support, generic parts.
- Copyright (C) 1999-2017 Free Software Foundation, Inc.
+ Copyright (C) 1999-2018 Free Software Foundation, Inc.
This file is part of GDB.
/* Use "struct private_thread_info" to cache thread state. This is
a substantial optimization. */
-struct private_thread_info
+struct thread_db_thread_info : public private_thread_info
{
/* Flag set when we see a TD_DEATH event for this thread. */
- unsigned int dying:1;
+ bool dying = false;
/* Cached thread state. */
- td_thrhandle_t th;
- thread_t tid;
+ td_thrhandle_t th {};
+ thread_t tid {};
};
-\f
+
+static thread_db_thread_info *
+get_thread_db_thread_info (thread_info *thread)
+{
+ return static_cast<thread_db_thread_info *> (thread->priv.get ());
+}
static const char *
thread_db_err_str (td_err_e err)
from libthread_db thread state information. */
static void
-update_thread_state (struct private_thread_info *priv,
+update_thread_state (thread_db_thread_info *priv,
const td_thrinfo_t *ti_p)
{
priv->dying = (ti_p->ti_state == TD_THR_UNKNOWN
ptid_t ptid, const td_thrhandle_t *th_p,
const td_thrinfo_t *ti_p)
{
- struct private_thread_info *priv;
-
/* A thread ID of zero may mean the thread library has not
initialized yet. Leave private == NULL until the thread library
has initialized. */
return tp;
/* Construct the thread's private data. */
- priv = XCNEW (struct private_thread_info);
+ thread_db_thread_info *priv = new thread_db_thread_info;
priv->th = *th_p;
priv->tid = ti_p->ti_tid;
if (tp == NULL || tp->state == THREAD_EXITED)
tp = add_thread_with_info (ptid, priv);
else
- tp->priv = priv;
+ tp->priv.reset (priv);
if (target_has_execution)
check_thread_signals ();
}
static void
-thread_db_detach (struct target_ops *ops, const char *args, int from_tty)
+thread_db_detach (struct target_ops *ops, inferior *inf, int from_tty)
{
struct target_ops *target_beneath = find_target_beneath (ops);
- struct thread_db_info *info;
- info = get_thread_db_info (ptid_get_pid (inferior_ptid));
-
- if (info)
- delete_thread_db_info (ptid_get_pid (inferior_ptid));
+ delete_thread_db_info (inf->pid);
- target_beneath->to_detach (target_beneath, args, from_tty);
+ target_beneath->to_detach (target_beneath, inf, from_tty);
/* NOTE: From this point on, inferior_ptid is null_ptid. */
if (thread_info != NULL && thread_info->priv != NULL)
{
static char buf[64];
- thread_t tid;
+ thread_db_thread_info *priv = get_thread_db_thread_info (thread_info);
- tid = thread_info->priv->tid;
snprintf (buf, sizeof (buf), "Thread 0x%lx (LWP %ld)",
- (unsigned long) tid, ptid_get_lwp (ptid));
+ (unsigned long) priv->tid, ptid_get_lwp (ptid));
return buf;
}
if (info->priv == NULL)
return NULL;
- if (info->priv->dying)
+ thread_db_thread_info *priv = get_thread_db_thread_info (info);
+
+ if (priv->dying)
return "Exiting";
return NULL;
ALL_NON_EXITED_THREADS (tp)
{
- if (tp->inf == inf && tp->priv != NULL && handle_tid == tp->priv->tid)
+ thread_db_thread_info *priv = get_thread_db_thread_info (tp);
+
+ if (tp->inf == inf && priv != NULL && handle_tid == priv->tid)
return tp;
}
{
td_err_e err;
psaddr_t address;
- struct thread_db_info *info;
-
- info = get_thread_db_info (ptid_get_pid (ptid));
+ thread_db_info *info = get_thread_db_info (ptid_get_pid (ptid));
+ thread_db_thread_info *priv = get_thread_db_thread_info (thread_info);
/* Finally, get the address of the variable. */
if (lm != 0)
/* Note the cast through uintptr_t: this interface only works if
a target address fits in a psaddr_t, which is a host pointer.
So a 32-bit debugger can not access 64-bit TLS through this. */
- err = info->td_thr_tls_get_addr_p (&thread_info->priv->th,
+ err = info->td_thr_tls_get_addr_p (&priv->th,
(psaddr_t)(uintptr_t) lm,
offset, &address);
}
PR libc/16831 due to GDB PR threads/16954 LOAD_MODULE is also NULL.
The constant number 1 depends on GNU __libc_setup_tls
initialization of l_tls_modid to 1. */
- err = info->td_thr_tlsbase_p (&thread_info->priv->th,
- 1, &address);
+ err = info->td_thr_tlsbase_p (&priv->th, 1, &address);
address = (char *) address + offset;
}