aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2022-02-22 11:22:14 -0800
committerJohn Baldwin <jhb@FreeBSD.org>2022-02-22 11:22:14 -0800
commitca81b5334e074e6c00137dba00154ef1b4489388 (patch)
treea50ca85ed9cd3aeaca6132b5fc4f934db9091bfc
parent85e8c48c73a5c39a6980f9b2bd16ec96062fc4c3 (diff)
downloadgdb-ca81b5334e074e6c00137dba00154ef1b4489388.zip
gdb-ca81b5334e074e6c00137dba00154ef1b4489388.tar.gz
gdb-ca81b5334e074e6c00137dba00154ef1b4489388.tar.bz2
inf-ptrace: Support async targets in inf_ptrace_target::wait.
- Handle TARGET_WNOHANG by passing WNOHANG to waitpid and returning TARGET_WAITKIND_IGNORE if there are no events to report. - Handle a race in async mode where SIGCHLD might signal the event pipe for an event that has already been reported. If the event was the exit of the last child process, waitpid() will fail with ECHILD rather than returning a pid of 0. For this case, return TARGET_WAITKIND_NO_RESUMED.
-rw-r--r--gdb/inf-ptrace.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c
index 0b94aad..ebcc409 100644
--- a/gdb/inf-ptrace.c
+++ b/gdb/inf-ptrace.c
@@ -289,10 +289,14 @@ inf_ptrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
ptid_t
inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
- target_wait_flags options)
+ target_wait_flags target_options)
{
pid_t pid;
- int status, save_errno;
+ int options, status, save_errno;
+
+ options = 0;
+ if (target_options & TARGET_WNOHANG)
+ options |= WNOHANG;
do
{
@@ -300,15 +304,32 @@ inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
do
{
- pid = waitpid (ptid.pid (), &status, 0);
+ pid = waitpid (ptid.pid (), &status, options);
save_errno = errno;
}
while (pid == -1 && errno == EINTR);
clear_sigint_trap ();
+ if (pid == 0)
+ {
+ gdb_assert (target_options & TARGET_WNOHANG);
+ ourstatus->set_ignore ();
+ return minus_one_ptid;
+ }
+
if (pid == -1)
{
+ /* In async mode the SIGCHLD might have raced and triggered
+ a check for an event that had already been reported. If
+ the event was the exit of the only remaining child,
+ waitpid() will fail with ECHILD. */
+ if (ptid == minus_one_ptid && save_errno == ECHILD)
+ {
+ ourstatus->set_no_resumed ();
+ return minus_one_ptid;
+ }
+
fprintf_unfiltered (gdb_stderr,
_("Child process unexpectedly missing: %s.\n"),
safe_strerror (save_errno));