From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FtPZGEvSAWZh0xUAWB0awg (envelope-from ) for ; Mon, 25 Mar 2024 15:36:43 -0400 Received: by simark.ca (Postfix, from userid 112) id 4F3781E0AC; Mon, 25 Mar 2024 15:36:43 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 2E9131E0AC for ; Mon, 25 Mar 2024 15:36:41 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C10573858404 for ; Mon, 25 Mar 2024 19:36:40 +0000 (GMT) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by sourceware.org (Postfix) with ESMTPS id 321553858D33 for ; Mon, 25 Mar 2024 19:36:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 321553858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 321553858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711395379; cv=none; b=JGuCy0/Ao3JKrArklodAb+MEEyrQlvLODA/9lk8M1TKnmzE/ku9VMHoQ73cJtOQt/J+lQD61Mq9ky26sxPWS320SQgoIb0KRCJBfJeQcUzj6ViGnl1ORVo8BDz+cN9KRjEzsvnTWrsRku3w+h/7X3arumjSUPhuJkM7+DSqF52A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711395379; c=relaxed/simple; bh=zGKwkeHFRnwUpanoEY34wlI/QATAb+DL4uKdcMSt3uE=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=ZCkHIv0DRdYIoVTPPwTuiaOx6qgSHXsfw6T39w9BePuEm9Pk6JhNM20XYONtP0cu2eev02a2NpKdJdq3gcnfvNRG49YuCeUhyTlvu+jrX+5T5GgTj2nhAySZYM3Pa85dLQj3zUmNvPm52dStYdeEBHr/K1dWf6LEHj42xZuLmxk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-41488d7d0f6so9087465e9.1 for ; Mon, 25 Mar 2024 12:36:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711395367; x=1712000167; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xdzvS1K6+YGWpAeNi+aibLWGoEMxNiGOLGl4B0VBn88=; b=KOqs5GADrU3DtSEauAewtlQ0o6P8Zfz8HbIpFvV2usHXjoXu+lwNmh45RH9tU9udfa k+NTw0vWGxqsInYzygnK/JfZrULBMH6nV25CnVt9j/3/j6TV5ZbgpKzVZDsNXiwtk5c7 g/glKiTATMZdKHroN8WmI5UAt8KZc46KS+OD6KV2VA2lqy3GyrBlUtVP+MHWx+EmH5VI Ucej4eJCfuc9Zxq+kdYFd+WpJrAvN2VXU0fu0QF2wMhpZrjxvurkrsNfTEKRpk/H4Tn/ c/avrDZx/IZ4wkt47Zy+wojozx4GoBFwlLnXJULPydjf/zkTTbtEMaW21HVeWdlMaD/J OxvQ== X-Gm-Message-State: AOJu0YwBOoiS2d+AJNtEs4hIKKvF6qxBW0c5+lucePOigKkQDrKDo1Kc +HSjwvaWhcDHdxY+ooODqn/Q5CwiKfanM1rCU6oYx4G/3axv0wwB X-Google-Smtp-Source: AGHT+IHtcIQEPKHorpUubRHoN3ZjdU3+nItWI7FMfbKrybUFQE5UqQ1qAINmI+tW10aFmJ0bx6dgfg== X-Received: by 2002:a5d:6a0a:0:b0:33e:b758:a039 with SMTP id m10-20020a5d6a0a000000b0033eb758a039mr5570674wru.28.1711395366659; Mon, 25 Mar 2024 12:36:06 -0700 (PDT) Received: from ?IPV6:2001:8a0:f918:ab00:614:7511:27a5:e9eb? ([2001:8a0:f918:ab00:614:7511:27a5:e9eb]) by smtp.gmail.com with ESMTPSA id co1-20020a0560000a0100b00341cb22a8d4sm4598167wrb.108.2024.03.25.12.36.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Mar 2024 12:36:06 -0700 (PDT) Message-ID: <2544bf99-997c-4065-8ae9-4dfb0b07d17b@palves.net> Date: Mon, 25 Mar 2024 19:36:04 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Fix windows_nat_target::fake_create_process ptid To: Eli Zaretskii Cc: gdb-patches@sourceware.org References: <20240322193030.1235342-1-pedro@palves.net> <86wmptzc2f.fsf@gnu.org> Content-Language: en-US From: Pedro Alves In-Reply-To: <86wmptzc2f.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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 2024-03-23 06:39, Eli Zaretskii wrote: >> From: Pedro Alves >> Date: Fri, 22 Mar 2024 19:30:30 +0000 >> >> While working on Windows non-stop mode, I managed to introduce a bug >> that led to fake_create_process being called. That then resulted in >> GDB crashes later on, because fake_create_process added a thread with >> an incorrect ptid for this target. It is putting dwThreadId in the >> tid field of the ptid instead of on the lwp field. This is fixed by >> this patch. >> >> I do however wonder why nobody has seen it this long. > > AFAIU, to actually see the bug, one would need to attach GDB to a > process whose main thread has exited, is that true? If so, I'm not > surprised this bug was not reported: it's unusual for the main thread > to exit without shutting down the process, and the need to attach to > such a process (as opposed to having it run from GDB to begin with) > makes that even more rare. And finally, not every bug is reported by > the first person who sees it the first time, right? Yes, that could be the reason. But it could also be because the brokenness with the Windows debug API that Chris was seeing only happens on Windows versions we no longer claim support for (i.e., earlier than Windows XP). Anyhow, the patch is pretty obvious on its own, so I went ahead and merged it without that blurb in the commit log, like below. I also wrote a testcase that exercises the scenario in question. I'll post that next. Here's what I merged. >From ccf3148e3133f016a8e1484e85e5e4d8c271c4f0 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 22 Mar 2024 19:28:55 +0000 Subject: [PATCH] Fix windows_nat_target::fake_create_process ptid While working on Windows non-stop mode, I managed to introduce a bug that led to fake_create_process being called. That then resulted in GDB crashes later on, because fake_create_process added a thread with an incorrect ptid for this target. It is putting dwThreadId in the tid field of the ptid instead of on the lwp field. This is fixed by this patch. Change-Id: Iaee5d2deaa57c501f7e6909f8ac242af9b183215 --- gdb/windows-nat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index ee38b985efa..b123a66ef0f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1371,8 +1371,8 @@ windows_nat_target::fake_create_process () throw_winerror_with_name (_("OpenProcess call failed"), err); /* We can not debug anything in that case. */ } - add_thread (ptid_t (windows_process.current_event.dwProcessId, 0, - windows_process.current_event.dwThreadId), + add_thread (ptid_t (windows_process.current_event.dwProcessId, + windows_process.current_event.dwThreadId, 0), windows_process.current_event.u.CreateThread.hThread, windows_process.current_event.u.CreateThread.lpThreadLocalBase, true /* main_thread_p */); base-commit: f9ee45c3a95ac37cf1c3f4ac6be34b9a53e306f4 -- 2.43.2