From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iEjmAHHc/WW+4REAWB0awg (envelope-from ) for ; Fri, 22 Mar 2024 15:30:57 -0400 Received: by simark.ca (Postfix, from userid 112) id E42EE1E0C0; Fri, 22 Mar 2024 15:30:56 -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 C8BEB1E08C for ; Fri, 22 Mar 2024 15:30:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FAC73858403 for ; Fri, 22 Mar 2024 19:30:54 +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 07AA13858D1E for ; Fri, 22 Mar 2024 19:30:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07AA13858D1E 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 07AA13858D1E 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=1711135835; cv=none; b=rAOF8n9auzNdeHef40ox3IOGNeJZl3Jj3sqge42UKY389shoc9b3cUPgtuplnw3aKYIy8fVeFGmq+XXgrKY35d2Qw2AaoBywWc2L76Of0JLDjxpAJnnALmCjQz96qkHj7HUr//FyUNuZ6dhDE/FVej+31t951JtM4nBYFL4nZwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711135835; c=relaxed/simple; bh=6jT6+pn/dneorBGWKv1H3X/XGTS/pwrxLp/+WWdt25U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hWZLWMX63vz+u2ROsLKb6tBMDPXACBINLseLG6Sv4qNUZ9+5R84XEFbRpH57gHDixiQZkaFMydAimPj5DMvnVpkzpS+v/ICql+Hz45wL8nrjr8TqH1Z3yyTzDU3HJ4FSJHXwycimZWv/nLk4eDQBOZbbYax9eHTg8KbCzkrv4PA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4147f546a64so1983755e9.0 for ; Fri, 22 Mar 2024 12:30:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711135832; x=1711740632; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ixS5OXIbmIyTcAXZnxAVrLqtmlfRhfL5jDkHooe2Pdw=; b=wQAWa8a79IXnZTFDjAq/jScsKq6dfm+2kmelhNFKG45RX/ArpIciN2ij/ouPL4Fkct Ra0a4noEjRZlT4vai9Y/KdqwcFJYVbbhHn7E1WaXFgmmeVzyAKKymG5oLmlDFCGNHfdR ZL2UM0enYpoP6JKNJJ/9ZaigFVOXXl7UddxeobWzjBA+s2/wVj9mlCKORBuFrw1hMOed MkBT6Taca9k+HaIyoVqg6Y3QTysLs0R6M/B+piwUiIV4p7XCKF4S1IaKAB+fLPpw46aF w0KT72GVfvV7mazoTuhRLjlbjCH/ZgUznMUVmZZkpjBWPsrZfKIP3MyRY6cUK2ASS73Z WdTQ== X-Gm-Message-State: AOJu0Yy6Zl/Le0VmnTk54G+rHcvktvnA6tn/BAioQH/meCQnd5laG7KL 0pqSkG8McHqg65gouQYE37mCCS4TqWeXdCxMantav04BxYVVnroZTgDoMIXB X-Google-Smtp-Source: AGHT+IEVo8RxQ+9+TlwVC6z/nEUOnDwqH8JL5pbrnLZv9SgfqLZoEYtNf7bqLsfBwzJRh4GBi9KcCA== X-Received: by 2002:a5d:4e0e:0:b0:33e:7942:4139 with SMTP id p14-20020a5d4e0e000000b0033e79424139mr222336wrt.61.1711135832485; Fri, 22 Mar 2024 12:30:32 -0700 (PDT) Received: from localhost ([2001:8a0:f918:ab00:3ba9:feec:1922:9a68]) by smtp.gmail.com with UTF8SMTPSA id g20-20020a05600c4ed400b00413e63bb140sm349001wmq.41.2024.03.22.12.30.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Mar 2024 12:30:32 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Fix windows_nat_target::fake_create_process ptid Date: Fri, 22 Mar 2024 19:30:30 +0000 Message-ID: <20240322193030.1235342-1-pedro@palves.net> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.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 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. The fake_create_process code was added for https://sourceware.org/bugzilla/show_bug.cgi?id=8153 and Chris said back then, in: https://sourceware.org/legacy-ml/gdb-patches/2003-12/msg00479.html "If the main thread has exited, there is never any create process notification when attaching to a process. That confuses all sorts of things." Unfortunately, nowhere was it stated which version of Windows was that observed on. I don't see any missing CREATE_PROCESS_DEBUG_EVENT when I try the reproducer from the bugzilla on Windows 10. I would have to try on Windows XP (the oldest version of Windows we claim to support), but I don't have such a machine handy. Do note however, that GDBserver has never gotten an equivalent to fake_create_process. But I'm not sure that is proof enough that we can yank that out from GDB, as seemingly not many people use Windows gdbserver. 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 a90388922e2..a0013aa81e0 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1365,8 +1365,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: c05dd51122c2d654031b04e02ad0ea5b53ffe5e2 -- 2.43.2