From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [FYI/pushed v4 09/25] gdbserver: Hide and don't detach pending clone children
Date: Mon, 13 Nov 2023 15:04:11 +0000 [thread overview]
Message-ID: <20231113150427.477431-10-pedro@palves.net> (raw)
In-Reply-To: <20231113150427.477431-1-pedro@palves.net>
This commit extends the logic added by these two commits from a while
ago:
#1 7b961964f866 (gdbserver: hide fork child threads from GDB),
#2 df5ad102009c (gdb, gdbserver: detach fork child when detaching from fork parent)
... to handle thread clone events, which are very similar to (v)fork
events.
For #1, we want to hide clone children as well, so just update the
comments.
For #2, unlike (v)fork children, pending clone children aren't full
processes, they're just threads, so don't detach them in
handle_detach. linux-low.cc will take care of detaching them along
with all other threads of the process, there's nothing special that
needs to be done.
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Change-Id: I7f5901d07efda576a2522d03e183994e071b8ffc
---
gdbserver/linux-low.cc | 5 +++--
gdbserver/linux-low.h | 15 ++++++++++-----
gdbserver/server.cc | 12 +++++++-----
gdbserver/target.cc | 3 ++-
gdbserver/target.h | 16 +++++++++-------
5 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 136a8b6c9a1..7a4f8758ae9 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -6951,9 +6951,10 @@ linux_process_target::thread_pending_parent (thread_info *thread)
}
thread_info *
-linux_process_target::thread_pending_child (thread_info *thread)
+linux_process_target::thread_pending_child (thread_info *thread,
+ target_waitkind *kind)
{
- lwp_info *child = get_thread_lwp (thread)->pending_child ();
+ lwp_info *child = get_thread_lwp (thread)->pending_child (kind);
if (child == nullptr)
return nullptr;
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 94093dd4ed8..b5ff9391198 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -315,7 +315,8 @@ class linux_process_target : public process_stratum_target
#endif
thread_info *thread_pending_parent (thread_info *thread) override;
- thread_info *thread_pending_child (thread_info *thread) override;
+ thread_info *thread_pending_child (thread_info *thread,
+ target_waitkind *kind) override;
bool supports_catch_syscall () override;
@@ -756,13 +757,15 @@ struct lwp_info
const target_waitstatus &ws
= this->relative->waitstatus;
gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED
- || ws.kind () == TARGET_WAITKIND_VFORKED);
+ || ws.kind () == TARGET_WAITKIND_VFORKED
+ || ws.kind () == TARGET_WAITKIND_THREAD_CLONED);
return this->relative; }
/* If this LWP is the parent of a fork/vfork/clone child we haven't
- reported to GDB yet, return that child, else nullptr. */
- lwp_info *pending_child () const
+ reported to GDB yet, return that child and fill in KIND with the
+ matching waitkind, otherwise nullptr. */
+ lwp_info *pending_child (target_waitkind *kind) const
{
if (this->relative == nullptr)
return nullptr;
@@ -781,8 +784,10 @@ struct lwp_info
const target_waitstatus &ws = this->waitstatus;
gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED
- || ws.kind () == TARGET_WAITKIND_VFORKED);
+ || ws.kind () == TARGET_WAITKIND_VFORKED
+ || ws.kind () == TARGET_WAITKIND_THREAD_CLONED);
+ *kind = ws.kind ();
return this->relative;
}
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index c24a5c9fb96..2a70ca63cbd 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1349,8 +1349,9 @@ handle_detach (char *own_buf)
continue;
/* Only threads that have a pending fork event. */
- thread_info *child = target_thread_pending_child (thread);
- if (child == nullptr)
+ target_waitkind kind;
+ thread_info *child = target_thread_pending_child (thread, &kind);
+ if (child == nullptr || kind == TARGET_WAITKIND_THREAD_CLONED)
continue;
process_info *fork_child_process = get_thread_process (child);
@@ -1771,9 +1772,10 @@ handle_qxfer_threads_worker (thread_info *thread, std::string *buffer)
gdb_byte *handle;
bool handle_status = target_thread_handle (ptid, &handle, &handle_len);
- /* If this is a fork or vfork child (has a fork parent), GDB does not yet
- know about this process, and must not know about it until it gets the
- corresponding (v)fork event. Exclude this thread from the list. */
+ /* If this is a (v)fork/clone child (has a (v)fork/clone parent),
+ GDB does not yet know about this thread, and must not know about
+ it until it gets the corresponding (v)fork/clone event. Exclude
+ this thread from the list. */
if (target_thread_pending_parent (thread) != nullptr)
return;
diff --git a/gdbserver/target.cc b/gdbserver/target.cc
index 1c740bbf583..dbb4e2d9024 100644
--- a/gdbserver/target.cc
+++ b/gdbserver/target.cc
@@ -816,7 +816,8 @@ process_stratum_target::thread_pending_parent (thread_info *thread)
}
thread_info *
-process_stratum_target::thread_pending_child (thread_info *thread)
+process_stratum_target::thread_pending_child (thread_info *thread,
+ target_waitkind *kind)
{
return nullptr;
}
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 8893e0a6a8b..0f1fd5906fb 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -478,13 +478,15 @@ class process_stratum_target
virtual bool thread_handle (ptid_t ptid, gdb_byte **handle,
int *handle_len);
- /* If THREAD is a fork child that was not reported to GDB, return its parent
- else nullptr. */
+ /* If THREAD is a fork/vfork/clone child that was not reported to
+ GDB, return its parent else nullptr. */
virtual thread_info *thread_pending_parent (thread_info *thread);
- /* If THREAD is the parent of a fork child that was not reported to GDB,
- return this child, else nullptr. */
- virtual thread_info *thread_pending_child (thread_info *thread);
+ /* If THREAD is the parent of a fork/vfork/clone child that was not
+ reported to GDB, return this child and fill in KIND with the
+ matching waitkind, otherwise nullptr. */
+ virtual thread_info *thread_pending_child (thread_info *thread,
+ target_waitkind *kind);
/* Returns true if the target can software single step. */
virtual bool supports_software_single_step ();
@@ -700,9 +702,9 @@ target_thread_pending_parent (thread_info *thread)
}
static inline thread_info *
-target_thread_pending_child (thread_info *thread)
+target_thread_pending_child (thread_info *thread, target_waitkind *kind)
{
- return the_target->thread_pending_child (thread);
+ return the_target->thread_pending_child (thread, kind);
}
/* Read LEN bytes from MEMADDR in the buffer MYADDR. Return 0 if the read
--
2.34.1
next prev parent reply other threads:[~2023-11-13 15:05 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 15:04 [FYI/pushed v4 00/25] Step over thread clone and thread exit Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 01/25] Add "maint info linux-lwps" command Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 02/25] gdb/linux: Delete all other LWPs immediately on ptrace exec event Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 03/25] Step over clone syscall w/ breakpoint, TARGET_WAITKIND_THREAD_CLONED Pedro Alves
2023-11-14 12:55 ` Guinevere Larsen
2023-11-14 13:26 ` Pedro Alves
2023-11-14 16:29 ` Guinevere Larsen
2023-11-14 16:44 ` Luis Machado
2023-11-14 13:28 ` Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 04/25] Support clone events in the remote protocol Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 05/25] Avoid duplicate QThreadEvents packets Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 06/25] Thread options & clone events (core + remote) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 07/25] Thread options & clone events (native Linux) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 08/25] Thread options & clone events (Linux GDBserver) Pedro Alves
2024-02-06 11:04 ` Luis Machado
2024-02-06 14:57 ` Tom Tromey
2024-02-06 15:12 ` Luis Machado
2024-02-07 8:59 ` Luis Machado
2024-02-07 15:43 ` Tom Tromey
2024-02-07 17:10 ` Simon Marchi
2024-02-07 18:05 ` Luis Machado
2024-02-07 18:18 ` Tom Tromey
2024-02-07 18:56 ` Pedro Alves
2024-02-07 20:11 ` Pedro Alves
2024-02-08 8:57 ` Luis Machado
2024-02-08 10:53 ` Pedro Alves
2024-02-08 11:47 ` Luis Machado
2024-02-08 14:58 ` Tom Tromey
2024-02-07 18:06 ` Tom Tromey
2023-11-13 15:04 ` Pedro Alves [this message]
2023-11-13 15:04 ` [FYI/pushed v4 10/25] Remove gdb/19675 kfails (displaced stepping + clone) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 11/25] all-stop/synchronous RSP support thread-exit events Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 12/25] gdbserver/linux-low.cc: Ignore event_ptid if TARGET_WAITKIND_IGNORE Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 13/25] Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to core Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 14/25] Introduce GDB_THREAD_OPTION_EXIT thread option, fix step-over-thread-exit Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 15/25] Implement GDB_THREAD_OPTION_EXIT support for Linux GDBserver Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 16/25] Implement GDB_THREAD_OPTION_EXIT support for native Linux Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 17/25] gdb: clear step over information on thread exit (PR gdb/27338) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 18/25] stop_all_threads: (re-)enable async before waiting for stops Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 19/25] gdbserver: Queue no-resumed event after thread exit Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 20/25] Don't resume new threads if scheduler-locking is in effect Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 21/25] Report thread exit event for leader if reporting thread exit events Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 22/25] gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 23/25] Testcases for stepping over thread exit syscall (PR gdb/27338) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 24/25] Document remote clone events, and QThreadOptions packet Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 25/25] Cancel execution command on thread exit, when stepping, nexting, etc Pedro Alves
2023-11-13 19:28 ` [FYI/pushed v4 00/25] Step over thread clone and thread exit Tom de Vries
2023-11-14 10:51 ` Pedro Alves
2023-11-14 13:39 ` 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=20231113150427.477431-10-pedro@palves.net \
--to=pedro@palves.net \
--cc=aburgess@redhat.com \
--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).