From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by sourceware.org (Postfix) with ESMTPS id D81D5385843B for ; Tue, 7 May 2024 23:43:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D81D5385843B 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 D81D5385843B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.208.174 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125394; cv=none; b=hb9FPgOWJaTZClPIfuGjEi6ZCwClFipvfC2ii1WUiZ4OH8eNeB4fMrDrqyCWBW+cSGMtJZhkZPa8e2p2EgmeIIad49ZYNicvLT/J9BDz447vRwqoJhwSrlod1ueWkZ/h8mQoMe+x97FbvJaRMCPNcaAWxD1y6Q3pTdkGPL3WIyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125394; c=relaxed/simple; bh=aAJpKKN8zWq60K7lENEy36zymw4KSD6NKDod/sKs9ws=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=oBEPE+fJ7E5Nf2n20b2VWjIc13/mC+gzT98bKZgX0NZh7pZMj/dz/23t8lO2iVGAigQoctUQY2mPur8VHazFmLrWCdbOzHxP4G3ImY8s7NQncU6V0CMV8f1Mi5QTF0XY50rUdIjke5apiMl8SunZ1p+bZF7i8MkTnVwnqVNSZi8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2e3e18c24c1so18571191fa.1 for ; Tue, 07 May 2024 16:43:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715125388; x=1715730188; 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=YC/sYqphd0RnCtzeifWN326RiMJtLGCxebZehYrmZeQ=; b=PSytVnuBiggWnZZrd+KRmz9cn1R1763D1w7dxHJtUdZNvWWOnMMwKSn7isByaZvCHz rR5XFPW8HXWsVAaUE/+InCsNPciBEMUbtLeXMMfPukuspiR5Lg1ahuS8SnRAU/EIUnZc C8QRAt9R9v3pjuSrRz/nmjd49ZLlAbLDwBQHDdOuKVHIWByw9MZjKmgyxdp0vlpW2Bzd /PgkGDwcq7mnMC4gaJZ1dni0MDfrpsMh/vEBifRWa+D9V00Bgik1BBzOHLCAKtCA2kYK qTiNhKNO90zeGUUbLMa/ZkQobPSnKHYlsqI7Ym7dhxyHNyqPfrgVjG4jB8Lhxm6C9ApW jXnw== X-Gm-Message-State: AOJu0YxJcZc78lcDijwRPBz8Y81RXY+mYg5oVCe1q6BuL20QrP4aZR9P tRqZl1Km+DXCbd/6zkDh8wzi7yxmIlGyALDPKzlTrwhC6AVabf8Dape1IQwf X-Google-Smtp-Source: AGHT+IH5VDx9UgA6plBFJXCcX5D275vthMWArvO1NQEQdaQUD7GZGmeInsfYhoSe3ENDf/y6ELA+EQ== X-Received: by 2002:a2e:9948:0:b0:2dd:c9fc:c472 with SMTP id 38308e7fff4ca-2e447086ab3mr6028801fa.26.1715125387967; Tue, 07 May 2024 16:43:07 -0700 (PDT) Received: from localhost ([2001:8a0:f908:4900:2dd1:1a0d:2b75:dc42]) by smtp.gmail.com with UTF8SMTPSA id v20-20020a05600c445400b0041ac5f19213sm200984wmn.8.2024.05.07.16.43.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 16:43:07 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 09/34] Windows gdb: Simplify windows_nat_target::wait Date: Wed, 8 May 2024 00:42:08 +0100 Message-ID: <20240507234233.371123-10-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.7 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 List-Id: 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 9b1bedee250..9730377d6fc 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -1764,7 +1764,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); } @@ -1785,27 +1788,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.43.2