From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [FYI/pushed v4 15/25] Implement GDB_THREAD_OPTION_EXIT support for Linux GDBserver
Date: Mon, 13 Nov 2023 15:04:17 +0000 [thread overview]
Message-ID: <20231113150427.477431-16-pedro@palves.net> (raw)
In-Reply-To: <20231113150427.477431-1-pedro@palves.net>
This implements support for the new GDB_THREAD_OPTION_EXIT thread
option for Linux GDBserver.
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Change-Id: I96b719fdf7fee94709e98bb3a90751d8134f3a38
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338
---
gdbserver/linux-low.cc | 38 +++++++++++++++++++++++++-------------
gdbserver/linux-low.h | 9 +++++----
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index ca2b7aa1e1b..b4a1191b5b4 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -144,6 +144,18 @@ is_leader (thread_info *thread)
return ptid.pid () == ptid.lwp ();
}
+/* Return true if we should report thread exit events to GDB, for
+ THR. */
+
+static bool
+report_exit_events_for (thread_info *thr)
+{
+ client_state &cs = get_client_state ();
+
+ return (cs.report_thread_events
+ || (thr->thread_options & GDB_THREAD_OPTION_EXIT) != 0);
+}
+
/* LWP accessors. */
/* See nat/linux-nat.h. */
@@ -2233,7 +2245,6 @@ linux_low_ptrace_options (int attached)
void
linux_process_target::filter_event (int lwpid, int wstat)
{
- client_state &cs = get_client_state ();
struct lwp_info *child;
struct thread_info *thread;
int have_stop_pc = 0;
@@ -2320,7 +2331,7 @@ linux_process_target::filter_event (int lwpid, int wstat)
/* If this is not the leader LWP, then the exit signal was not
the end of the debugged application and should be ignored,
unless GDB wants to hear about thread exits. */
- if (cs.report_thread_events || is_leader (thread))
+ if (report_exit_events_for (thread) || is_leader (thread))
{
/* Since events are serialized to GDB core, and we can't
report this one right now. Leave the status pending for
@@ -2888,13 +2899,20 @@ ptid_t
linux_process_target::filter_exit_event (lwp_info *event_child,
target_waitstatus *ourstatus)
{
- client_state &cs = get_client_state ();
struct thread_info *thread = get_lwp_thread (event_child);
ptid_t ptid = ptid_of (thread);
+ /* Note we must filter TARGET_WAITKIND_SIGNALLED as well, otherwise
+ if a non-leader thread exits with a signal, we'd report it to the
+ core which would interpret it as the whole-process exiting.
+ There is no TARGET_WAITKIND_THREAD_SIGNALLED event kind. */
+ if (ourstatus->kind () != TARGET_WAITKIND_EXITED
+ && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED)
+ return ptid;
+
if (!is_leader (thread))
{
- if (cs.report_thread_events)
+ if (report_exit_events_for (thread))
ourstatus->set_thread_exited (0);
else
ourstatus->set_ignore ();
@@ -3037,10 +3055,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
WTERMSIG (w));
}
- if (ourstatus->kind () == TARGET_WAITKIND_EXITED)
- return filter_exit_event (event_child, ourstatus);
-
- return ptid_of (current_thread);
+ return filter_exit_event (event_child, ourstatus);
}
/* If step-over executes a breakpoint instruction, in the case of a
@@ -3607,10 +3622,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
target_pid_to_str (ptid_of (current_thread)).c_str (),
ourstatus->to_string ().c_str ());
- if (ourstatus->kind () == TARGET_WAITKIND_EXITED)
- return filter_exit_event (event_child, ourstatus);
-
- return ptid_of (current_thread);
+ return filter_exit_event (event_child, ourstatus);
}
/* Get rid of any pending event in the pipe. */
@@ -5920,7 +5932,7 @@ linux_process_target::supports_vfork_events ()
gdb_thread_options
linux_process_target::supported_thread_options ()
{
- return GDB_THREAD_OPTION_CLONE;
+ return GDB_THREAD_OPTION_CLONE | GDB_THREAD_OPTION_EXIT;
}
/* Check if exec events are supported. */
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index b5ff9391198..3597e33289c 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -575,10 +575,11 @@ class linux_process_target : public process_stratum_target
exited. */
void check_zombie_leaders ();
- /* Convenience function that is called when the kernel reports an exit
- event. This decides whether to report the event to GDB as a
- process exit event, a thread exit event, or to suppress the
- event. */
+ /* Convenience function that is called when we're about to return an
+ event to the core. If the event is an exit or signalled event,
+ then this decides whether to report it as process-wide event, as
+ a thread exit event, or to suppress it. All other event kinds
+ are passed through unmodified. */
ptid_t filter_exit_event (lwp_info *event_child,
target_waitstatus *ourstatus);
--
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 ` [FYI/pushed v4 09/25] gdbserver: Hide and don't detach pending clone children Pedro Alves
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 ` Pedro Alves [this message]
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-16-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).