From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xXZWJH++PmrghRkAWB0awg (envelope-from ) for ; Fri, 26 Jun 2026 14:01:35 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=tX4bl8Fj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7D0571E024; Fri, 26 Jun 2026 14:01:35 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 87AE01E024 for ; Fri, 26 Jun 2026 14:01:34 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E5DC4BA2E3C for ; Fri, 26 Jun 2026 18:01:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E5DC4BA2E3C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=tX4bl8Fj Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 12F774BA2E16 for ; Fri, 26 Jun 2026 18:01:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12F774BA2E16 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12F774BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782496868; cv=none; b=SU4O307zAPlizrdUuU+UnZ4oe8NCQScZHJVVeOnl24fBGCqTIUSHYDYbVZOqQrkjJAojBQaT1pxOIIoq5WcENy78/q+pplHjiudsYlvsB3QnaKMKhn4Tt2ViPVgvGattdNkAVA4PehpaHNoAsaDJVOUbXEIpY/DYV8+UVOLoM6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782496868; c=relaxed/simple; bh=6RwufF0UN5keIfN22vTr4vP8mes/ES/Jdz3PnBtcA3o=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=S1Rn25+OaZ3U/w+R+Pf6MnXMdYr+nP5vi6zSCkmFc58HQPxktnPd2j0Iy3HwydtsgRAX58JQqhQoeoVI+S4IXLaNMTCcRvNseCirQgffrj8susMt0CPxhrJ7ovLRkosnDk1U8XiB8CniF2hDzifaVxnoXYuCSHRKc7iJL1X+f+o= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=tX4bl8Fj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12F774BA2E16 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 65QI10ru203514 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Jun 2026 14:01:05 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 65QI10ru203514 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1782496865; bh=M1BUJefptDh9gC2+BwfL9aU41uLH8+GPyMEQ6E3Mupk=; h=Date:Subject:To:From:In-Reply-To:From; b=tX4bl8Fj2CwcL2y2lGtil/cVpBYT65NJydS9OFGWN1DwiKN5zQUIRN1k/1IrCqsIQ bYjk7j6Z2ZjPMr5Ib275N3LZHD9rj3x12kgKVkijqjm/hFhLIhZTP7oT74sNzEUiDQ +hZGRYg/N3u5U1giKEF5Vs5OzZrO06le/uPm7MV5ZayQCg+SY53inoCjJ345KdtTWF jPxg05E+4Q4K7UCoBSOgKNZn+cU9kD1me9eILzDGSRQvsZKoYjFtgfWkeRqyH9tv9h pA5L48fVlrYs/uMuCdEjrhRkTcj4PrkHOh1DmXOwJTT0XSFKARhGDaX916JoXf3bII mEqs5Rv1ImfMg== Received: by simark.ca (Postfix) id 4848E1E024; Fri, 26 Jun 2026 14:01:00 -0400 (EDT) Message-ID: Date: Fri, 26 Jun 2026 14:00:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdbserver/linux-low: carry over stop_expected flag after exec (avoid spurious SIGSTOPs) To: Pedro Alves , gdb-patches@sourceware.org References: <20260626143242.4033142-1-simon.marchi@polymtl.ca> Content-Language: en-US From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 26 Jun 2026 18:01:00 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 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 On 2026-06-26 13:35, Pedro Alves wrote: > On 2026-06-26 15:32, simon.marchi@polymtl.ca wrote: > >> What about GDB >> ============== >> >> I tried to check if the same bug could happen with GDB's linux-nat >> target, and if the same fix was needed. linux-nat takes a different >> approach when handling PTRACE_EVENT_EXEC. It wipes all lwp_infos except >> the leader: >> >> for (lwp_info &other_lp : all_lwps_safe ()) >> if (&other_lp != lp && other_lp.ptid.pid () == lp->ptid.pid ()) >> exit_lwp (&other_lp); >> >> Here, LP is an lwp_info obtained using the event ptid of the >> PTRACE_EVENT_EXEC, therefore the leader's lwp_info (even if the exec was >> done by a non-leader). >> >> If the exec is done by the leader, as is the case with >> gdb.base/vfork-follow-parent.exp, we are ok. Because GDB doesn't delete >> and re-create the lwp_info, the equivalent of GDBserver's >> `lwp_info::stop_expected`, `lwp_info::signalled`, survives the exec. >> >> If the exec is done by a non-leader, then we could be in trouble. If >> the leader's signalled flag is not set, but the exec'ing non-leader's >> flag is set, then we'll lose it. I suppose we could fix GDB to use >> PTRACE_GETEVENTMSG to get the exec'ing thread former id, look up the >> lwp_info for that id, and preserve that lwp_info. > > Yeah, it'd be good to fix GDB too. This sort of bug is hard to track > down, and we already know we have it. I'll see what I can do. I'd like to have a test to expose this alleged bug, but it's not easy. >> + unsigned long execing_tid = event_ptid.lwp (); >> + if (ptrace (PTRACE_GETEVENTMSG, event_ptid.lwp (), (PTRACE_TYPE_ARG3) 0, >> + &execing_tid) != 0) >> + execing_tid = event_ptid.lwp (); > > This gave me pause -- this is setting execing_tid to the event lwp if ptrace fails. > But execing_tid is already initialized to the event lwp. I think it'd be clearer not > to initialize it, like: > > unsigned long execing_tid; > if (ptrace (PTRACE_GETEVENTMSG, event_ptid.lwp (), (PTRACE_TYPE_ARG3) 0, > &execing_tid) != 0) > execing_tid = event_ptid.lwp (); Well, the question then is: what if the ptrace call fails? It probably never fails, but we still have to think about it. execing_tid would be used uninitialized. I see three options: 1. Don't carry over any stop_expected, that would degrade to the behavior we have today. 2. Continue with the leader's id and lwp_info, falling back to carrying over the leader's stop_expected flag (which may or may not be right, we don't know which thread actually exec'd) 3. Give up and abandon everything. My code does #2, which I thought was a useful fallback (since it will be right most of the time, execs from a multi-threaded program are probably are, execs from a non-leader thread even more so). But there is the theoretical risk of carrying over a stop_expected flag that we shouldn't have, and the user really uses SIGSTOP, and we would erroneously swallow it. So it might be safer (and simpler) to do #1, the only risk I see is that the user might get a spurious SIGSTOP, which is surprising but doesn't break the debugging session. I would go for that. Let me know what you think and I'll send a v2. Simon