From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uEjrJ+MyK2g2NyoAWB0awg (envelope-from ) for ; Mon, 19 May 2025 09:32:19 -0400 Received: by simark.ca (Postfix, from userid 112) id A128A1E11C; Mon, 19 May 2025 09:32:19 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 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 28D501E102 for ; Mon, 19 May 2025 09:32:19 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD8763858410 for ; Mon, 19 May 2025 13:32:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD8763858410 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by sourceware.org (Postfix) with ESMTPS id B4DEF3858410 for ; Mon, 19 May 2025 13:24:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4DEF3858410 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 B4DEF3858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661068; cv=none; b=yDKPEY8MsPHpDhXEgU6yo4AcfaEtg4qJ+O0sN5EzMOLtlZ/RtwbB+G5J2Bnb7vuP1CfSHKdhghvIafDP2NP/BtRoyHuZbVXr6nxzbrgA1kJD1iOJ0kWeLaWv315lnT4rNuQV3z2dG0jjW5cWDtUof6ibtT/NxrMvDrETgSTuyc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661068; c=relaxed/simple; bh=BctSZOxobUWuGO41EH3C9L58QXBBR/LZbGzqp0mBF7k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=cZPl8enh5uI1c49sUizIOxe+RD0DAB8yexzA1h347GpbHdvNIWrYImyeTAXzKM82ccsjEF3xjp0fe3/jcM7/dPMaGaziYvPJNsH8YBlKQ8PEOMJ2qpm0ww9oKsXzE71Guv6jRiOV/vI7eNO0QBkxtvfOyQ8/wXHWMxZtWRCn6NA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4DEF3858410 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43d2d952eb1so34721655e9.1 for ; Mon, 19 May 2025 06:24:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747661067; x=1748265867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l8Bu8azuUHjWukRQCVe3JtdMff//egBXOb5MIBG8yes=; b=c7DtzABbijRN7bYMC7qb0i6tbC8oj+lQqPKgWb2XJDhJ7eJ4mqs+VzCFTd0mbjX7bp pjtre6t2HFp3hacilrub9qrkB2CEv4ssa34q3QEYWJfQqRV7HWmVRQncFz6M0klYDu+1 7USE6wRB6dLv0ijs98TWQKCOZrkboF6/niQH0y6TEAmO2184BXdtZCd5VOOwsOn4nuiZ xLbw505aRdMcbVWW9xpBxPv1qiRR3YNBDCx27L/vKUTiiqGWgQBTXi+hNcmPHiyrdUIp H+I+9I/qmsV2FPB565GTFcAG2eex6ueNQgfQfn+jcVly14PrbPIft2/d9ngzIL9M78ia r63w== X-Gm-Message-State: AOJu0Yxfa69PthrXYjIaqvyEf0mx5NrSqXiTYRXNtnoiR6/wNsnLaUiw ii7H42jKATv1hNS+5GoZ9w233DOJUuA9u24f783uFDhyZkRwC7kE7hpKIRR1WEa4 X-Gm-Gg: ASbGncuxcaCD/BAHaXdgHpxVxdNZro37fn0QIFAcWaR/46OlppmAfqtTFB3ETsFo8L3 49FbNkXD/H6qlo5l44zK1w0tUE3mBRTpk/84gRzO/r57HVc7AK1+MC0afJQGVT5FB8UNx9OwXXL uMjZchTiqDGX5kcK9cUdltDI9X81I265y9HGIUNlTDStqhaInpBMyym4zMdZsGNsANcbUToCOjC dZ6iEGd7wwMic0pUhFGz6Dcd2OX6OHvIF5YcvLJy1ajUjQ4JcuhHckbSPKNHGkARTT05GIdCJdJ eZXXuQvAEB+x/12A+LAKAzt0nn3+CN7lgzSOvUJiNgZuYCzNypc= X-Google-Smtp-Source: AGHT+IGBIWW03Cg6h3c6oNKRK89edKRajPKtA4CImezaYPtqD3ha3FAQZP0z+vZ1lB9pVRkAp1DT3Q== X-Received: by 2002:a05:600c:34c4:b0:43c:ee62:33f5 with SMTP id 5b1f17b1804b1-442fd6752e7mr122598215e9.27.1747661067184; Mon, 19 May 2025 06:24:27 -0700 (PDT) Received: from localhost ([2001:8a0:4fe9:b400:8d90:6f0d:36bf:32df]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-442f3951b57sm218264645e9.21.2025.05.19.06.24.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 May 2025 06:24:26 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 25/47] Windows gdbserver: Eliminate soft-interrupt mechanism Date: Mon, 19 May 2025 14:22:46 +0100 Message-ID: <20250519132308.3553663-26-pedro@palves.net> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250519132308.3553663-1-pedro@palves.net> References: <20250519132308.3553663-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 I noticed that faked_breakpoint is write only. And then I hacked win32_process_target::request_interrupt to force it to stop threads using the soft_interrupt_requested mechanism (which suspends threads, and then fakes a breakpoint event in the main thread), and saw that it no longer works -- gdbserver crashes accessing a NULL current_thread, because fake_breakpoint_event does not switch to a thread. This code was originally added for Windows CE, as neither GenerateConsoleCtrlEvent nor DebugBreakProcess worked there. Windows CE support has since been removed. We nowadays require Windows XP or later, and XP has DebugBreakProcess. The soft_interrupt_requested mechanism has other problems, like for example faking the event in the main thread, even if that thread was previously stopped, due to scheduler-locking. A following patch will add a similar mechanism stopping all threads with SuspendThread to native GDB, for non-stop mode, which doesn't have these problems. It's different enough from this old code that I think we should just rip the old code out, and reimplement it from scratch (based on gdb's version) when we need it. Approved-By: Tom Tromey Change-Id: I89e98233a9c40c6dcba7c8e1dacee08603843fb1 --- gdbserver/win32-low.cc | 32 +------------------------------- gdbserver/win32-low.h | 8 -------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 2e3e4442012..ebce67cd72d 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -294,8 +294,6 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached) windows_process.process_id = pid; windows_process.main_thread_id = 0; - windows_process.soft_interrupt_requested = 0; - windows_process.faked_breakpoint = 0; windows_process.open_process_used = true; memset (&windows_process.current_event, 0, @@ -418,7 +416,6 @@ child_continue_for_kill (DWORD continue_status, int thread_id) { continue_one_thread (thread, thread_id); }); - windows_process.faked_breakpoint = 0; return continue_last_debug_event (continue_status, debug_threads); } @@ -918,23 +915,6 @@ suspend_one_thread (thread_info *thread) th->suspend (); } -static void -fake_breakpoint_event (void) -{ - OUTMSG2(("fake_breakpoint_event\n")); - - windows_process.faked_breakpoint = 1; - - memset (&windows_process.current_event, 0, - sizeof (windows_process.current_event)); - windows_process.current_event.dwThreadId = windows_process.main_thread_id; - windows_process.current_event.dwDebugEventCode = EXCEPTION_DEBUG_EVENT; - windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode - = EXCEPTION_BREAKPOINT; - - for_each_thread (suspend_one_thread); -} - /* See nat/windows-nat.h. */ bool @@ -989,13 +969,6 @@ get_child_debug_event (DWORD *continue_status, DEBUG_EVENT *current_event = &windows_process.current_event; - if (windows_process.soft_interrupt_requested) - { - windows_process.soft_interrupt_requested = 0; - fake_breakpoint_event (); - goto gotevent; - } - windows_process.attaching = 0; { process_info *proc = find_process_pid (windows_process.process_id); @@ -1036,8 +1009,6 @@ get_child_debug_event (DWORD *continue_status, } } - gotevent: - switch (current_event->dwDebugEventCode) { case CREATE_THREAD_DEBUG_EVENT: @@ -1291,8 +1262,7 @@ win32_process_target::request_interrupt () if (DebugBreakProcess (windows_process.handle)) return; - /* Last resort, suspend all threads manually. */ - windows_process.soft_interrupt_requested = 1; + OUTMSG2 (("Could not interrupt.\n")); } bool diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h index 3c49ca7de9b..b170eb898f6 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -194,14 +194,6 @@ struct gdbserver_windows_process : public windows_nat::windows_process_info debug event off the win32 API. */ struct target_waitstatus cached_status; - /* Non zero if an interrupt request is to be satisfied by suspending - all threads. */ - int soft_interrupt_requested = 0; - - /* Non zero if the inferior is stopped in a simulated breakpoint done - by suspending all the threads. */ - int faked_breakpoint = 0; - /* True if current_process_handle needs to be closed. */ bool open_process_used = false; -- 2.49.0