From patchwork Tue May 7 23:42:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 89690 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02F3C3845148 for ; Tue, 7 May 2024 23:46:18 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by sourceware.org (Postfix) with ESMTPS id D3F9A3849ADA for ; Tue, 7 May 2024 23:44:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3F9A3849ADA 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 D3F9A3849ADA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125443; cv=none; b=jjinl24XFXYs7ty7aQUoSLZ/jCsGFdboCid/WeT8pMpJglm6WBhm+7aIigsX6BeSVnkxWMvjLOf0RHLPgjqEUuen7EH11P5WGISPO+AUN8rYAF2vquLM5zdpIVwMhIW4UWx0MOHYO4UC/gF8IX8PJTGXkQ6B9OypclgjwpYtGMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125443; c=relaxed/simple; bh=2MVMNbnzfyZzTmStfB+vlk7xN6sEL/xueQzrNpltbF4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=R++5KSswncC86n8vVZKg4+xLniqXf5hl/3QhEv7KyIt9yg6Q8VD+J+E5+dikdy/LQ3EcdEoducpNMxgyT7ofmH7y9Gp/sgIx/b7Ffm33ossN2U/nWxtVriUzww/mScZ7Zh7EfchfBoil8gOgLfFwxYtzi9tSOAtd0zPO34B6/+Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-34e040ed031so2675798f8f.0 for ; Tue, 07 May 2024 16:44:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715125439; x=1715730239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aRgxONDqW7HHO25Wi3FMIDL/xmHHmfqAAemnVzVC0A8=; b=XlnwRshnV/qYWNaFULn2i7Lomh/DEhGEsW/tip3mztCWdstTJu5hgFGgroPWNWTnV7 C8noy3uav9c/DsIsLcBsc1lKgTUYw4Kkg4kSdFIbz5AVCP+0tH4G49DqWtZnzOg9sapJ BfxxxR171witFj24ikUdx8pYQGKzng7HWsa+roe6EooPUI8YS4+u44eWMz0hUHN/x2cC qBQ+c+qYTzU4wxuW+FtW2YqBz/PWh0C/nnyQ/JX1qeqy5ldrd4rTX+Rpaf/VshYxX1KF RtrtQ8BAmGoA6TVU2OVNNKyeRjkXUnpmRfguF29tCt9MhX0VtfxDUN0VpRz15DvOOJxk R6UQ== X-Gm-Message-State: AOJu0YzhTJK2HzHdRY2gp3fHF5CHLQQ80axcqoZmKXYn6rwjWiZvnzxp JaH5ocBJEJ1oM6PzM31J5de8kMnl72VD29O0PviaiSRuz+f3eO9KpH4YK3NT X-Google-Smtp-Source: AGHT+IG5HZO7FWe95LgMBq+UHTS0uKEmfVf6LOLbo2vre8ZWHza2UVtRNO5uK7V7wgB65iVBfFyaPQ== X-Received: by 2002:a5d:5147:0:b0:34b:81b3:2c62 with SMTP id ffacd0b85a97d-34fcafcce2fmr659011f8f.35.1715125439321; Tue, 07 May 2024 16:43:59 -0700 (PDT) Received: from localhost ([2001:8a0:f908:4900:2dd1:1a0d:2b75:dc42]) by smtp.gmail.com with UTF8SMTPSA id g4-20020a5d5404000000b0034ca136f0e9sm13910265wrv.88.2024.05.07.16.43.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 16:43:58 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 20/34] Windows gdbserver: Eliminate soft-interrupt mechanism Date: Wed, 8 May 2024 00:42:19 +0100 Message-ID: <20240507234233.371123-21-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240507234233.371123-1-pedro@palves.net> References: <20240507234233.371123-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 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+patchwork=sourceware.org@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. 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. 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 7d37068ab91..99a6150599e 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -307,8 +307,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, @@ -433,7 +431,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); } @@ -941,23 +938,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 @@ -1012,13 +992,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; { for (thread_info *thread : all_threads) @@ -1058,8 +1031,6 @@ get_child_debug_event (DWORD *continue_status, } } - gotevent: - switch (current_event->dwDebugEventCode) { case CREATE_THREAD_DEBUG_EVENT: @@ -1313,8 +1284,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 7ee4de4b37f..4d26b87d73d 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -187,14 +187,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;