From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CY2fEZzY+GkpGRMAWB0awg (envelope-from ) for ; Mon, 04 May 2026 13:34:20 -0400 Received: by simark.ca (Postfix, from userid 112) id 44B0B1E0BA; Mon, 04 May 2026 13:34:20 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 BB4A71E067 for ; Mon, 04 May 2026 13:34:19 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 418A74BAE7E6 for ; Mon, 4 May 2026 17:34:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 418A74BAE7E6 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id ACF9E4BAD173 for ; Mon, 4 May 2026 17:33:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACF9E4BAD173 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 ACF9E4BAD173 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777916032; cv=none; b=cn6OJs/XlOjDtyKlh0XPVIYQKxQZw0gF7qICDfSsTkosj+6+vSzXzoz2vbgerEryQ1cxlb5tNCQ8rE2mMCp3c+eYimdx0RRGDiodCe+HTpYtajZtyBAp6Owthvz/ivfAXVRo7uJw6HLJPlh8kgh+hYaJ3yMn97iksfIsL6uPqWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777916032; c=relaxed/simple; bh=Ypd1xqz0Be8LcoEaWBGKleEos95hretHWs9nTVwyRzc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BXbvInUFShCpeE72chBVvknX6eFGC45gYx5jqfviI8/SjCGJ32r/eS1ywwSIWUBqamXD0urV8J1H/TORxNIJJcJJAkNhQEFXKjkcRR44xhcYc9YQsl0QgxGsG2TgHviKcaqJxomSajDnH3YmoUxde30jK6wlWtUuBH12uuNvD38= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACF9E4BAD173 Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-48d102471a4so9848345e9.2 for ; Mon, 04 May 2026 10:33:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777916031; x=1778520831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=L4HQFUgE+S79q1YWK3fhnfxqrWHvmZnIM92l6OyU2Ms=; b=fss1rV3Hg2bf4835LuP09juIemueIruFfdY6EXffPHihnJzzubh3AaY2LdlwS6QpO1 57ANVgMLNWuoSgkHrKmXyWUBAhlA7XJFa/3buqZ5Fqvgt2RH8iH1DEufFrSbi+vLjv7o zY7pJrcA1ELiB4pVpOsMNHc1yFXTpfddL1y5xIhIvtYgdG7jWKLksadsk52ZuLkoc4ww wn4MS/+YJp/UXMtglp+LLLrljuQOhBi4L28qi4ttpBy8LLDTA0WQBrd/WESqotkF4RaD G2YbbfIarOA99GFJzv7fjPaUXklYsz/hiWuWZX8prgtyCf47aia3a1v6dEcuqvYdUgRf ek7w== X-Gm-Message-State: AOJu0YxgoHsvn5Y39WJh3znkLemBAaTUHbUa+NB44soFCCWh9IhbP7ma bUjvihMgH8aZt9TZXMR7Ajta17Miz39e4461qr4JAktdaJPfDwNK/dR3P8lW3A== X-Gm-Gg: AeBDiesMtN9Py6riR97zpYrXFAIdI0IUoXxIII3I3Tj3NHACBnm233XL6ZEuX4vzKoE yUxR+z1IHzpGCVKmRXXiDyoSVNIIuKx6RVpRpepdBkUWOuU/ONup1q76yhWkat/XaguAMjil4sJ IjoK3axgaQQJoXl0Epsj/f2YK0r1l8skBTggHLcbVngA5cnLzRGHLUopL0A9GRHDUCAhFKo8Zhu 6KWebcykoO+UlNyd7HU1LHfj2LmwtDUDsMV8p6zXLdOLnuYfAcB5FWBEDKhiQnBra+4Sl7ifzUM C4Um3oIm0TrPCvmx9Cv/hOMeGHW8zPERV8hVsL/ONyWXRckNQnQnFAN6d+r1LzA79ykpqqYS0QV Ieb7Zzh0EYSqcVGt10hROEmQ5ET0e74gbjq9rOmc5gaiaQYxKlNEp0MqlbNST67sNtB2yqgKYNc xCuFaexSTztyznNeFqTTG6PoR/c/fEGTat X-Received: by 2002:a05:600c:3487:b0:486:fb0b:ad79 with SMTP id 5b1f17b1804b1-48a988a6ec9mr188973995e9.20.1777916031232; Mon, 04 May 2026 10:33:51 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:f625:f0b7:9de7:360b]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-44a981dee90sm26769479f8f.22.2026.05.04.10.33.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2026 10:33:50 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/3] Windows gdb: Show CONTEXT_EXCEPTION_REQUEST info in "info threads" Date: Mon, 4 May 2026 18:33:40 +0100 Message-ID: <20260504173344.1278735-2-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260504173344.1278735-1-pedro@palves.net> References: <20260504173344.1278735-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 This patch makes the Windows native target expose CONTEXT_EXCEPTION_REQUEST information in "info threads" extra info, like so: (gdb) info threads Id Target Id Frame 1 Thread 15648.0x4338 "sleeper" main () at sleeper.c:5 2 Thread 15648.0x3d58 (in syscall) 0x00007ffde37057b4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:/WINDOWS/SYSTEM32/ntdll.dll 3 Thread 15648.0x27e0 "sig" (in syscall) 0x00007ffde3701bc4 in ntdll!ZwReadFile () from C:/WINDOWS/SYSTEM32/ntdll.dll 4 Thread 15648.0x26f0 (in syscall) 0x00007ffde37057b4 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:/WINDOWS/SYSTEM32/ntdll.dll * 5 Thread 15648.0xff8 (in exception) 0x00007ffde00aa464 in KERNELBASE!CtrlRoutine () from C:/WINDOWS/System32/KERNELBASE.dll (gdb) Above, we can see that thread 1 is running user space code, threads 2 to 4 are in some system call, and thread 5 raised an exception (a Ctrl-C). This is useful information to see, as system calls are not interruptible on Windows. E.g. an infcall on a thread that is blocked in a system call will appear to hang, until the system call returns on its own. Change-Id: I04221f123eef81d59b5cc1c9fbb298f7a33fa001 commit-id:d93544e4 --- gdb/nat/windows-nat.h | 3 ++- gdb/windows-nat.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 52378765438..d66d5ec0ed3 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -527,7 +527,8 @@ struct WindowsContext | CONTEXT_SEGMENTS #endif | CONTEXT_DEBUG_REGISTERS - | CONTEXT_EXTENDED_REGISTERS); + | CONTEXT_EXTENDED_REGISTERS + | CONTEXT_EXCEPTION_REQUEST); }; #ifdef __x86_64__ diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a9647e90bb8..d01fbc8e4ba 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -3363,6 +3363,28 @@ windows_nat_target::extra_thread_info (thread_info *info) || th->last_event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) return "exiting process"; + /* Specifying CONTEXT_EXCEPTION_REQUEST in ContextFlags as input + (which we do), asks Windows to report back why the thread entered + kernel mode. If GetThreadContext returns a context with + CONTEXT_EXCEPTION_REPORTING set, it means that it understood the + request. */ + windows_process->fill_thread_context (th); + DWORD context_flags = *windows_process->context_flags_ptr (th); + if ((context_flags & CONTEXT_EXCEPTION_REPORTING) != 0) + { + /* The thread was running user space code which raised an + exception, which we intercepted. */ + if ((context_flags & CONTEXT_EXCEPTION_ACTIVE) != 0) + return "in exception"; + + /* The thread was running a system call. */ + if ((context_flags & CONTEXT_SERVICE_ACTIVE) != 0) + return "in syscall"; + + /* Otherwise, the thread was simply suspended while running + user space code. */ + } + return nullptr; } -- 2.53.0