From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 10/11] Ensure EXIT is last event, gdbserver/linux
Date: Thu, 3 Mar 2022 14:40:19 +0000 [thread overview]
Message-ID: <20220303144020.3601082-11-pedro@palves.net> (raw)
In-Reply-To: <20220303144020.3601082-1-pedro@palves.net>
Same as the previous patch, but for GDBserver.
In a nutshell, don't report exit events for the leader thread until
all pending events for other threads are flushed.
Change-Id: I3f855f48bea15a527a87565f8b9f4000169cd6c0
---
gdbserver/linux-low.cc | 46 +++++++++++++++++++++++++++++++++---------
gdbserver/linux-low.h | 15 ++++++++++++--
2 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 5c037881670..15c2914e444 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -1655,16 +1655,10 @@ lwp_resumed (struct lwp_info *lwp)
}
bool
-linux_process_target::status_pending_p_callback (thread_info *thread,
- ptid_t ptid)
+linux_process_target::status_pending_p (thread_info *thread)
{
struct lwp_info *lp = get_thread_lwp (thread);
- /* Check if we're only interested in events from a specific process
- or a specific LWP. */
- if (!thread->id.matches (ptid))
- return 0;
-
if (!lwp_resumed (lp))
return 0;
@@ -1678,6 +1672,38 @@ linux_process_target::status_pending_p_callback (thread_info *thread,
return lp->status_pending_p;
}
+bool
+linux_process_target::non_leader_lwp_in_process_with_pending_event
+ (thread_info *thread)
+{
+ gdb_assert (is_leader (thread));
+
+ thread_info *found = find_thread (ptid_t (pid_of (thread)),
+ [&] (thread_info *other)
+ {
+ return !is_leader (other) && status_pending_p (other);
+ });
+
+ return found != nullptr;
+}
+
+bool
+linux_process_target::has_reportable_pending_event (thread_info *thread,
+ ptid_t filter_ptid)
+{
+ /* Check if we're only interested in events from a specific process
+ or a specific thread. */
+ if (!thread->id.matches (filter_ptid))
+ return false;
+
+ lwp_info *lp = get_thread_lwp (thread);
+
+ return (status_pending_p (thread)
+ && !(!WIFSTOPPED (lp->status_pending)
+ && is_leader (thread)
+ && non_leader_lwp_in_process_with_pending_event (thread)));
+}
+
struct lwp_info *
find_lwp_pid (ptid_t ptid)
{
@@ -2446,7 +2472,7 @@ linux_process_target::wait_for_event_filtered (ptid_t wait_ptid,
{
event_thread = find_thread_in_random ([&] (thread_info *thread)
{
- return status_pending_p_callback (thread, filter_ptid);
+ return has_reportable_pending_event (thread, filter_ptid);
});
if (event_thread != NULL)
@@ -2562,7 +2588,7 @@ linux_process_target::wait_for_event_filtered (ptid_t wait_ptid,
any. */
event_thread = find_thread_in_random ([&] (thread_info *thread)
{
- return status_pending_p_callback (thread, filter_ptid);
+ return has_reportable_pending_event (thread, filter_ptid);
});
if (event_thread != NULL)
@@ -2902,7 +2928,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
auto status_pending_p_any = [&] (thread_info *thread)
{
- return status_pending_p_callback (thread, minus_one_ptid);
+ return status_pending_p (thread);
};
auto not_stopped = [&] (thread_info *thread)
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 27cc9641f12..bd71e673871 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -483,8 +483,19 @@ class linux_process_target : public process_stratum_target
they should be re-issued if necessary. */
void resume_one_thread (thread_info *thread, bool leave_all_stopped);
- /* Return true if this lwp has an interesting status pending. */
- bool status_pending_p_callback (thread_info *thread, ptid_t ptid);
+ /* Return true if THREAD has an interesting status pending. */
+ bool status_pending_p (thread_info *thread);
+
+ /* Return true if another thread of the same process as THREAD has a
+ pending status ready to be processed. THREAD is assumed to be
+ the leader of its process. */
+ bool non_leader_lwp_in_process_with_pending_event (thread_info *thread);
+
+ /* Indicate if THREAD has a pending event which should be considered
+ for immediate processing. Only threads that match FILTER_PTID
+ are considered. Does not consider a leader thread's exit event
+ before the non-leader threads have reported their exits. */
+ bool has_reportable_pending_event (thread_info *thread, ptid_t filter_ptid);
/* Resume LWPs that are currently stopped without any pending status
to report, but are resumed from the core's perspective. */
--
2.26.2
next prev parent reply other threads:[~2022-03-03 14:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-03 14:40 [PATCH 00/11] Linux: Fix issues around thread group leader exits Pedro Alves
2022-03-03 14:40 ` [PATCH 01/11] Fix gdbserver/linux target_waitstatus logging assert Pedro Alves
2022-03-03 14:40 ` [PATCH 02/11] Fix gdb.threads/clone-new-thread-event.exp race Pedro Alves
2022-03-03 14:40 ` [PATCH 03/11] Fix gdb.threads/current-lwp-dead.exp race Pedro Alves
2022-03-03 14:40 ` [PATCH 04/11] gdb: Reorganize linux_nat_filter_event Pedro Alves
2022-03-03 14:40 ` [PATCH 05/11] gdbserver: Reorganize linux_process_target::filter_event Pedro Alves
2022-03-03 14:40 ` [PATCH 06/11] gdbserver: Reindent check_zombie_leaders Pedro Alves
2022-03-03 14:40 ` [PATCH 07/11] Re-add zombie leader on exit, gdb/linux Pedro Alves
2022-03-07 20:08 ` Simon Marchi
2022-03-07 20:27 ` Pedro Alves
2022-03-07 20:31 ` Simon Marchi
2022-03-09 14:37 ` Pedro Alves
2022-03-03 14:40 ` [PATCH 08/11] Re-add zombie leader on exit, gdbserver/linux Pedro Alves
2022-03-03 14:40 ` [PATCH 09/11] Ensure EXIT is last event, gdb/linux Pedro Alves
2022-03-07 20:24 ` Simon Marchi
2022-03-09 0:21 ` Lancelot SIX
2022-03-09 14:45 ` Pedro Alves
2022-03-09 22:29 ` Lancelot SIX
2022-03-10 11:46 ` Pedro Alves
2022-03-03 14:40 ` Pedro Alves [this message]
2022-03-03 14:40 ` [PATCH 11/11] Process exit status is leader exit status testcase Pedro Alves
2023-06-22 11:28 ` Ilya Leoshkevich
2023-06-22 13:07 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220303144020.3601082-11-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).