diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2017-11-24 10:40:31 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2017-11-24 10:40:31 -0500 |
commit | 7aabaf9d4ad52a1df1f551908fbd8cafc5e7597a (patch) | |
tree | 236f4fa7e2efc5fce63f60afbe983e106e3a611d /gdb/linux-thread-db.c | |
parent | 21fe1c752e254167d953fa8c846280f63a3a5290 (diff) | |
download | gdb-7aabaf9d4ad52a1df1f551908fbd8cafc5e7597a.zip gdb-7aabaf9d4ad52a1df1f551908fbd8cafc5e7597a.tar.gz gdb-7aabaf9d4ad52a1df1f551908fbd8cafc5e7597a.tar.bz2 |
Create private_thread_info hierarchy
There are multiple definitions of the private_thread_info structure
compiled in the same GDB build. Because of the one definition rule, we
need to change this if we want to be able to make them non-POD (e.g. use
std::vector fields). This patch creates a class hierarchy, with
private_thread_info being an abstract base class, and all the specific
implementations inheriting from it.
In order to poison XNEW/xfree for non-POD types, it is also needed to
get rid of the xfree in thread_info::~thread_info, which operates on an
opaque type. This is replaced by thread_info::priv now being a
unique_ptr, which calls the destructor of the private_thread_info
subclass when the thread is being destroyed.
Including gdbthread.h from darwin-nat.h gave these errors:
/Users/simark/src/binutils-gdb/gdb/gdbthread.h:609:3: error: must use 'class' tag to refer to type 'thread_info' in this scope
thread_info *m_thread;
^
class
/usr/include/mach/thread_act.h:240:15: note: class 'thread_info' is hidden by a non-type declaration of 'thread_info' here
kern_return_t thread_info
^
It turns out that there is a thread_info function in the Darwin/XNU/mach API:
http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_info.html
Therefore, I had to add the class keyword at a couple of places in gdbthread.h,
I don't really see a way around it.
gdb/ChangeLog:
* gdbthread.h (private_thread_info): Define structure type, add
virtual pure destructor.
(thread_info) <priv>: Change type to unique_ptr.
<private_dtor>: Remove.
* thread.c (add_thread_with_info): Adjust to use of unique_ptr.
(private_thread_info::~private_thread_info): Provide default
implementation.
(thread_info::~thread_info): Don't call private_dtor nor
manually free priv.
* aix-thread.c (private_thread_info): Rename to ...
(aix_thread_info): ... this.
(get_aix_thread_info): New.
(sync_threadlists): Adjust.
(iter_tid): Adjust.
(aix_thread_resume): Adjust.
(aix_thread_fetch_registers): Adjust.
(aix_thread_store_registers): Adjust.
(aix_thread_extra_thread_info): Adjust.
* darwin-nat.h (private_thread_info): Rename to ...
(darwin_thread_info): ... this.
(get_darwin_thread_info): New.
* darwin-nat.c (darwin_init_thread_list): Adjust.
(darwin_check_new_threads): Adjust.
(thread_info_from_private_thread_info): Adjust.
* linux-thread-db.c (private_thread_info): Rename to ...
(thread_db_thread_info): ... this, initialize fields.
(get_thread_db_thread_info): New.
<dying>: Change type to bool.
(update_thread_state): Adjust to type rename.
(record_thread): Adjust to type rename an use of unique_ptr.
(thread_db_pid_to_str): Likewise.
(thread_db_extra_thread_info): Likewise.
(thread_db_thread_handle_to_thread_info): Likewise.
(thread_db_get_thread_local_address): Likewise.
* nto-tdep.h (private_thread_info): Rename to ...
(nto_thread_info): ... this, initialize fields.
(get_nto_thread_info): New.
<name>: Change type to std::string.
* nto-tdep.c (nto_extra_thread_info): Adjust to type rename and
use of unique_ptr.
* nto-procfs.c (update_thread_private_data_name): Adjust to
std::string change, allocate nto_private_thread_info with new.
(update_thread_private_data): Adjust to unique_ptr.
* remote.c (private_thread_info): Rename to ...
(remote_thread_info): ... this, initialize data members with
default values.
<extra, name>: Change type to std::string.
<thread_handle>: Change type to non-pointer.
(free_private_thread_info): Remove.
(get_private_info_thread): Rename to...
(get_remote_thread_info): ... this, change return type, adjust to
use of unique_ptr, use remote_thread_info constructor.
(remote_add_thread): Adjust.
(get_private_info_ptid): Rename to...
(get_remote_thread_info): ...this, change return type.
(remote_thread_name): Use get_remote_thread_info, adjust to
change to std::string.
(struct thread_item) <~thread_item>: Remove.
<thread_handle>: Make non pointer.
(start_thread): Adjust to thread_item::thread_handle type
change.
(remote_update_thread_list): Adjust to type name change, move
strings from temporary to long-lived object instead of
duplicating.
(remote_threads_extra_info): Use get_remote_thread_info.
(process_initial_stop_replies): Likewise.
(resume_clear_thread_private_info): Likewise.
(remote_resume): Adjust to type name change.
(remote_commit_resume): Use get_remote_thread_info.
(process_stop_reply): Adjust to type name change.
(remote_stopped_by_sw_breakpoint): Use get_remote_thread_info.
(remote_stopped_by_hw_breakpoint): Likewise.
(remote_stopped_by_watchpoint): Likewise.
(remote_stopped_data_address): Likewise.
(remote_core_of_thread): Likewise.
(remote_thread_handle_to_thread_info): Use
get_private_info_thread, adjust to thread_handle field type
change.
Diffstat (limited to 'gdb/linux-thread-db.c')
-rw-r--r-- | gdb/linux-thread-db.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index ea032fc..27f9ce8 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -251,16 +251,21 @@ delete_thread_db_info (int pid) /* 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 {}; }; - + +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) @@ -1040,7 +1045,7 @@ thread_db_inferior_created (struct target_ops *target, int from_tty) 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 @@ -1057,8 +1062,6 @@ record_thread (struct thread_db_info *info, 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. */ @@ -1066,7 +1069,7 @@ record_thread (struct thread_db_info *info, 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; @@ -1078,7 +1081,7 @@ record_thread (struct thread_db_info *info, 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 (); @@ -1381,11 +1384,10 @@ thread_db_pid_to_str (struct target_ops *ops, ptid_t 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; } @@ -1404,7 +1406,9 @@ thread_db_extra_thread_info (struct target_ops *self, 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; @@ -1434,7 +1438,9 @@ thread_db_thread_handle_to_thread_info (struct target_ops *ops, 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; } @@ -1464,9 +1470,8 @@ thread_db_get_thread_local_address (struct target_ops *ops, { 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) @@ -1479,7 +1484,7 @@ thread_db_get_thread_local_address (struct target_ops *ops, /* 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); } @@ -1497,8 +1502,7 @@ thread_db_get_thread_local_address (struct target_ops *ops, 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; } |