From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Ec/cKrOgFGqyHxoAWB0awg (envelope-from ) for ; Mon, 25 May 2026 15:19:15 -0400 Received: by simark.ca (Postfix, from userid 112) id A23741E0A3; Mon, 25 May 2026 15:19:15 -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 8E4861E024 for ; Mon, 25 May 2026 15:19:14 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 242134BA7987 for ; Mon, 25 May 2026 19:19:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 242134BA7987 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by sourceware.org (Postfix) with ESMTPS id 594804BA902B for ; Mon, 25 May 2026 19:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 594804BA902B 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 594804BA902B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736729; cv=none; b=QNFTct99pQKqcwinQC739bynG3DMpFET8SbFKnUFYlcLYx+rw5vX9EZRTe9pxoOgy0M4iBXuha27Fff0c792U+x3Aybr6a+X1iGPtb+JMifdcT/t0uHPua86vkpzH/JXI3X8S0vCp1ZIhFMWqlZ+jOJIEHXKXRhMOr7Ib5dKWto= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779736729; c=relaxed/simple; bh=jcRIRMFbAKvrCSQ2frf9AbowLjuwRwz5Cvb3TlBbUcQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=sv97TRpFrdrH906YHiFTXFO6K76dIBtwXJan3ernfYopCQbxe/KaWRCrXiPiT7K9tHfP7WheD1MddfqaPypsa0Ki8psyHMwP9sn5Ogaf8kzJCsoly0iP3CWhgVVunfMMCVUXvfUEJh3C1BCsI+F02cgaEnrj98f4RD4ggdjB00Y= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 594804BA902B Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-43fe608cb92so5961954f8f.2 for ; Mon, 25 May 2026 12:18:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779736728; x=1780341528; 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=KegiR+8QIiXNimEjLM//fKwwnb0+13QdRufAYYwEr4k=; b=PKNIUVAHJdj8CeIyiWEynbgsOMcFv9OAyODHqDJua1xXtPA2q+IWHQ/XbXxtHsCMXs OAZqwBVpU7hA34iYdrwBvrRF0ARedCyYNfOfylS+osCF/RU6Mo1ZBb5hLT8Vw4BcDKhx TSM6AoHZyekqy7DmOmOGjxL0wac70E7Xyoq9zw17lafgZRI8ILnsROUPwb1fcD3Y3N/h lljwBXF8/DdSFgG5diKMuropjzaANQywIZITYtITairenrHHpdqsPi1ja6XLCcniJ3CN LYL08WnOp+Bbld+TrqVf+iTPO43U98xjR+ffLribuNMtjtZiLtRTes42fMlvO35E+DYi LW9A== X-Gm-Message-State: AOJu0YwvIdZn+9hnd/+8NKpJai3vroph2Sz0fqK/9KPYpHrqKZeb8si4 HJ+3SG5pFQugpR5OvNCeWT+aiMgH48xSJRX9k67IXU2PIiHsmAsTdHo4J0zNwg== X-Gm-Gg: Acq92OFfprQ7nA5a4muWkgg1EZo6wzuE8r67lAUeQlrSpAZjLqKA7fHoGTMKd5+RWu+ PgJaehfUbxW+yLy7LPKLzJByQd17BV2fGMjgJAgRKZJoybbdeH3BXVbYzftlHj/ysAaQUwF0hau iyXqJjVCd+8reWBuHKdlWFATkq8frCTz9+jr8ouPaUYC/Rb2Ah9FJsUg8QBMsuNN0oJ98OJjXV1 /RBkE22iOe+RS+8Iypv3hsnD17MsPMgYwwf0zP8EjJZMf3NOshLsZ0S+Nq7Pr4VfEPTaLaI2287 B6Sz59O3LIMo8tvk0JTpUUnfUS6p8rFOEo6igvy10hHRpwjIjmXjd10ysJttulq8hndVVZHq7Pg jashv4to7AvpnYK0q/haI0L175V/ybhlZeGFNDEpoaRNoVy82AS3R35HQcG5sgOVPH4rQQdrYH0 EUFtM4P549VEL8SCDOTDXYgg== X-Received: by 2002:a05:6000:2003:b0:45e:653a:40df with SMTP id ffacd0b85a97d-45eb38e4d0dmr25084184f8f.41.1779736728025; Mon, 25 May 2026 12:18:48 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:dc16:ec0f:632c:5ba7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb6ccd211sm37107222f8f.10.2026.05.25.12.18.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2026 12:18:47 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 07/11] Windows gdb+gdbserver: Share exit status logic Date: Mon, 25 May 2026 20:18:25 +0100 Message-ID: <20260525191829.984105-8-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525191829.984105-1-pedro@palves.net> References: <20260525191829.984105-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 Move the exit status logic added by commit 559e7e5056 ("Improve process exit status macros on MinGW") from both GDB and GDBserver to a shared routine used by both. The next patch extends this routine with Cygwin-specific decoding. Change-Id: I4bf08c6beff0d1688064a81d49bbdd615643735e commit-id: 586becd8 --- gdb/nat/windows-nat.c | 24 ++++++++++++++++++++++++ gdb/nat/windows-nat.h | 6 ++++++ gdb/windows-nat.c | 15 +++------------ gdbserver/win32-low.cc | 16 +++------------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index b093acda342..92f9394ca6d 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -18,6 +18,8 @@ #include "nat/windows-nat.h" #include "gdbsupport/common-debug.h" +#include "gdbsupport/gdb_signals.h" +#include "gdbsupport/gdb_wait.h" #include "target/target.h" #undef GetModuleFileNameEx @@ -694,6 +696,28 @@ windows_process_info::add_all_dlls () /* See nat/windows-nat.h. */ +target_waitstatus +windows_process_info::exit_process_to_target_status + (const EXIT_PROCESS_DEBUG_INFO &info) +{ + DWORD exit_code = info.dwExitCode; + target_waitstatus tstatus; + + /* If the exit status looks like a fatal exception, but we don't + recognize the exception's code, make the original exit status + value available, to avoid losing information. */ + int exit_signal + = WIFSIGNALED (exit_code) ? WTERMSIG (exit_code) : -1; + if (exit_signal == -1) + tstatus.set_exited (exit_code); + else + tstatus.set_signalled (gdb_signal_from_host (exit_signal)); + + return tstatus; +} + +/* See nat/windows-nat.h. */ + std::string event_code_to_string (DWORD event_code) { diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 52378765438..d2e6adb4f40 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -315,6 +315,12 @@ struct windows_process_info }); } + /* Convert an EXIT_PROCESS_DEBUG_EVENT payload to a target wait + status. */ + + target_waitstatus exit_process_to_target_status + (const EXIT_PROCESS_DEBUG_INFO &info); + private: /* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a284438bd36..26333238cfa 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -62,7 +62,6 @@ #include "complaints.h" #include "gdbsupport/gdb_tilde_expand.h" #include "gdbsupport/pathstuff.h" -#include "gdbsupport/gdb_wait.h" #include "gdbsupport/symbol.h" #include "inf-loop.h" @@ -1610,17 +1609,9 @@ windows_nat_target::get_windows_debug_event } else if (windows_process->saw_create == 1) { - DWORD exit_status = current_event->u.ExitProcess.dwExitCode; - /* If the exit status looks like a fatal exception, but we - don't recognize the exception's code, make the original - exit status value available, to avoid losing - information. */ - int exit_signal - = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1; - if (exit_signal == -1) - ourstatus->set_exited (exit_status); - else - ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); + *ourstatus + = (windows_process->exit_process_to_target_status + (current_event->u.ExitProcess)); thread_id = current_event->dwThreadId; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 6f1cf5ed025..550994b0bf2 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -33,7 +33,6 @@ #include #include "gdbsupport/gdb_tilde_expand.h" #include "gdbsupport/common-inferior.h" -#include "gdbsupport/gdb_wait.h" using namespace windows_nat; @@ -1061,18 +1060,9 @@ get_child_debug_event (DWORD *continue_status, break; case EXIT_PROCESS_DEBUG_EVENT: - { - DWORD exit_status = current_event->u.ExitProcess.dwExitCode; - /* If the exit status looks like a fatal exception, but we - don't recognize the exception's code, make the original - exit status value available, to avoid losing information. */ - int exit_signal - = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1; - if (exit_signal == -1) - ourstatus->set_exited (exit_status); - else - ourstatus->set_signalled (gdb_signal_from_host (exit_signal)); - } + *ourstatus + = (windows_process.exit_process_to_target_status + (current_event->u.ExitProcess)); continue_last_debug_event (DBG_CONTINUE, debug_threads); break; -- 2.53.0