From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 217F33858427 for ; Thu, 29 Jul 2021 19:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 217F33858427 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 16TJEPvI012693 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 15:14:30 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 16TJEPvI012693 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 AEEF01E4A3; Thu, 29 Jul 2021 15:14:25 -0400 (EDT) Subject: Re: [PATCH v2 4/5] obsd-nat: Various fixes for fork following. To: John Baldwin , gdb-patches@sourceware.org References: <20210727174110.62480-1-jhb@FreeBSD.org> <20210727174110.62480-5-jhb@FreeBSD.org> From: Simon Marchi Message-ID: <2af9f23d-86e5-a84c-b579-a9dba5e9e9ff@polymtl.ca> Date: Thu, 29 Jul 2021 15:14:25 -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: <20210727174110.62480-5-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 Thu, 29 Jul 2021 19:14:25 +0000 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 29 Jul 2021 19:14:33 -0000 On 2021-07-27 1:41 p.m., John Baldwin wrote: > - Don't use #ifdef's on ptrace ops. obsd-nat.h didn't include > , so the virtual methods weren't always overridden > causing the fork following to not work. In addition, the thread and > fork code is intertwined in ::wait and and the lack of #ifdef's > there already assumed both were present. In any case, PT_GET_PROCESS_STATE was added here, 16 years ago: https://github.com/openbsd/src/commit/f38bed7f869bd3503530c554b4860228ea4e8641 So it's reasonable to assume it's there (especially for a port with no maintainer). > > - Move duplicated code to enable PTRACE_FORK event reporting to a > single function and invoke it on new child processes reported via > PTRACE_FORK. > > - Don't return early from PTRACE_FORK handling, but instead reset > wptid to the correct ptid if the child reports its event before the > parent. This allows the ptid fixup code to add thread IDs if the > first event for a process is a PTRACE_FORK event. This also > properly returns ptid's with thread IDs when reporting PTRACE_FORK > events. > > - Handle detach_fork by skipping the PT_DETACH. > --- > gdb/obsd-nat.c | 51 +++++++++++++++++++++++--------------------------- > gdb/obsd-nat.h | 2 -- > 2 files changed, 23 insertions(+), 30 deletions(-) > > diff --git a/gdb/obsd-nat.c b/gdb/obsd-nat.c > index 8549c6ea66b..0edaa66cf1b 100644 > --- a/gdb/obsd-nat.c > +++ b/gdb/obsd-nat.c > @@ -33,8 +33,6 @@ > that maps userland threads directly onto kernel threads in a 1:1 > fashion. */ > > -#ifdef PT_GET_THREAD_FIRST 10 years ago for this one. Still long enough, and removing it makes the code much simpler to understand. > - > std::string > obsd_nat_target::pid_to_str (ptid_t ptid) > { > @@ -72,6 +70,19 @@ obsd_nat_target::update_thread_list () > } > } > > +static void > +obsd_enable_proc_events (pid_t pid) Could you please write a small, oneliner comment for this one? Simon