From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +H5pAYBS/2AcZwAAWB0awg (envelope-from ) for ; Mon, 26 Jul 2021 20:25:36 -0400 Received: by simark.ca (Postfix, from userid 112) id 0322A1EDFB; Mon, 26 Jul 2021 20:25:35 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4D3E91E813 for ; Mon, 26 Jul 2021 20:25:34 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E95263950CBD for ; Tue, 27 Jul 2021 00:25:33 +0000 (GMT) Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 665463898032 for ; Tue, 27 Jul 2021 00:24:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 665463898032 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from gimli.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id DC1731A84C6B for ; Mon, 26 Jul 2021 20:24:27 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 3/3] obsd-nat: Various fixes to obsd_nat_target::wait. Date: Mon, 26 Jul 2021 17:24:21 -0700 Message-Id: <20210727002421.18947-4-jhb@FreeBSD.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210727002421.18947-1-jhb@FreeBSD.org> References: <20210727002421.18947-1-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Mon, 26 Jul 2021 20:24:28 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" - Call inf_ptrace_target::wait instead of duplicating the code. Replace a check for WIFSTOPPED on the returned status from waitpid by checking for TARGET_WAITKIND_STOPPED in the parsed status as is done in fbsd_nat_target::wait. - Don't use inferior_ptid when deciding if a new process is a child vs parent of the fork. Instead, use find_inferior_pid and assume that if an inferior already exists, the pid in question is the parent; otherwise, the pid is the child. - Don't use inferior_ptid when deciding if the ptid of the process needs to be updated with an LWP ID, or if this is a new thread. Instead, use the approach from fbsd-nat which is to check if a ptid without an LWP exists and if so update the ptid of that thread instead of adding a new thread. --- gdb/obsd-nat.c | 61 +++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/gdb/obsd-nat.c b/gdb/obsd-nat.c index 46fdc0676e..a6612a982b 100644 --- a/gdb/obsd-nat.c +++ b/gdb/obsd-nat.c @@ -26,7 +26,7 @@ #include #include "gdbsupport/gdb_wait.h" -#include "inf-child.h" +#include "inf-ptrace.h" #include "obsd-nat.h" /* OpenBSD 5.2 and later include rthreads which uses a thread model @@ -76,47 +76,14 @@ ptid_t obsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, target_wait_flags options) { - pid_t pid; - int status, save_errno; - - do - { - set_sigint_trap (); - - do - { - pid = waitpid (ptid.pid (), &status, 0); - save_errno = errno; - } - while (pid == -1 && errno == EINTR); - - clear_sigint_trap (); - - if (pid == -1) - { - fprintf_unfiltered (gdb_stderr, - _("Child process unexpectedly missing: %s.\n"), - safe_strerror (save_errno)); - - /* Claim it exited with unknown signal. */ - ourstatus->kind = TARGET_WAITKIND_SIGNALLED; - ourstatus->value.sig = GDB_SIGNAL_UNKNOWN; - return inferior_ptid; - } - - /* Ignore terminated detached child processes. */ - if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ()) - pid = -1; - } - while (pid == -1); - - ptid = ptid_t (pid); - - if (WIFSTOPPED (status)) + ptid_t wptid = inf_ptrace_target::wait (ptid, ourstatus, options); + if (ourstatus->kind == TARGET_WAITKIND_STOPPED) { ptrace_state_t pe; - pid_t fpid; + pid_t fpid, pid; + int status; + pid = wptid.pid (); if (ptrace (PT_GET_PROCESS_STATE, pid, (caddr_t)&pe, sizeof pe) == -1) perror_with_name (("ptrace")); @@ -137,7 +104,7 @@ obsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, gdb_assert (pe.pe_report_event == PTRACE_FORK); gdb_assert (pe.pe_other_pid == pid); - if (fpid == inferior_ptid.pid ()) + if (find_inferior_pid (this, pid) != nullptr) { ourstatus->value.related_pid = ptid_t (pe.pe_other_pid); return ptid_t (fpid); @@ -146,18 +113,16 @@ obsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, return ptid_t (pid); } - ptid = ptid_t (pid, pe.pe_tid, 0); - if (!in_thread_list (this, ptid)) + wptid = ptid_t (pid, pe.pe_tid, 0); + if (!in_thread_list (this, wptid)) { - if (inferior_ptid.lwp () == 0) - thread_change_ptid (this, inferior_ptid, ptid); + if (in_thread_list (this, ptid_t (pid))) + thread_change_ptid (this, ptid_t (pid), wptid); else - add_thread (this, ptid); + add_thread (this, wptid); } } - - store_waitstatus (ourstatus, status); - return ptid; + return wptid; } #endif /* PT_GET_THREAD_FIRST */ -- 2.31.1