From 7aabaf9d4ad52a1df1f551908fbd8cafc5e7597a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 24 Nov 2017 10:40:31 -0500 Subject: 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) : Change type to unique_ptr. : 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. : 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. : 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. : Change type to std::string. : 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. : 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. --- gdb/aix-thread.c | 57 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) (limited to 'gdb/aix-thread.c') diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index b5c9f3b..1a1d769 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -84,11 +84,20 @@ static int debug_aix_thread; /* Private data attached to each element in GDB's thread list. */ -struct private_thread_info { +struct aix_thread_info : public private_thread_info +{ pthdb_pthread_t pdtid; /* thread's libpthdebug id */ pthdb_tid_t tid; /* kernel thread id */ }; +/* Return the aix_thread_info attached to THREAD. */ + +static aix_thread_info * +get_aix_thread_info (thread_info *thread) +{ + return static_cast (thread->priv.get ()); +} + /* Information about a thread of which libpthdebug is aware. */ struct pd_thread { @@ -756,10 +765,12 @@ sync_threadlists (void) } else if (gi == gcount) { - thread = add_thread (ptid_build (infpid, 0, pbuf[pi].pthid)); - thread->priv = XNEW (struct private_thread_info); - thread->priv->pdtid = pbuf[pi].pdtid; - thread->priv->tid = pbuf[pi].tid; + aix_thread_info *priv = new aix_thread_info; + priv->pdtid = pbuf[pi].pdtid; + priv->tid = pbuf[pi].tid; + + thread = add_thread_with_info (ptid_t (infpid, 0, pbuf[pi].pthid), priv); + pi++; } else @@ -776,8 +787,10 @@ sync_threadlists (void) if (cmp_result == 0) { - gbuf[gi]->priv->pdtid = pdtid; - gbuf[gi]->priv->tid = tid; + aix_thread_info *priv = get_aix_thread_info (gbuf[gi]); + + priv->pdtid = pdtid; + priv->tid = tid; pi++; gi++; } @@ -789,9 +802,11 @@ sync_threadlists (void) else { thread = add_thread (pptid); - thread->priv = XNEW (struct private_thread_info); - thread->priv->pdtid = pdtid; - thread->priv->tid = tid; + + aix_thread_info *priv = new aix_thread_info; + thread->priv.reset (priv); + priv->pdtid = pdtid; + priv->tid = tid; pi++; } } @@ -808,8 +823,9 @@ static int iter_tid (struct thread_info *thread, void *tidp) { const pthdb_tid_t tid = *(pthdb_tid_t *)tidp; + aix_thread_info *priv = get_aix_thread_info (thread); - return (thread->priv->tid == tid); + return priv->tid == tid; } /* Synchronize libpthdebug's state with the inferior and with GDB, @@ -998,7 +1014,9 @@ aix_thread_resume (struct target_ops *ops, error (_("aix-thread resume: unknown pthread %ld"), ptid_get_lwp (ptid)); - tid[0] = thread->priv->tid; + aix_thread_info *priv = get_aix_thread_info (thread); + + tid[0] = priv->tid; if (tid[0] == PTHDB_INVALID_TID) error (_("aix-thread resume: no tid for pthread %ld"), ptid_get_lwp (ptid)); @@ -1314,10 +1332,11 @@ aix_thread_fetch_registers (struct target_ops *ops, else { thread = find_thread_ptid (regcache_get_ptid (regcache)); - tid = thread->priv->tid; + aix_thread_info *priv = get_aix_thread_info (thread); + tid = priv->tid; if (tid == PTHDB_INVALID_TID) - fetch_regs_user_thread (regcache, thread->priv->pdtid); + fetch_regs_user_thread (regcache, priv->pdtid); else fetch_regs_kernel_thread (regcache, regno, tid); } @@ -1668,10 +1687,11 @@ aix_thread_store_registers (struct target_ops *ops, else { thread = find_thread_ptid (regcache_get_ptid (regcache)); - tid = thread->priv->tid; + aix_thread_info *priv = get_aix_thread_info (thread); + tid = priv->tid; if (tid == PTHDB_INVALID_TID) - store_regs_user_thread (regcache, thread->priv->pdtid); + store_regs_user_thread (regcache, priv->pdtid); else store_regs_kernel_thread (regcache, regno, tid); } @@ -1759,9 +1779,10 @@ aix_thread_extra_thread_info (struct target_ops *self, return NULL; string_file buf; + aix_thread_info *priv = get_aix_thread_info (thread); - pdtid = thread->priv->pdtid; - tid = thread->priv->tid; + pdtid = priv->pdtid; + tid = priv->tid; if (tid != PTHDB_INVALID_TID) /* i18n: Like "thread-identifier %d, [state] running, suspended" */ -- cgit v1.1