aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-03-04 12:05:03 -0700
committerTom Tromey <tromey@adacore.com>2019-03-12 10:45:35 -0600
commitd3a70e03cf51c8fb6bc183eaff7559edffec2045 (patch)
treea482ecb424eec253f95a9a065f48d8ebeb1acd70 /gdb/linux-nat.c
parent7a6e0d89bb018cef0d8d13c497d8f340aa2a0fc8 (diff)
downloadgdb-d3a70e03cf51c8fb6bc183eaff7559edffec2045.zip
gdb-d3a70e03cf51c8fb6bc183eaff7559edffec2045.tar.gz
gdb-d3a70e03cf51c8fb6bc183eaff7559edffec2045.tar.bz2
Change iterate_over_lwps to take a gdb::function_view
This changes iterate_over_lwps to use a gdb::function_view. This was needed in order to make null_ptid and minus_one_ptid 'const'. gdb/ChangeLog 2019-03-12 Tom Tromey <tromey@adacore.com> * linux-nat.c (iterate_over_lwps): Update. (stop_callback): Remove parameter. (stop_wait_callback, detach_callback, resume_set_callback) (select_singlestep_lwp_callback, set_ignore_sigint) (status_callback, resumed_callback, resume_clear_callback) (kill_callback, kill_wait_callback, linux_nat_stop_lwp): Remove data parameter. (linux_nat_target::detach, linux_nat_target::resume) (linux_stop_and_wait_all_lwps, select_event_lwp) (linux_nat_filter_event, linux_nat_wait_1) (linux_nat_target::kill, linux_nat_target::stop) (linux_nat_target::stop): Update. (linux_nat_resume_callback): Change type. (resume_stopped_resumed_lwps, count_events_callback) (select_event_lwp_callback): Likewise. (linux_stop_lwp, linux_nat_stop_lwp): Update. * arm-linux-nat.c (struct update_registers_data): Remove. (update_registers_callback): Change type. (arm_linux_insert_hw_breakpoint1): Update. * nat/x86-linux-dregs.c (update_debug_registers_callback): Remove parameter. (x86_linux_dr_set_addr): Update. (x86_linux_dr_set_control): Update. * nat/linux-nat.h (iterate_over_lwps_ftype): Remove parameter. (iterate_over_lwps): Use gdb::function_view. * nat/aarch64-linux-hw-point.c (struct aarch64_dr_update_callback_param): Remove. (debug_reg_change_callback): Change type. (aarch64_notify_debug_reg_change): Update. * s390-linux-nat.c (s390_refresh_per_info): Update. gdb/gdbserver/ChangeLog 2019-03-12 Tom Tromey <tromey@adacore.com> * linux-low.c (iterate_over_lwps): Update.
Diffstat (limited to 'gdb/linux-nat.c')
-rw-r--r--gdb/linux-nat.c138
1 files changed, 75 insertions, 63 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 063afe2..ad5ec3d 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -262,8 +262,7 @@ async_file_mark (void)
static int kill_lwp (int lwpid, int signo);
-static int stop_callback (struct lwp_info *lp, void *data);
-static int resume_stopped_resumed_lwps (struct lwp_info *lp, void *data);
+static int stop_callback (struct lwp_info *lp);
static void block_child_signals (sigset_t *prev_mask);
static void restore_child_signals_mask (sigset_t *prev_mask);
@@ -807,8 +806,8 @@ linux_nat_target::pass_signals
/* Prototypes for local functions. */
-static int stop_wait_callback (struct lwp_info *lp, void *data);
-static int resume_stopped_resumed_lwps (struct lwp_info *lp, void *data);
+static int stop_wait_callback (struct lwp_info *lp);
+static int resume_stopped_resumed_lwps (struct lwp_info *lp, const ptid_t wait_ptid);
static int check_ptrace_stopped_lwp_gone (struct lwp_info *lp);
@@ -960,8 +959,7 @@ find_lwp_pid (ptid_t ptid)
struct lwp_info *
iterate_over_lwps (ptid_t filter,
- iterate_over_lwps_ftype callback,
- void *data)
+ gdb::function_view<iterate_over_lwps_ftype> callback)
{
struct lwp_info *lp, *lpnext;
@@ -971,7 +969,7 @@ iterate_over_lwps (ptid_t filter,
if (lp->ptid.matches (filter))
{
- if ((*callback) (lp, data) != 0)
+ if (callback (lp) != 0)
return lp;
}
}
@@ -1456,7 +1454,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p)
}
static int
-detach_callback (struct lwp_info *lp, void *data)
+detach_callback (struct lwp_info *lp)
{
/* We don't actually detach from the thread group leader just yet.
If the thread group exits, we must reap the zombie clone lwps
@@ -1477,12 +1475,12 @@ linux_nat_target::detach (inferior *inf, int from_tty)
/* Stop all threads before detaching. ptrace requires that the
thread is stopped to sucessfully detach. */
- iterate_over_lwps (ptid_t (pid), stop_callback, NULL);
+ iterate_over_lwps (ptid_t (pid), stop_callback);
/* ... and wait until all of them have reported back that
they're no longer running. */
- iterate_over_lwps (ptid_t (pid), stop_wait_callback, NULL);
+ iterate_over_lwps (ptid_t (pid), stop_wait_callback);
- iterate_over_lwps (ptid_t (pid), detach_callback, NULL);
+ iterate_over_lwps (ptid_t (pid), detach_callback);
/* Only the initial process should be left right now. */
gdb_assert (num_lwps (pid) == 1);
@@ -1646,7 +1644,7 @@ resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
Resume LWP with the last stop signal, if it is in pass state. */
static int
-linux_nat_resume_callback (struct lwp_info *lp, void *except)
+linux_nat_resume_callback (struct lwp_info *lp, struct lwp_info *except)
{
enum gdb_signal signo = GDB_SIGNAL_0;
@@ -1670,7 +1668,7 @@ linux_nat_resume_callback (struct lwp_info *lp, void *except)
}
static int
-resume_clear_callback (struct lwp_info *lp, void *data)
+resume_clear_callback (struct lwp_info *lp)
{
lp->resumed = 0;
lp->last_resume_kind = resume_stop;
@@ -1678,7 +1676,7 @@ resume_clear_callback (struct lwp_info *lp, void *data)
}
static int
-resume_set_callback (struct lwp_info *lp, void *data)
+resume_set_callback (struct lwp_info *lp)
{
lp->resumed = 1;
lp->last_resume_kind = resume_continue;
@@ -1705,7 +1703,7 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
|| ptid.is_pid ());
/* Mark the lwps we're resuming as resumed. */
- iterate_over_lwps (ptid, resume_set_callback, NULL);
+ iterate_over_lwps (ptid, resume_set_callback);
/* See if it's the current inferior that should be handled
specially. */
@@ -1766,7 +1764,10 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo)
}
if (resume_many)
- iterate_over_lwps (ptid, linux_nat_resume_callback, lp);
+ iterate_over_lwps (ptid, [=] (struct lwp_info *info)
+ {
+ return linux_nat_resume_callback (info, lp);
+ });
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
@@ -2305,7 +2306,7 @@ wait_lwp (struct lwp_info *lp)
/* Send a SIGSTOP to LP. */
static int
-stop_callback (struct lwp_info *lp, void *data)
+stop_callback (struct lwp_info *lp)
{
if (!lp->stopped && !lp->signalled)
{
@@ -2339,7 +2340,7 @@ stop_callback (struct lwp_info *lp, void *data)
void
linux_stop_lwp (struct lwp_info *lwp)
{
- stop_callback (lwp, NULL);
+ stop_callback (lwp);
}
/* See linux-nat.h */
@@ -2348,11 +2349,11 @@ void
linux_stop_and_wait_all_lwps (void)
{
/* Stop all LWP's ... */
- iterate_over_lwps (minus_one_ptid, stop_callback, NULL);
+ iterate_over_lwps (minus_one_ptid, stop_callback);
/* ... and wait until all of them have reported back that
they're no longer running. */
- iterate_over_lwps (minus_one_ptid, stop_wait_callback, NULL);
+ iterate_over_lwps (minus_one_ptid, stop_wait_callback);
}
/* See linux-nat.h */
@@ -2361,7 +2362,10 @@ void
linux_unstop_all_lwps (void)
{
iterate_over_lwps (minus_one_ptid,
- resume_stopped_resumed_lwps, &minus_one_ptid);
+ [] (struct lwp_info *info)
+ {
+ return resume_stopped_resumed_lwps (info, minus_one_ptid);
+ });
}
/* Return non-zero if LWP PID has a pending SIGINT. */
@@ -2383,7 +2387,7 @@ linux_nat_has_pending_sigint (int pid)
/* Set a flag in LP indicating that we should ignore its next SIGINT. */
static int
-set_ignore_sigint (struct lwp_info *lp, void *data)
+set_ignore_sigint (struct lwp_info *lp)
{
/* If a thread has a pending SIGINT, consume it; otherwise, set a
flag to consume the next one. */
@@ -2484,7 +2488,7 @@ linux_nat_target::low_status_is_event (int status)
/* Wait until LP is stopped. */
static int
-stop_wait_callback (struct lwp_info *lp, void *data)
+stop_wait_callback (struct lwp_info *lp)
{
struct inferior *inf = find_inferior_ptid (lp->ptid);
@@ -2516,7 +2520,7 @@ stop_wait_callback (struct lwp_info *lp, void *data)
target_pid_to_str (lp->ptid),
errno ? safe_strerror (errno) : "OK");
- return stop_wait_callback (lp, NULL);
+ return stop_wait_callback (lp);
}
maybe_clear_ignore_sigint (lp);
@@ -2566,7 +2570,7 @@ stop_wait_callback (struct lwp_info *lp, void *data)
caused the stop became uninteresting. */
static int
-status_callback (struct lwp_info *lp, void *data)
+status_callback (struct lwp_info *lp)
{
/* Only report a pending wait status if we pretend that this has
indeed been resumed. */
@@ -2628,10 +2632,8 @@ status_callback (struct lwp_info *lp, void *data)
/* Count the LWP's that have had events. */
static int
-count_events_callback (struct lwp_info *lp, void *data)
+count_events_callback (struct lwp_info *lp, int *count)
{
- int *count = (int *) data;
-
gdb_assert (count != NULL);
/* Select only resumed LWPs that have an event pending. */
@@ -2644,7 +2646,7 @@ count_events_callback (struct lwp_info *lp, void *data)
/* Select the LWP (if any) that is currently being single-stepped. */
static int
-select_singlestep_lwp_callback (struct lwp_info *lp, void *data)
+select_singlestep_lwp_callback (struct lwp_info *lp)
{
if (lp->last_resume_kind == resume_step
&& lp->status != 0)
@@ -2667,10 +2669,8 @@ lwp_status_pending_p (struct lwp_info *lp)
/* Select the Nth LWP that has had an event. */
static int
-select_event_lwp_callback (struct lwp_info *lp, void *data)
+select_event_lwp_callback (struct lwp_info *lp, int *selector)
{
- int *selector = (int *) data;
-
gdb_assert (selector != NULL);
/* Select only resumed LWPs that have an event pending. */
@@ -2869,8 +2869,7 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
signal. */
if (!target_is_non_stop_p ())
{
- event_lp = iterate_over_lwps (filter,
- select_singlestep_lwp_callback, NULL);
+ event_lp = iterate_over_lwps (filter, select_singlestep_lwp_callback);
if (event_lp != NULL)
{
if (debug_linux_nat)
@@ -2885,7 +2884,11 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
/* Pick one at random, out of those which have had events. */
/* First see how many events we have. */
- iterate_over_lwps (filter, count_events_callback, &num_events);
+ iterate_over_lwps (filter,
+ [&] (struct lwp_info *info)
+ {
+ return count_events_callback (info, &num_events);
+ });
gdb_assert (num_events > 0);
/* Now randomly pick a LWP out of those that have had
@@ -2898,9 +2901,14 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
"SEL: Found %d events, selecting #%d\n",
num_events, random_selector);
- event_lp = iterate_over_lwps (filter,
- select_event_lwp_callback,
- &random_selector);
+ event_lp
+ = (iterate_over_lwps
+ (filter,
+ [&] (struct lwp_info *info)
+ {
+ return select_event_lwp_callback (info,
+ &random_selector);
+ }));
}
if (event_lp != NULL)
@@ -2917,7 +2925,7 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
/* Return non-zero if LP has been resumed. */
static int
-resumed_callback (struct lwp_info *lp, void *data)
+resumed_callback (struct lwp_info *lp)
{
return lp->resumed;
}
@@ -3136,8 +3144,7 @@ linux_nat_filter_event (int lwpid, int status)
will receive it - unless they're using CLONE_THREAD to
share signals. Since we only want to report it once, we
mark it as ignored for all LWPs except this one. */
- iterate_over_lwps (ptid_t (lp->ptid.pid ()),
- set_ignore_sigint, NULL);
+ iterate_over_lwps (ptid_t (lp->ptid.pid ()), set_ignore_sigint);
lp->ignore_sigint = 0;
}
else
@@ -3279,7 +3286,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
block_child_signals (&prev_mask);
/* First check if there is a LWP with a wait status pending. */
- lp = iterate_over_lwps (ptid, status_callback, NULL);
+ lp = iterate_over_lwps (ptid, status_callback);
if (lp != NULL)
{
if (debug_linux_nat)
@@ -3336,11 +3343,14 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
/* Now that we've pulled all events out of the kernel, resume
LWPs that don't have an interesting event to report. */
iterate_over_lwps (minus_one_ptid,
- resume_stopped_resumed_lwps, &minus_one_ptid);
+ [] (struct lwp_info *info)
+ {
+ return resume_stopped_resumed_lwps (info, minus_one_ptid);
+ });
/* ... and find an LWP with a status to report to the core, if
any. */
- lp = iterate_over_lwps (ptid, status_callback, NULL);
+ lp = iterate_over_lwps (ptid, status_callback);
if (lp != NULL)
break;
@@ -3350,7 +3360,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
/* If there are no resumed children left, bail. We'd be stuck
forever in the sigsuspend call below otherwise. */
- if (iterate_over_lwps (ptid, resumed_callback, NULL) == NULL)
+ if (iterate_over_lwps (ptid, resumed_callback) == NULL)
{
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog, "LLW: exit (no resumed LWP)\n");
@@ -3388,11 +3398,11 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
if (!target_is_non_stop_p ())
{
/* Now stop all other LWP's ... */
- iterate_over_lwps (minus_one_ptid, stop_callback, NULL);
+ iterate_over_lwps (minus_one_ptid, stop_callback);
/* ... and wait until all of them have reported back that
they're no longer running. */
- iterate_over_lwps (minus_one_ptid, stop_wait_callback, NULL);
+ iterate_over_lwps (minus_one_ptid, stop_wait_callback);
}
/* If we're not waiting for a specific LWP, choose an event LWP from
@@ -3431,11 +3441,11 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
{
/* In all-stop, from the core's perspective, all LWPs are now
stopped until a new resume action is sent over. */
- iterate_over_lwps (minus_one_ptid, resume_clear_callback, NULL);
+ iterate_over_lwps (minus_one_ptid, resume_clear_callback);
}
else
{
- resume_clear_callback (lp, NULL);
+ resume_clear_callback (lp);
}
if (linux_target->low_status_is_event (status))
@@ -3485,10 +3495,8 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus,
to report, but are resumed from the core's perspective. */
static int
-resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
+resume_stopped_resumed_lwps (struct lwp_info *lp, const ptid_t wait_ptid)
{
- ptid_t *wait_ptid_p = (ptid_t *) data;
-
if (!lp->stopped)
{
if (debug_linux_nat)
@@ -3522,7 +3530,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
/* Don't bother if there's a breakpoint at PC that we'd hit
immediately, and we're not waiting for this LWP. */
- if (!lp->ptid.matches (*wait_ptid_p))
+ if (!lp->ptid.matches (wait_ptid))
{
if (breakpoint_inserted_here_p (regcache->aspace (), pc))
leave_stopped = 1;
@@ -3579,7 +3587,11 @@ linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
meanwhile the event became uninteresting. Don't bother resuming
LWPs we're not going to wait for if they'd stop immediately. */
if (target_is_non_stop_p ())
- iterate_over_lwps (minus_one_ptid, resume_stopped_resumed_lwps, &ptid);
+ iterate_over_lwps (minus_one_ptid,
+ [=] (struct lwp_info *info)
+ {
+ return resume_stopped_resumed_lwps (info, ptid);
+ });
event_ptid = linux_nat_wait_1 (ptid, ourstatus, target_options);
@@ -3662,7 +3674,7 @@ kill_wait_one_lwp (pid_t pid)
/* Callback for iterate_over_lwps. */
static int
-kill_callback (struct lwp_info *lp, void *data)
+kill_callback (struct lwp_info *lp)
{
kill_one_lwp (lp->ptid.lwp ());
return 0;
@@ -3671,7 +3683,7 @@ kill_callback (struct lwp_info *lp, void *data)
/* Callback for iterate_over_lwps. */
static int
-kill_wait_callback (struct lwp_info *lp, void *data)
+kill_wait_callback (struct lwp_info *lp)
{
kill_wait_one_lwp (lp->ptid.lwp ());
return 0;
@@ -3720,16 +3732,16 @@ linux_nat_target::kill ()
/* Stop all threads before killing them, since ptrace requires
that the thread is stopped to sucessfully PTRACE_KILL. */
- iterate_over_lwps (ptid, stop_callback, NULL);
+ iterate_over_lwps (ptid, stop_callback);
/* ... and wait until all of them have reported back that
they're no longer running. */
- iterate_over_lwps (ptid, stop_wait_callback, NULL);
+ iterate_over_lwps (ptid, stop_wait_callback);
/* Kill all LWP's ... */
- iterate_over_lwps (ptid, kill_callback, NULL);
+ iterate_over_lwps (ptid, kill_callback);
/* ... and wait until we've flushed all events. */
- iterate_over_lwps (ptid, kill_wait_callback, NULL);
+ iterate_over_lwps (ptid, kill_wait_callback);
}
target_mourn_inferior (inferior_ptid);
@@ -4415,7 +4427,7 @@ linux_nat_target::async (int enable)
event came out. */
static int
-linux_nat_stop_lwp (struct lwp_info *lwp, void *data)
+linux_nat_stop_lwp (struct lwp_info *lwp)
{
if (!lwp->stopped)
{
@@ -4435,7 +4447,7 @@ linux_nat_stop_lwp (struct lwp_info *lwp, void *data)
return 0;
}
- stop_callback (lwp, NULL);
+ stop_callback (lwp);
lwp->last_resume_kind = resume_stop;
}
else
@@ -4461,7 +4473,7 @@ linux_nat_stop_lwp (struct lwp_info *lwp, void *data)
void
linux_nat_target::stop (ptid_t ptid)
{
- iterate_over_lwps (ptid, linux_nat_stop_lwp, NULL);
+ iterate_over_lwps (ptid, linux_nat_stop_lwp);
}
void