From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Yfm+BGNn/2AuaQAAWB0awg (envelope-from ) for ; Mon, 26 Jul 2021 21:54:43 -0400 Received: by simark.ca (Postfix, from userid 112) id 039081EDFB; Mon, 26 Jul 2021 21:54:43 -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.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED 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 2D15F1E4A3 for ; Mon, 26 Jul 2021 21:54:42 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55BA2393F835 for ; Tue, 27 Jul 2021 01:54:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55BA2393F835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627350881; bh=ooV7khXBObQHSdAAgmwRmuHNqU+G5yNLWqypEm61r5c=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=KQYyc+7gOsxSXizfkczRjw1VKteJjUaIWJKWtHgEYwpgeLmSr5sykrrQgFNDfNQ0o lwoQxd30UGhI7WHvwo1n9ka+zcIhbQ7UHTT7BcpK+6W31ywiiVMdQKhoIQqGzOYRJ6 ux48YMWe3eHelkega4j4fCZ9vopcwFuYlVUEMjYU= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id BFE11389683C for ; Tue, 27 Jul 2021 01:54:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BFE11389683C Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 16R1sCHk002341 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Jul 2021 21:54:17 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 16R1sCHk002341 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8E0391E4A3; Mon, 26 Jul 2021 21:54:12 -0400 (EDT) Subject: Re: [PATCH 3/3] obsd-nat: Various fixes to obsd_nat_target::wait. To: John Baldwin , gdb-patches@sourceware.org References: <20210727002421.18947-1-jhb@FreeBSD.org> <20210727002421.18947-4-jhb@FreeBSD.org> Message-ID: <268f5540-4418-103b-1cb2-84026af99606@polymtl.ca> Date: Mon, 26 Jul 2021 21:54:12 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210727002421.18947-4-jhb@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 27 Jul 2021 01:54:12 +0000 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-07-26 8:24 p.m., John Baldwin wrote: > - 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); I don't really have comments on this, since I am not familiar with the OpenBSD specifics. But I don't understand this code above. fpid refers to the fork child pid? And pe.pe_other_pid as well? So it's as if we return that the child has forked? What am I getting wrong? Simon