From patchwork Fri Oct 3 13:54:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 3085 Received: (qmail 18272 invoked by alias); 3 Oct 2014 13:54:27 -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 18167 invoked by uid 89); 3 Oct 2014 13:54:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 03 Oct 2014 13:54:24 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s93DsNUh012694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 3 Oct 2014 09:54:23 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s93DsJ7b025501 for ; Fri, 3 Oct 2014 09:54:22 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 3/8] infrun.c: add for_each_just_stopped_thread Date: Fri, 3 Oct 2014 14:54:13 +0100 Message-Id: <1412344458-31774-4-git-send-email-palves@redhat.com> In-Reply-To: <1412344458-31774-1-git-send-email-palves@redhat.com> References: <1412344458-31774-1-git-send-email-palves@redhat.com> This is a preparatory/cleanup patch that does two things: - Renames 'delete_step_thread_step_resume_breakpoint'. The "step_resume" part is misnomer these days, as the function deletes other kinds of breakpoints, not just the step-resume breakpoint. A following patch will want to make it delete yet another kind of breakpoint, even. - Splits out the logic of which threads get those breakpoints deleted to a separate "for_each"-style function, so that the same following patch may use it with a different callback. Tested on x86_64 Fedora 20. gdb/ 2014-10-03 Pedro Alves * infrun.c (delete_step_resume_breakpoint_callback): Delete. (delete_thread_infrun_breakpoints): New function, with parts salvaged from delete_step_resume_breakpoint_callback. (delete_step_thread_step_resume_breakpoint): Delete. (for_each_just_stopped_thread_callback_func): New typedef. (for_each_just_stopped_thread): New function. (delete_just_stopped_threads_infrun_breakpoints): New function. (delete_step_thread_step_resume_breakpoint_cleanup): Rename to ... (delete_just_stopped_threads_infrun_breakpoints_cleanup): ... this. Adjust. (wait_for_inferior, fetch_inferior_event): Adjust to renames. --- gdb/infrun.c | 72 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 31a1d35..3f32d24 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -2847,54 +2847,61 @@ infrun_thread_thread_exit (struct thread_info *tp, int silent) nullify_last_target_wait_ptid (); } -/* Callback for iterate_over_threads. */ +/* Delete the step resume, single-step and longjmp/exception resume + breakpoints of TP. */ -static int -delete_step_resume_breakpoint_callback (struct thread_info *info, void *data) +static void +delete_thread_infrun_breakpoints (struct thread_info *tp) { - if (is_exited (info->ptid)) - return 0; - - delete_step_resume_breakpoint (info); - delete_exception_resume_breakpoint (info); - return 0; + delete_step_resume_breakpoint (tp); + delete_exception_resume_breakpoint (tp); } -/* In all-stop, delete the step resume breakpoint of any thread that - had one. In non-stop, delete the step resume breakpoint of the - thread that just stopped. */ +/* If the target still has execution, call FUNC for each thread that + just stopped. In all-stop, that's all the non-exited threads; in + non-stop, that's the current thread, only. */ + +typedef void (*for_each_just_stopped_thread_callback_func) + (struct thread_info *tp); static void -delete_step_thread_step_resume_breakpoint (void) +for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func) { - if (!target_has_execution - || ptid_equal (inferior_ptid, null_ptid)) - /* If the inferior has exited, we have already deleted the step - resume breakpoints out of GDB's lists. */ + if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid)) return; if (non_stop) { - /* If in non-stop mode, only delete the step-resume or - longjmp-resume breakpoint of the thread that just stopped - stepping. */ - struct thread_info *tp = inferior_thread (); - - delete_step_resume_breakpoint (tp); - delete_exception_resume_breakpoint (tp); + /* If in non-stop mode, only the current thread stopped. */ + func (inferior_thread ()); } else - /* In all-stop mode, delete all step-resume and longjmp-resume - breakpoints of any thread that had them. */ - iterate_over_threads (delete_step_resume_breakpoint_callback, NULL); + { + struct thread_info *tp; + + /* In all-stop mode, all threads have stopped. */ + ALL_NON_EXITED_THREADS (tp) + { + func (tp); + } + } +} + +/* Delete the step resume and longjmp/exception resume breakpoints of + the threads that just stopped. */ + +static void +delete_just_stopped_threads_infrun_breakpoints (void) +{ + for_each_just_stopped_thread (delete_thread_infrun_breakpoints); } /* A cleanup wrapper. */ static void -delete_step_thread_step_resume_breakpoint_cleanup (void *arg) +delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg) { - delete_step_thread_step_resume_breakpoint (); + delete_just_stopped_threads_infrun_breakpoints (); } /* Pretty print the results of target_wait, for debugging purposes. */ @@ -3029,8 +3036,9 @@ wait_for_inferior (void) fprintf_unfiltered (gdb_stdlog, "infrun: wait_for_inferior ()\n"); - old_cleanups = - make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL); + old_cleanups + = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup, + NULL); while (1) { @@ -3152,7 +3160,7 @@ fetch_inferior_event (void *client_data) { struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); - delete_step_thread_step_resume_breakpoint (); + delete_just_stopped_threads_infrun_breakpoints (); /* We may not find an inferior if this was a process exit. */ if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)