From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SOJ/AAoyK2i1NioAWB0awg (envelope-from ) for ; Mon, 19 May 2025 09:28:42 -0400 Received: by simark.ca (Postfix, from userid 112) id F3BF51E11C; Mon, 19 May 2025 09:28:41 -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 766FB1E102 for ; Mon, 19 May 2025 09:28:41 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 17EC83858429 for ; Mon, 19 May 2025 13:28:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17EC83858429 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by sourceware.org (Postfix) with ESMTPS id 0FAC43858D26 for ; Mon, 19 May 2025 13:23:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FAC43858D26 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 0FAC43858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661038; cv=none; b=HF+ciAZ4nGuLYAzBqNo6S/G8F5mb83OkUt0K8Ah0N9ZTDxdP9OnA04kpOt/BVLxmXs3qEuKUK5wliGUXtqo+fEyuyOnkqMXT3ubks5h1mJYuX30Hkepl5vbOgJTS0IXQ9AS1srMWzYVXRVQejnRf6VNqhdp05sKBA4Cc+OrI2NU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661038; c=relaxed/simple; bh=qZSCAQ3BQezCHf5o/z2M8Ei+iwnLNFd8pg6vJpvpfec=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hu7TpvNuFUc3UQi5jUQRK8hZiI/Zo+AZdTeg5jTYm1ny4c6TBdKDH++c2KMwX6de4YRGTZGgOm0SWhsH7P7OkmadqHp2K9HVhaAt/D957a/omQyX7QHnp4f0096mR3VEDLmeUVHU55ww/Lf3ujYLhTUym4LxA6ng4aotFFGO1NQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FAC43858D26 Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3a0ac853894so3828440f8f.3 for ; Mon, 19 May 2025 06:23:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747661037; x=1748265837; 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=bAy/MVTRJWXMvJ+6pQV2f8Q2xeK1zmW8gm3IJGhJK1Y=; b=mHMAToTVgXURot2SEbNWA0u1P7CLH/nQdeutV/Uh1Vjz+g20nnWAox4GPVyp4F3wyl mpbphdYjz8gLVi+EjGPpfcp0t1BaOZzzS8P1bL2M6Ny0XaNfLP16Jsnxcq1bp6DR7TkP 711xudq6Bvc4WrY0ZRt21go7YcElBYL8UqLsX+tb0IRD+24XTqam4Nvj80YmolLyji2z srjE6k/KNfdZ/EhNprNkTKJPPXypC4Yi+aBL1L9ki9Pm6Qpsv0youcWMmDo4iZ5F/btv bEb7iheInxu9ZNgtepRJLJ0f/4NSU9h054y5IE4oyxo6JdZwW7Nbpuu5wQtfUZWTZaEm Gyfw== X-Gm-Message-State: AOJu0YzMMzC8lafzjxdoyRk7kgFVjG5g7E/E+NqtXqvbc/1C8+xVoKwM OPf5hYG1G83c19H/ZPhV6duH/W9NGj7SZVtK4/1hUbYt02laK3D9CAIuJzzAn4s5 X-Gm-Gg: ASbGncvvB2EQBi3XcptNy3EJ5HCuZaa5MWtp0X+Jvd10x3snLkSVrGHzj6HfKu7fnuD GuXO7rXiQ31/pv6LPt1OnlYilRa7ORkf/AAJcO6+3gDtz5CevwOqJXisCUGgNsgN4rOfsnKGCJ0 Z17D3UU6Ib37w2c7q8KF+t0cmW966USfdjwLq6hlIAO2HKBaYNiUzhYqK4EdyJyiXZYOCYcRrC2 ZevLFyft1ACn+mNNO102GX/Iv2zsDpWbHcqV99IdsOmdUH1YN44VY+4zccYlO9reDKNix06zWK1 JgTs8qdgczqczeO83ZTw1kGOFJW7l2H2sSwz8r3jM/JDY3k15oI= X-Google-Smtp-Source: AGHT+IFk/UQFdNit9MgTMcrt+BecY6B2D+kov3C3Q1EaKsJjNzeY2WJlxIoyAr3bXEoW1esgQQCTEg== X-Received: by 2002:a05:6000:400f:b0:3a0:b37f:c97e with SMTP id ffacd0b85a97d-3a35c821c56mr10933980f8f.4.1747661036575; Mon, 19 May 2025 06:23:56 -0700 (PDT) Received: from localhost ([2001:8a0:4fe9:b400:8d90:6f0d:36bf:32df]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a3620dbc6asm11635263f8f.88.2025.05.19.06.23.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 May 2025 06:23:56 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 14/47] Windows gdb: Simplify windows_nat_target::wait Date: Mon, 19 May 2025 14:22:35 +0100 Message-ID: <20250519132308.3553663-15-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 The logic in windows_nat_target::wait, where we decide what to do depending on the result from get_windows_debug_event is harder to grasp than it looks. It is not easy to tell what should happen when in async mode get_windows_debug_event returns that there's no event to process. And then, if get_windows_debug_event returns null_ptid / TARGET_WAITKIND_SPURIOUS, then we need to issue a ContinueDebugEvent. There's also this comment in windows_nat_target::wait, which we're not really implementing today: ~~~~ /* We loop when we get a non-standard exception rather than return with a SPURIOUS because resume can try and step or modify things, which needs a current_thread->h. But some of these exceptions mark the birth or death of threads, which mean that the current thread isn't necessarily what you think it is. */ ~~~~ This patch changes things a bit so that the code is more obvious: - look at the status kind, instead of ptid_t. - add an explicit early return case for no-event. - add an explicit case for TARGET_WAITKIND_SPURIOUS. - with those, we no longer need to handle the case of find_thread not finding a thread, so we can drop one indentation level. Change-Id: I76c41762e1f893a7ff23465856ccf6a44af1f0e7 --- gdb/windows-nat.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index f15b7520296..9b8bb66d700 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1661,7 +1661,10 @@ windows_nat_target::get_windows_debug_event } if (thread_id == 0) - return null_ptid; + { + ourstatus->set_ignore (); + return null_ptid; + } return ptid_t (windows_process.current_event.dwProcessId, thread_id, 0); } @@ -1682,27 +1685,33 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, { ptid_t result = get_windows_debug_event (pid, ourstatus, options); - if (result != null_ptid) + if ((options & TARGET_WNOHANG) != 0 + && ourstatus->kind () == TARGET_WAITKIND_IGNORE) + return result; + + if (ourstatus->kind () == TARGET_WAITKIND_SPURIOUS) + { + CHECK (windows_continue (DBG_CONTINUE, + windows_process.desired_stop_thread_id, 0)); + } + else if (ourstatus->kind () != TARGET_WAITKIND_IGNORE) { if (ourstatus->kind () != TARGET_WAITKIND_EXITED - && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED) + && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED) { windows_thread_info *th = windows_process.find_thread (result); - if (th != nullptr) + th->stopped_at_software_breakpoint = false; + if (windows_process.current_event.dwDebugEventCode + == EXCEPTION_DEBUG_EVENT + && ((windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode + == EXCEPTION_BREAKPOINT) + || (windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode + == STATUS_WX86_BREAKPOINT)) + && windows_process.windows_initialization_done) { - th->stopped_at_software_breakpoint = false; - if (windows_process.current_event.dwDebugEventCode - == EXCEPTION_DEBUG_EVENT - && ((windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode - == EXCEPTION_BREAKPOINT) - || (windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode - == STATUS_WX86_BREAKPOINT)) - && windows_process.windows_initialization_done) - { - th->stopped_at_software_breakpoint = true; - th->pc_adjusted = false; - } + th->stopped_at_software_breakpoint = true; + th->pc_adjusted = false; } } -- 2.49.0