From patchwork Mon Mar 4 20:25:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31716 Received: (qmail 89946 invoked by alias); 4 Mar 2019 20:25:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 89807 invoked by uid 89); 4 Mar 2019 20:25:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=nb, flushed, STATE, forever X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Mar 2019 20:25:20 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 3911856126; Mon, 4 Mar 2019 15:25:19 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id mlQqj+1moRVb; Mon, 4 Mar 2019 15:25:19 -0500 (EST) Received: from murgatroyd.Home (75-166-85-218.hlrn.qwest.net [75.166.85.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id C1FEB560BB; Mon, 4 Mar 2019 15:25:18 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] Change iterate_over_lwps to take a gdb::function_view Date: Mon, 4 Mar 2019 13:25:15 -0700 Message-Id: <20190304202516.19100-2-tromey@adacore.com> In-Reply-To: <20190304202516.19100-1-tromey@adacore.com> References: <20190304202516.19100-1-tromey@adacore.com> MIME-Version: 1.0 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-04 Tom Tromey * 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 user-data 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-04 Tom Tromey * linux-low.c (iterate_over_lwps): Update. --- gdb/ChangeLog | 34 ++++++++ gdb/arm-linux-nat.c | 26 +++--- gdb/gdbserver/ChangeLog | 4 + gdb/gdbserver/linux-low.c | 5 +- gdb/linux-nat.c | 138 +++++++++++++++++-------------- gdb/nat/aarch64-linux-hw-point.c | 27 ++---- gdb/nat/linux-nat.h | 9 +- gdb/nat/x86-linux-dregs.c | 6 +- gdb/s390-linux-nat.c | 4 +- 9 files changed, 144 insertions(+), 109 deletions(-) diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c index e4622b04076..8c98a7189fe 100644 --- a/gdb/arm-linux-nat.c +++ b/gdb/arm-linux-nat.c @@ -952,26 +952,18 @@ arm_linux_hw_breakpoint_equal (const struct arm_linux_hw_breakpoint *p1, /* Callback to mark a watch-/breakpoint to be updated in all threads of the current process. */ -struct update_registers_data -{ - int watch; - int index; -}; - static int -update_registers_callback (struct lwp_info *lwp, void *arg) +update_registers_callback (struct lwp_info *lwp, int watch, int index) { - struct update_registers_data *data = (struct update_registers_data *) arg; - if (lwp->arch_private == NULL) lwp->arch_private = XCNEW (struct arch_lwp_info); /* The actual update is done later just before resuming the lwp, we just mark that the registers need updating. */ - if (data->watch) - lwp->arch_private->wpts_changed[data->index] = 1; + if (watch) + lwp->arch_private->wpts_changed[index] = 1; else - lwp->arch_private->bpts_changed[data->index] = 1; + lwp->arch_private->bpts_changed[index] = 1; /* If the lwp isn't stopped, force it to momentarily pause, so we can update its breakpoint registers. */ @@ -991,7 +983,6 @@ arm_linux_insert_hw_breakpoint1 (const struct arm_linux_hw_breakpoint* bpt, ptid_t pid_ptid; gdb_byte count, i; struct arm_linux_hw_breakpoint* bpts; - struct update_registers_data data; pid = inferior_ptid.pid (); pid_ptid = ptid_t (pid); @@ -1010,10 +1001,13 @@ arm_linux_insert_hw_breakpoint1 (const struct arm_linux_hw_breakpoint* bpt, for (i = 0; i < count; ++i) if (!arm_hwbp_control_is_enabled (bpts[i].control)) { - data.watch = watchpoint; - data.index = i; bpts[i] = *bpt; - iterate_over_lwps (pid_ptid, update_registers_callback, &data); + iterate_over_lwps (pid_ptid, + [=] (struct lwp_info *info) + { + return update_registers_callback (info, watch, + index); + }); break; } diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 8c5a51f23c6..b1a9d128990 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -1843,14 +1843,13 @@ num_lwps (int pid) struct lwp_info * iterate_over_lwps (ptid_t filter, - iterate_over_lwps_ftype callback, - void *data) + gdb::function_view callback) { thread_info *thread = find_thread (filter, [&] (thread_info *thr_arg) { lwp_info *lwp = get_thread_lwp (thr_arg); - return callback (lwp, data); + return callback (lwp); }); if (thread == NULL) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 063afe26666..ad5ec3d0b57 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 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 diff --git a/gdb/nat/aarch64-linux-hw-point.c b/gdb/nat/aarch64-linux-hw-point.c index eed060610ec..1efec9a268c 100644 --- a/gdb/nat/aarch64-linux-hw-point.c +++ b/gdb/nat/aarch64-linux-hw-point.c @@ -278,27 +278,17 @@ aarch64_align_watchpoint (CORE_ADDR addr, int len, CORE_ADDR *aligned_addr_p, *next_addr_orig_p = align_down (*next_addr_orig_p + alignment, alignment); } -struct aarch64_dr_update_callback_param -{ - int is_watchpoint; - unsigned int idx; -}; - -/* Callback for iterate_over_lwps. Records the +/* Helper for aarch64_notify_debug_reg_change. Records the information about the change of one hardware breakpoint/watchpoint setting for the thread LWP. - The information is passed in via PTR. N.B. The actual updating of hardware debug registers is not carried out until the moment the thread is resumed. */ static int -debug_reg_change_callback (struct lwp_info *lwp, void *ptr) +debug_reg_change_callback (struct lwp_info *lwp, int is_watchpoint, + unsigned int idx) { - struct aarch64_dr_update_callback_param *param_p - = (struct aarch64_dr_update_callback_param *) ptr; int tid = ptid_of_lwp (lwp).lwp (); - int idx = param_p->idx; - int is_watchpoint = param_p->is_watchpoint; struct arch_lwp_info *info = lwp_arch_private_info (lwp); dr_changed_t *dr_changed_ptr; dr_changed_t dr_changed; @@ -356,13 +346,14 @@ static void aarch64_notify_debug_reg_change (const struct aarch64_debug_reg_state *state, int is_watchpoint, unsigned int idx) { - struct aarch64_dr_update_callback_param param; ptid_t pid_ptid = ptid_t (current_lwp_ptid ().pid ()); - param.is_watchpoint = is_watchpoint; - param.idx = idx; - - iterate_over_lwps (pid_ptid, debug_reg_change_callback, (void *) ¶m); + iterate_over_lwps (pid_ptid, [=] (struct lwp_info *info) + { + return debug_reg_change_callback (info, + is_watchpoint, + idx); + }); } /* Reconfigure STATE to be compatible with Linux kernels with the PR diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h index 1e32dd9eb6b..29f43d8dfa5 100644 --- a/gdb/nat/linux-nat.h +++ b/gdb/nat/linux-nat.h @@ -20,6 +20,7 @@ #ifndef NAT_LINUX_NAT_H #define NAT_LINUX_NAT_H +#include "common/function-view.h" #include "target/waitstatus.h" struct lwp_info; @@ -43,7 +44,7 @@ struct arch_lwp_info; extern ptid_t current_lwp_ptid (void); /* Function type for the CALLBACK argument of iterate_over_lwps. */ -typedef int (iterate_over_lwps_ftype) (struct lwp_info *lwp, void *arg); +typedef int (iterate_over_lwps_ftype) (struct lwp_info *lwp); /* Iterate over all LWPs. Calls CALLBACK with its second argument set to DATA for every LWP in the list. If CALLBACK returns nonzero for @@ -51,9 +52,9 @@ typedef int (iterate_over_lwps_ftype) (struct lwp_info *lwp, void *arg); LWP immediately. Otherwise return NULL. This function must be provided by the client. */ -extern struct lwp_info *iterate_over_lwps (ptid_t filter, - iterate_over_lwps_ftype callback, - void *data); +extern struct lwp_info *iterate_over_lwps + (ptid_t filter, + gdb::function_view callback); /* Return the ptid of LWP. */ diff --git a/gdb/nat/x86-linux-dregs.c b/gdb/nat/x86-linux-dregs.c index 33bbfa2d823..29b4ee16b60 100644 --- a/gdb/nat/x86-linux-dregs.c +++ b/gdb/nat/x86-linux-dregs.c @@ -76,7 +76,7 @@ x86_linux_dr_set (ptid_t ptid, int regnum, unsigned long value) the actual debug registers immediately prior to LWP resuming. */ static int -update_debug_registers_callback (struct lwp_info *lwp, void *arg) +update_debug_registers_callback (struct lwp_info *lwp) { lwp_set_debug_registers_changed (lwp, 1); @@ -106,7 +106,7 @@ x86_linux_dr_set_addr (int regnum, CORE_ADDR addr) gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR); - iterate_over_lwps (pid_ptid, update_debug_registers_callback, NULL); + iterate_over_lwps (pid_ptid, update_debug_registers_callback); } /* See nat/x86-linux-dregs.h. */ @@ -124,7 +124,7 @@ x86_linux_dr_set_control (unsigned long control) { ptid_t pid_ptid = ptid_t (current_lwp_ptid ().pid ()); - iterate_over_lwps (pid_ptid, update_debug_registers_callback, NULL); + iterate_over_lwps (pid_ptid, update_debug_registers_callback); } /* See nat/x86-linux-dregs.h. */ diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c index 69a3df0b0da..5f6c5be8e02 100644 --- a/gdb/s390-linux-nat.c +++ b/gdb/s390-linux-nat.c @@ -833,7 +833,7 @@ s390_linux_nat_target::low_delete_thread (struct arch_lwp_info *arch_lwp) /* Iterator callback for s390_refresh_per_info. */ static int -s390_refresh_per_info_cb (struct lwp_info *lp, void *arg) +s390_refresh_per_info_cb (struct lwp_info *lp) { s390_mark_per_info_changed (lp); @@ -849,7 +849,7 @@ s390_refresh_per_info (void) { ptid_t pid_ptid = ptid_t (current_lwp_ptid ().pid ()); - iterate_over_lwps (pid_ptid, s390_refresh_per_info_cb, NULL); + iterate_over_lwps (pid_ptid, s390_refresh_per_info_cb); return 0; }