[4/4] DEC threads: Simplify updating the thread list
Commit Message
Seems to me that we can simplify DEC thread's
target_update_thread_list implementation, avoiding the need to build
the array of GDB threads.
I have no way to test this.
gdb/
2014-10-02 Pedro Alves <palves@redhat.com>
* dec-thread.c (dec_thread_count_gdb_threads)
(dec_thread_add_gdb_thread): Delete.
(dec_thread_update_thread_list): Delete.
(dec_thread_find_new_threads): Rename to ...
(dec_thread_update_thread_list): ... this. Delete GDB-size
threads that are no longer found in dec_thread_list.
(resync_thread_list): Delete.
(dec_thread_wait): Call dec_thread_update_thread_list instead of
resync_thread_list.
---
gdb/dec-thread.c | 93 +++++++++++++-------------------------------------------
1 file changed, 21 insertions(+), 72 deletions(-)
Comments
> From: Pedro Alves <palves@redhat.com>
> Date: Thu, 2 Oct 2014 17:21:36 +0100
>
> Seems to me that we can simplify DEC thread's
> target_update_thread_list implementation, avoiding the need to build
> the array of GDB threads.
>
> I have no way to test this.
Given that Alpha True64 support is about to be removed, I don't think
anyone will care.
> gdb/
> 2014-10-02 Pedro Alves <palves@redhat.com>
>
> * dec-thread.c (dec_thread_count_gdb_threads)
> (dec_thread_add_gdb_thread): Delete.
> (dec_thread_update_thread_list): Delete.
> (dec_thread_find_new_threads): Rename to ...
> (dec_thread_update_thread_list): ... this. Delete GDB-size
> threads that are no longer found in dec_thread_list.
> (resync_thread_list): Delete.
> (dec_thread_wait): Call dec_thread_update_thread_list instead of
> resync_thread_list.
> ---
> gdb/dec-thread.c | 93 +++++++++++++-------------------------------------------
> 1 file changed, 21 insertions(+), 72 deletions(-)
>
> diff --git a/gdb/dec-thread.c b/gdb/dec-thread.c
> index fc43153..d5cfad2 100644
> --- a/gdb/dec-thread.c
> +++ b/gdb/dec-thread.c
> @@ -369,40 +369,33 @@ update_dec_thread_list (void)
> pthreadDebugThdSeqDestroy (debug_context);
> }
>
> -/* A callback to count the number of threads known to GDB. */
> -
> -static int
> -dec_thread_count_gdb_threads (struct thread_info *ignored, void *context)
> -{
> - int *count = (int *) context;
> -
> - *count = *count + 1;
> - return 0;
> -}
> -
> -/* A callback that saves the given thread INFO at the end of an
> - array. The end of the array is given in the CONTEXT and is
> - incremented once the info has been added. */
> -
> -static int
> -dec_thread_add_gdb_thread (struct thread_info *info, void *context)
> -{
> - struct thread_info ***listp = (struct thread_info ***) context;
> -
> - **listp = info;
> - *listp = *listp + 1;
> - return 0;
> -}
> -
> -/* Find new threads. */
> +/* Implement the update_thread_list target_ops method. */
>
> static void
> -dec_thread_find_new_threads (struct target_ops *ops)
> +dec_thread_update_thread_list (struct target_ops *ops)
> {
> int i;
> struct dec_thread_info *info;
> + struct thread_info *tp, *tmp;
>
> update_dec_thread_list ();
> +
> + /* Delete GDB-side threads no longer found in dec_thread_list. */
> + ALL_NON_EXITED_THREADS_SAFE (tp, tmp)
> + {
> + for (i = 0; VEC_iterate (dec_thread_info_s, dec_thread_list, i, info); i++)
> + {
> + if (ptid_equal (info->ptid, tp->ptid))
> + break;
> + }
> + if (i == VEC_length (dec_thread_info_s, dec_thread_list))
> + {
> + /* Not found. */
> + delete_thread (tp->ptid);
> + }
> + }
> +
> + /* And now add new threads. */
> for (i = 0; VEC_iterate (dec_thread_info_s, dec_thread_list, i, info); i++)
> {
> ptid_t ptid = ptid_build_from_info (*info);
> @@ -412,50 +405,6 @@ dec_thread_find_new_threads (struct target_ops *ops)
> }
> }
>
> -/* Implement the update_thread_list target_ops method. */
> -
> -static void
> -dec_thread_update_thread_list (struct target_ops *ops)
> -{
> - int i;
> - struct dec_thread_info *info;
> -
> - /* Delete dead threads. */
> - prune_threads ();
> -
> - /* Now find new threads. */
> - dec_thread_find_new_threads (ops);
> -}
> -
> -/* Resynchronize the list of threads known by GDB with the actual
> - list of threads reported by libpthread_debug. */
> -
> -static void
> -resync_thread_list (struct target_ops *ops)
> -{
> - int i;
> - int num_gdb_threads = 0;
> - struct thread_info **gdb_thread_list;
> - struct thread_info **next_thread_info;
> -
> - /* Add new threads. */
> - dec_thread_find_new_threads (ops);
> -
> - /* Remove threads that no longer exist. To help with the search,
> - we build an array of GDB threads, and then iterate over this
> - array. */
> -
> - iterate_over_threads (dec_thread_count_gdb_threads,
> - (void *) &num_gdb_threads);
> - gdb_thread_list = alloca (num_gdb_threads * sizeof (struct thread_info *));
> - next_thread_info = gdb_thread_list;
> - iterate_over_threads (dec_thread_add_gdb_thread, (void *) &next_thread_info);
> -
> - for (i = 0; i < num_gdb_threads; i++)
> - if (!dec_thread_ptid_is_alive (gdb_thread_list[i]->ptid))
> - delete_thread (gdb_thread_list[i]->ptid);
> -}
> -
> /* The "to_detach" method of the dec_thread_ops. */
>
> static void
> @@ -502,7 +451,7 @@ dec_thread_wait (struct target_ops *ops,
>
> /* The ptid returned by the target beneath us is the ptid of the process.
> We need to find which thread is currently active and return its ptid. */
> - resync_thread_list (ops);
> + dec_thread_update_thread_list (ops);
> active_ptid = get_active_ptid ();
> if (ptid_equal (active_ptid, null_ptid))
> return ptid;
> --
> 1.9.3
>
>
On 10/02/2014 07:46 PM, Mark Kettenis wrote:
>> From: Pedro Alves <palves@redhat.com>
>> Date: Thu, 2 Oct 2014 17:21:36 +0100
>>
>> Seems to me that we can simplify DEC thread's
>> target_update_thread_list implementation, avoiding the need to build
>> the array of GDB threads.
>>
>> I have no way to test this.
>
> Given that Alpha True64 support is about to be removed, I don't think
> anyone will care.
Eh, I saw that dec-thread.o was pulled in by config/alpha/alpha-osf3.mh,
and then that is used when configuring for "alpha-osf" host, but somehow
failed to make the OSF->True64 connection. :-P
Thanks,
Pedro Alves
@@ -369,40 +369,33 @@ update_dec_thread_list (void)
pthreadDebugThdSeqDestroy (debug_context);
}
-/* A callback to count the number of threads known to GDB. */
-
-static int
-dec_thread_count_gdb_threads (struct thread_info *ignored, void *context)
-{
- int *count = (int *) context;
-
- *count = *count + 1;
- return 0;
-}
-
-/* A callback that saves the given thread INFO at the end of an
- array. The end of the array is given in the CONTEXT and is
- incremented once the info has been added. */
-
-static int
-dec_thread_add_gdb_thread (struct thread_info *info, void *context)
-{
- struct thread_info ***listp = (struct thread_info ***) context;
-
- **listp = info;
- *listp = *listp + 1;
- return 0;
-}
-
-/* Find new threads. */
+/* Implement the update_thread_list target_ops method. */
static void
-dec_thread_find_new_threads (struct target_ops *ops)
+dec_thread_update_thread_list (struct target_ops *ops)
{
int i;
struct dec_thread_info *info;
+ struct thread_info *tp, *tmp;
update_dec_thread_list ();
+
+ /* Delete GDB-side threads no longer found in dec_thread_list. */
+ ALL_NON_EXITED_THREADS_SAFE (tp, tmp)
+ {
+ for (i = 0; VEC_iterate (dec_thread_info_s, dec_thread_list, i, info); i++)
+ {
+ if (ptid_equal (info->ptid, tp->ptid))
+ break;
+ }
+ if (i == VEC_length (dec_thread_info_s, dec_thread_list))
+ {
+ /* Not found. */
+ delete_thread (tp->ptid);
+ }
+ }
+
+ /* And now add new threads. */
for (i = 0; VEC_iterate (dec_thread_info_s, dec_thread_list, i, info); i++)
{
ptid_t ptid = ptid_build_from_info (*info);
@@ -412,50 +405,6 @@ dec_thread_find_new_threads (struct target_ops *ops)
}
}
-/* Implement the update_thread_list target_ops method. */
-
-static void
-dec_thread_update_thread_list (struct target_ops *ops)
-{
- int i;
- struct dec_thread_info *info;
-
- /* Delete dead threads. */
- prune_threads ();
-
- /* Now find new threads. */
- dec_thread_find_new_threads (ops);
-}
-
-/* Resynchronize the list of threads known by GDB with the actual
- list of threads reported by libpthread_debug. */
-
-static void
-resync_thread_list (struct target_ops *ops)
-{
- int i;
- int num_gdb_threads = 0;
- struct thread_info **gdb_thread_list;
- struct thread_info **next_thread_info;
-
- /* Add new threads. */
- dec_thread_find_new_threads (ops);
-
- /* Remove threads that no longer exist. To help with the search,
- we build an array of GDB threads, and then iterate over this
- array. */
-
- iterate_over_threads (dec_thread_count_gdb_threads,
- (void *) &num_gdb_threads);
- gdb_thread_list = alloca (num_gdb_threads * sizeof (struct thread_info *));
- next_thread_info = gdb_thread_list;
- iterate_over_threads (dec_thread_add_gdb_thread, (void *) &next_thread_info);
-
- for (i = 0; i < num_gdb_threads; i++)
- if (!dec_thread_ptid_is_alive (gdb_thread_list[i]->ptid))
- delete_thread (gdb_thread_list[i]->ptid);
-}
-
/* The "to_detach" method of the dec_thread_ops. */
static void
@@ -502,7 +451,7 @@ dec_thread_wait (struct target_ops *ops,
/* The ptid returned by the target beneath us is the ptid of the process.
We need to find which thread is currently active and return its ptid. */
- resync_thread_list (ops);
+ dec_thread_update_thread_list (ops);
active_ptid = get_active_ptid ();
if (ptid_equal (active_ptid, null_ptid))
return ptid;