mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-06 15:43:09 +00:00
Use gdb::function_view in iterate_over_threads
This C++-ifies iterate_over_threads, changing it to accept a gdb::function_view and to return bool. Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
@@ -867,16 +867,6 @@ sync_threadlists (pid_t pid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Iterate_over_threads() callback for locating a thread, using
|
|
||||||
the TID of its associated kernel thread. */
|
|
||||||
|
|
||||||
static int
|
|
||||||
iter_tid (struct thread_info *thread, void *tidp)
|
|
||||||
{
|
|
||||||
const pthdb_tid_t tid = *(pthdb_tid_t *)tidp;
|
|
||||||
return thread->ptid.lwp () == tid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Synchronize libpthdebug's state with the inferior and with GDB,
|
/* Synchronize libpthdebug's state with the inferior and with GDB,
|
||||||
generate a composite process/thread <pid> for the current thread,
|
generate a composite process/thread <pid> for the current thread,
|
||||||
Return the ptid of the event thread if one can be found, else
|
Return the ptid of the event thread if one can be found, else
|
||||||
@@ -906,7 +896,10 @@ pd_update (pid_t pid)
|
|||||||
|
|
||||||
tid = get_signaled_thread (pid);
|
tid = get_signaled_thread (pid);
|
||||||
if (tid != 0)
|
if (tid != 0)
|
||||||
thread = iterate_over_threads (iter_tid, &tid);
|
thread = iterate_over_threads ([&] (struct thread_info *thread)
|
||||||
|
{
|
||||||
|
return thread->ptid.lwp () == tid;
|
||||||
|
});
|
||||||
if (!thread)
|
if (!thread)
|
||||||
ptid = ptid_t (pid);
|
ptid = ptid_t (pid);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -11831,16 +11831,6 @@ bpstat_remove_bp_location (bpstat *bps, struct breakpoint *bpt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for iterate_over_threads. */
|
|
||||||
static int
|
|
||||||
bpstat_remove_breakpoint_callback (struct thread_info *th, void *data)
|
|
||||||
{
|
|
||||||
struct breakpoint *bpt = (struct breakpoint *) data;
|
|
||||||
|
|
||||||
bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See breakpoint.h. */
|
/* See breakpoint.h. */
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -12685,7 +12675,11 @@ delete_breakpoint (struct breakpoint *bpt)
|
|||||||
event-top.c won't do anything, and temporary breakpoints with
|
event-top.c won't do anything, and temporary breakpoints with
|
||||||
commands won't work. */
|
commands won't work. */
|
||||||
|
|
||||||
iterate_over_threads (bpstat_remove_breakpoint_callback, bpt);
|
iterate_over_threads ([&] (struct thread_info *th)
|
||||||
|
{
|
||||||
|
bpstat_remove_bp_location (th->control.stop_bpstat, bpt);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
/* Now that breakpoint is removed from breakpoint list, update the
|
/* Now that breakpoint is removed from breakpoint list, update the
|
||||||
global location list. This will remove locations that used to
|
global location list. This will remove locations that used to
|
||||||
|
|||||||
@@ -637,14 +637,11 @@ fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
find_signalled_thread (struct thread_info *info, void *data)
|
find_signalled_thread (struct thread_info *info)
|
||||||
{
|
{
|
||||||
if (info->stop_signal () != GDB_SIGNAL_0
|
return (info->stop_signal () != GDB_SIGNAL_0
|
||||||
&& info->ptid.pid () == inferior_ptid.pid ())
|
&& info->ptid.pid () == inferior_ptid.pid ());
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a byte_vector containing the contents of a core dump note
|
/* Return a byte_vector containing the contents of a core dump note
|
||||||
@@ -718,7 +715,7 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
|
|||||||
signalled_thr = curr_thr;
|
signalled_thr = curr_thr;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
signalled_thr = iterate_over_threads (find_signalled_thread, NULL);
|
signalled_thr = iterate_over_threads (find_signalled_thread);
|
||||||
if (signalled_thr == NULL)
|
if (signalled_thr == NULL)
|
||||||
signalled_thr = curr_thr;
|
signalled_thr = curr_thr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -734,8 +734,8 @@ void thread_change_ptid (process_stratum_target *targ,
|
|||||||
|
|
||||||
/* Iterator function to call a user-provided callback function
|
/* Iterator function to call a user-provided callback function
|
||||||
once for each known thread. */
|
once for each known thread. */
|
||||||
typedef int (*thread_callback_func) (struct thread_info *, void *);
|
typedef gdb::function_view<bool (struct thread_info *)> thread_callback_func;
|
||||||
extern struct thread_info *iterate_over_threads (thread_callback_func, void *);
|
extern struct thread_info *iterate_over_threads (thread_callback_func);
|
||||||
|
|
||||||
/* Pull in the internals of the inferiors/threads ranges and
|
/* Pull in the internals of the inferiors/threads ranges and
|
||||||
iterators. Must be done after struct thread_info is defined. */
|
iterators. Must be done after struct thread_info is defined. */
|
||||||
|
|||||||
12
gdb/infcmd.c
12
gdb/infcmd.c
@@ -530,8 +530,8 @@ starti_command (const char *args, int from_tty)
|
|||||||
run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
|
run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
proceed_thread_callback (struct thread_info *thread, void *arg)
|
proceed_thread_callback (struct thread_info *thread)
|
||||||
{
|
{
|
||||||
/* We go through all threads individually instead of compressing
|
/* We go through all threads individually instead of compressing
|
||||||
into a single target `resume_all' request, because some threads
|
into a single target `resume_all' request, because some threads
|
||||||
@@ -543,15 +543,15 @@ proceed_thread_callback (struct thread_info *thread, void *arg)
|
|||||||
thread stopped until I say otherwise', then we can optimize
|
thread stopped until I say otherwise', then we can optimize
|
||||||
this. */
|
this. */
|
||||||
if (thread->state != THREAD_STOPPED)
|
if (thread->state != THREAD_STOPPED)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
if (!thread->inf->has_execution ())
|
if (!thread->inf->has_execution ())
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
switch_to_thread (thread);
|
switch_to_thread (thread);
|
||||||
clear_proceed_status (0);
|
clear_proceed_status (0);
|
||||||
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
|
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -608,7 +608,7 @@ continue_1 (int all_threads)
|
|||||||
scoped_disable_commit_resumed disable_commit_resumed
|
scoped_disable_commit_resumed disable_commit_resumed
|
||||||
("continue all threads in non-stop");
|
("continue all threads in non-stop");
|
||||||
|
|
||||||
iterate_over_threads (proceed_thread_callback, nullptr);
|
iterate_over_threads (proceed_thread_callback);
|
||||||
|
|
||||||
if (current_ui->prompt_state == PROMPT_BLOCKED)
|
if (current_ui->prompt_state == PROMPT_BLOCKED)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6671,9 +6671,8 @@ restart_threads (struct thread_info *event_thread, inferior *inf)
|
|||||||
/* Callback for iterate_over_threads. Find a resumed thread that has
|
/* Callback for iterate_over_threads. Find a resumed thread that has
|
||||||
a pending waitstatus. */
|
a pending waitstatus. */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
resumed_thread_with_pending_status (struct thread_info *tp,
|
resumed_thread_with_pending_status (struct thread_info *tp)
|
||||||
void *arg)
|
|
||||||
{
|
{
|
||||||
return tp->resumed () && tp->has_pending_waitstatus ();
|
return tp->resumed () && tp->has_pending_waitstatus ();
|
||||||
}
|
}
|
||||||
@@ -6751,8 +6750,7 @@ finish_step_over (struct execution_control_state *ecs)
|
|||||||
if (ecs->ws.kind () == TARGET_WAITKIND_THREAD_EXITED)
|
if (ecs->ws.kind () == TARGET_WAITKIND_THREAD_EXITED)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pending = iterate_over_threads (resumed_thread_with_pending_status,
|
pending = iterate_over_threads (resumed_thread_with_pending_status);
|
||||||
nullptr);
|
|
||||||
if (pending != nullptr)
|
if (pending != nullptr)
|
||||||
{
|
{
|
||||||
struct thread_info *tp = ecs->event_thread;
|
struct thread_info *tp = ecs->event_thread;
|
||||||
|
|||||||
100
gdb/mi/mi-main.c
100
gdb/mi/mi-main.c
@@ -250,15 +250,6 @@ proceed_thread (struct thread_info *thread, int pid)
|
|||||||
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
|
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
proceed_thread_callback (struct thread_info *thread, void *arg)
|
|
||||||
{
|
|
||||||
int pid = *(int *)arg;
|
|
||||||
|
|
||||||
proceed_thread (thread, pid);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
exec_continue (const char *const *argv, int argc)
|
exec_continue (const char *const *argv, int argc)
|
||||||
{
|
{
|
||||||
@@ -288,7 +279,11 @@ exec_continue (const char *const *argv, int argc)
|
|||||||
pid = inf->pid;
|
pid = inf->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterate_over_threads (proceed_thread_callback, &pid);
|
iterate_over_threads ([&] (struct thread_info *thread)
|
||||||
|
{
|
||||||
|
proceed_thread (thread, pid);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
disable_commit_resumed.reset_and_commit ();
|
disable_commit_resumed.reset_and_commit ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -341,21 +336,6 @@ mi_cmd_exec_continue (const char *command, const char *const *argv, int argc)
|
|||||||
exec_continue (argv, argc);
|
exec_continue (argv, argc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
interrupt_thread_callback (struct thread_info *thread, void *arg)
|
|
||||||
{
|
|
||||||
int pid = *(int *)arg;
|
|
||||||
|
|
||||||
if (thread->state != THREAD_RUNNING)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (thread->ptid.pid () != pid)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
target_stop (thread->ptid);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Interrupt the execution of the target. Note how we must play
|
/* Interrupt the execution of the target. Note how we must play
|
||||||
around with the token variables, in order to display the current
|
around with the token variables, in order to display the current
|
||||||
token in the result of the interrupt command, and the previous
|
token in the result of the interrupt command, and the previous
|
||||||
@@ -385,7 +365,17 @@ mi_cmd_exec_interrupt (const char *command, const char *const *argv, int argc)
|
|||||||
scoped_disable_commit_resumed disable_commit_resumed
|
scoped_disable_commit_resumed disable_commit_resumed
|
||||||
("interrupting all threads of thread group");
|
("interrupting all threads of thread group");
|
||||||
|
|
||||||
iterate_over_threads (interrupt_thread_callback, &inf->pid);
|
iterate_over_threads ([&] (struct thread_info *thread)
|
||||||
|
{
|
||||||
|
if (thread->state != THREAD_RUNNING)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (thread->ptid.pid () != inf->pid)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
target_stop (thread->ptid);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -478,18 +468,6 @@ mi_cmd_exec_run (const char *command, const char *const *argv, int argc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
find_thread_of_process (struct thread_info *ti, void *p)
|
|
||||||
{
|
|
||||||
int pid = *(int *)p;
|
|
||||||
|
|
||||||
if (ti->ptid.pid () == pid && ti->state != THREAD_EXITED)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mi_cmd_target_detach (const char *command, const char *const *argv, int argc)
|
mi_cmd_target_detach (const char *command, const char *const *argv, int argc)
|
||||||
{
|
{
|
||||||
@@ -528,7 +506,10 @@ mi_cmd_target_detach (const char *command, const char *const *argv, int argc)
|
|||||||
|
|
||||||
/* Pick any thread in the desired process. Current
|
/* Pick any thread in the desired process. Current
|
||||||
target_detach detaches from the parent of inferior_ptid. */
|
target_detach detaches from the parent of inferior_ptid. */
|
||||||
tp = iterate_over_threads (find_thread_of_process, &pid);
|
tp = iterate_over_threads ([&] (struct thread_info *ti)
|
||||||
|
{
|
||||||
|
return ti->ptid.pid () == pid && ti->state != THREAD_EXITED;
|
||||||
|
});
|
||||||
if (!tp)
|
if (!tp)
|
||||||
error (_("Thread group is empty"));
|
error (_("Thread group is empty"));
|
||||||
|
|
||||||
@@ -600,28 +581,6 @@ mi_cmd_thread_info (const char *command, const char *const *argv, int argc)
|
|||||||
print_thread_info (current_uiout, argv[0], -1);
|
print_thread_info (current_uiout, argv[0], -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct collect_cores_data
|
|
||||||
{
|
|
||||||
int pid;
|
|
||||||
std::set<int> cores;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
|
||||||
collect_cores (struct thread_info *ti, void *xdata)
|
|
||||||
{
|
|
||||||
struct collect_cores_data *data = (struct collect_cores_data *) xdata;
|
|
||||||
|
|
||||||
if (ti->ptid.pid () == data->pid)
|
|
||||||
{
|
|
||||||
int core = target_core_of_thread (ti->ptid);
|
|
||||||
|
|
||||||
if (core != -1)
|
|
||||||
data->cores.insert (core);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_one_inferior (struct inferior *inferior, bool recurse,
|
print_one_inferior (struct inferior *inferior, bool recurse,
|
||||||
const std::set<int> &ids)
|
const std::set<int> &ids)
|
||||||
@@ -630,7 +589,7 @@ print_one_inferior (struct inferior *inferior, bool recurse,
|
|||||||
|
|
||||||
if (ids.empty () || (ids.find (inferior->pid) != ids.end ()))
|
if (ids.empty () || (ids.find (inferior->pid) != ids.end ()))
|
||||||
{
|
{
|
||||||
struct collect_cores_data data;
|
std::set<int> cores;
|
||||||
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
ui_out_emit_tuple tuple_emitter (uiout, NULL);
|
||||||
|
|
||||||
uiout->field_fmt ("id", "i%d", inferior->num);
|
uiout->field_fmt ("id", "i%d", inferior->num);
|
||||||
@@ -646,15 +605,24 @@ print_one_inferior (struct inferior *inferior, bool recurse,
|
|||||||
|
|
||||||
if (inferior->pid != 0)
|
if (inferior->pid != 0)
|
||||||
{
|
{
|
||||||
data.pid = inferior->pid;
|
iterate_over_threads ([&] (struct thread_info *ti)
|
||||||
iterate_over_threads (collect_cores, &data);
|
{
|
||||||
|
if (ti->ptid.pid () == inferior->pid)
|
||||||
|
{
|
||||||
|
int core = target_core_of_thread (ti->ptid);
|
||||||
|
|
||||||
|
if (core != -1)
|
||||||
|
cores.insert (core);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.cores.empty ())
|
if (!cores.empty ())
|
||||||
{
|
{
|
||||||
ui_out_emit_list list_emitter (uiout, "cores");
|
ui_out_emit_list list_emitter (uiout, "cores");
|
||||||
|
|
||||||
for (int b : data.cores)
|
for (int b : cores)
|
||||||
uiout->field_signed (NULL, b);
|
uiout->field_signed (NULL, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1108,25 +1108,14 @@ info_solthreads (const char *args, int from_tty)
|
|||||||
TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
|
TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback routine used to find a thread based on the TID part of
|
|
||||||
its PTID. */
|
|
||||||
|
|
||||||
static int
|
|
||||||
thread_db_find_thread_from_tid (struct thread_info *thread, void *data)
|
|
||||||
{
|
|
||||||
ULONGEST *tid = (ULONGEST *) data;
|
|
||||||
|
|
||||||
if (thread->ptid.tid () == *tid)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptid_t
|
ptid_t
|
||||||
sol_thread_target::get_ada_task_ptid (long lwp, ULONGEST thread)
|
sol_thread_target::get_ada_task_ptid (long lwp, ULONGEST thread)
|
||||||
{
|
{
|
||||||
struct thread_info *thread_info =
|
struct thread_info *thread_info
|
||||||
iterate_over_threads (thread_db_find_thread_from_tid, &thread);
|
= iterate_over_threads ([&] (struct thread_info *thread)
|
||||||
|
{
|
||||||
|
return thread->ptid.tid () == thread;
|
||||||
|
});
|
||||||
|
|
||||||
if (thread_info == NULL)
|
if (thread_info == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -602,11 +602,10 @@ find_thread_by_handle (gdb::array_view<const gdb_byte> handle,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct thread_info *
|
struct thread_info *
|
||||||
iterate_over_threads (int (*callback) (struct thread_info *, void *),
|
iterate_over_threads (gdb::function_view<bool (struct thread_info *)> callback)
|
||||||
void *data)
|
|
||||||
{
|
{
|
||||||
for (thread_info *tp : all_threads_safe ())
|
for (thread_info *tp : all_threads_safe ())
|
||||||
if ((*callback) (tp, data))
|
if (callback (tp))
|
||||||
return tp;
|
return tp;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user