mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-22 19:09:31 +08:00
Remove find_inferior usage for thread_search
Replace it with for_each_thread. While at it, we can inline the callback code. One little change is that I am using the prev_general_thread variable instead of current_gen_ptid, since they should have the same value. gdb/gdbserver/ChangeLog: * target.c (struct thread_search): Remove. (thread_search_callback): Remove. (prepare_to_access_memory): Use for_each_thread instead of find_inferior. Inline code from thread_search_callback.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
|
||||||
|
|
||||||
|
* target.c (struct thread_search): Remove.
|
||||||
|
(thread_search_callback): Remove.
|
||||||
|
(prepare_to_access_memory): Use for_each_thread instead of
|
||||||
|
find_inferior. Inline code from thread_search_callback.
|
||||||
|
|
||||||
2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
|
2017-10-27 Simon Marchi <simon.marchi@ericsson.com>
|
||||||
|
|
||||||
* server.c (struct visit_actioned_threads_data): Remove.
|
* server.c (struct visit_actioned_threads_data): Remove.
|
||||||
|
@ -32,51 +32,6 @@ set_desired_thread ()
|
|||||||
return (current_thread != NULL);
|
return (current_thread != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Structure used to look up a thread to use as current when accessing
|
|
||||||
memory. */
|
|
||||||
|
|
||||||
struct thread_search
|
|
||||||
{
|
|
||||||
/* The PTID of the current general thread. This is an input
|
|
||||||
parameter. */
|
|
||||||
ptid_t current_gen_ptid;
|
|
||||||
|
|
||||||
/* The first thread found. */
|
|
||||||
struct thread_info *first;
|
|
||||||
|
|
||||||
/* The first stopped thread found. */
|
|
||||||
struct thread_info *stopped;
|
|
||||||
|
|
||||||
/* The current general thread, if found. */
|
|
||||||
struct thread_info *current;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Callback for find_inferior. Search for a thread to use as current
|
|
||||||
when accessing memory. */
|
|
||||||
|
|
||||||
static int
|
|
||||||
thread_search_callback (thread_info *thread, void *args)
|
|
||||||
{
|
|
||||||
struct thread_search *s = (struct thread_search *) args;
|
|
||||||
|
|
||||||
if (thread->id.pid () == ptid_get_pid (s->current_gen_ptid)
|
|
||||||
&& mythread_alive (ptid_of (thread)))
|
|
||||||
{
|
|
||||||
if (s->stopped == NULL
|
|
||||||
&& the_target->thread_stopped != NULL
|
|
||||||
&& thread_stopped (thread))
|
|
||||||
s->stopped = thread;
|
|
||||||
|
|
||||||
if (s->first == NULL)
|
|
||||||
s->first = thread;
|
|
||||||
|
|
||||||
if (s->current == NULL && s->current_gen_ptid == thread->id)
|
|
||||||
s->current = thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The thread that was current before prepare_to_access_memory was
|
/* The thread that was current before prepare_to_access_memory was
|
||||||
called. done_accessing_memory uses this to restore the previous
|
called. done_accessing_memory uses this to restore the previous
|
||||||
selected thread. */
|
selected thread. */
|
||||||
@ -87,11 +42,15 @@ static ptid_t prev_general_thread;
|
|||||||
int
|
int
|
||||||
prepare_to_access_memory (void)
|
prepare_to_access_memory (void)
|
||||||
{
|
{
|
||||||
struct thread_search search;
|
/* The first thread found. */
|
||||||
struct thread_info *thread;
|
struct thread_info *first = NULL;
|
||||||
|
/* The first stopped thread found. */
|
||||||
|
struct thread_info *stopped = NULL;
|
||||||
|
/* The current general thread, if found. */
|
||||||
|
struct thread_info *current = NULL;
|
||||||
|
|
||||||
memset (&search, 0, sizeof (search));
|
/* Save the general thread value, since prepare_to_access_memory could change
|
||||||
search.current_gen_ptid = general_thread;
|
it. */
|
||||||
prev_general_thread = general_thread;
|
prev_general_thread = general_thread;
|
||||||
|
|
||||||
if (the_target->prepare_to_access_memory != NULL)
|
if (the_target->prepare_to_access_memory != NULL)
|
||||||
@ -103,18 +62,35 @@ prepare_to_access_memory (void)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
find_inferior (&all_threads, thread_search_callback, &search);
|
for_each_thread (prev_general_thread.pid (), [&] (thread_info *thread)
|
||||||
|
{
|
||||||
|
if (mythread_alive (thread->id))
|
||||||
|
{
|
||||||
|
if (stopped == NULL && the_target->thread_stopped != NULL
|
||||||
|
&& thread_stopped (thread))
|
||||||
|
stopped = thread;
|
||||||
|
|
||||||
|
if (first == NULL)
|
||||||
|
first = thread;
|
||||||
|
|
||||||
|
if (current == NULL && prev_general_thread == thread->id)
|
||||||
|
current = thread;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* The thread we end up choosing. */
|
||||||
|
struct thread_info *thread;
|
||||||
|
|
||||||
/* Prefer a stopped thread. If none is found, try the current
|
/* Prefer a stopped thread. If none is found, try the current
|
||||||
thread. Otherwise, take the first thread in the process. If
|
thread. Otherwise, take the first thread in the process. If
|
||||||
none is found, undo the effects of
|
none is found, undo the effects of
|
||||||
target->prepare_to_access_memory() and return error. */
|
target->prepare_to_access_memory() and return error. */
|
||||||
if (search.stopped != NULL)
|
if (stopped != NULL)
|
||||||
thread = search.stopped;
|
thread = stopped;
|
||||||
else if (search.current != NULL)
|
else if (current != NULL)
|
||||||
thread = search.current;
|
thread = current;
|
||||||
else if (search.first != NULL)
|
else if (first != NULL)
|
||||||
thread = search.first;
|
thread = first;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
done_accessing_memory ();
|
done_accessing_memory ();
|
||||||
|
Reference in New Issue
Block a user