From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SQyUOn+gD2q1sQ0AWB0awg (envelope-from ) for ; Thu, 21 May 2026 20:17:03 -0400 Received: by simark.ca (Postfix, from userid 112) id ED2721E091; Thu, 21 May 2026 20:17:03 -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 5C7D61E024 for ; Thu, 21 May 2026 20:17:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7943E48F6678 for ; Fri, 22 May 2026 00:17:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7943E48F6678 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by sourceware.org (Postfix) with ESMTPS id 0B29D48F60CE for ; Fri, 22 May 2026 00:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B29D48F60CE 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 0B29D48F60CE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408998; cv=none; b=gHHCE9SopSUUjJ8VCydeoaDFb7puSZA3DNH0eQWd1/rbDPccyhvXA4UqRAKjWYpncp5nLQCYpP822TOnFvvJxsfUkmTOL4HFh+IpihdlTvpB+o1EsO6vBHEznXBbyObY1ebuvQD6P+NeCNuI4l2bmRdNRQbGFuWvV+Y/6CZeINk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779408998; c=relaxed/simple; bh=79avVuj9z0/rTXR+gRHTelriPmaE6GTyp3H+RPR9uLg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=x0W1t5TidnkXVlMYLHj+GsaWLS1FMSX7WRcZeaOFMib9ygNw3/MeXmIpWGh2NDNAgZ7Zoo0xx7cpD9aZqElNXIXyzA0EazUOXY3CZRYAxq640Od4uNwJ4aqIBIOJ+hu9GUfb/dJj5quOSI1CmJpsFUdJmsV1kVPMEd7TSunxk9E= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B29D48F60CE Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-49039a8851fso13106155e9.2 for ; Thu, 21 May 2026 17:16:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779408997; x=1780013797; 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=xMEA4emqv+Wk/IurI4EGU3gCGGC7bXRlKSl07aetTCs=; b=eHDNas53eeUxJwZHqV2OJR5aauTdTlUSrUgcXRAdadUHC41KlnkjtKrxr6G6TKa8+l PbYD2azSS5laF+kDmZqPcCn8zSnAEktlAS+IE4Ydce8VQQujuJg2n70BC/mtYYit/5YQ wGwvSAfMg20ttTxT4o/tMYM1UM3hdTN/3kLg6obpy1zTCRVLARmkR30uY1bgJgOm1ga+ /xywFHPLfgi0/7ukSnKMm2zBhcBQcRCJEpisc2B4ByS+osAnw7eauOswl/BAJpFbAx10 CblvE0X0j3BGFpJJwgVD7PPb2GDGvOJ34Mnkao3VFMbSo4X+VOutp5VFpzlKXNgAOyDW 9sKg== X-Gm-Message-State: AOJu0YweKXy7Iiq/bmxB4g2SyzO1NkBgZ9YnExj389Sb/fzFMrSMtTqk Rj4i28THRpUXYKcPVeGydH4vphMxO4yC07mAG0kiRX0SM6lOr09qg311O1Y5+g== X-Gm-Gg: Acq92OGrBjkSX1aqsnRi2TFH10238H5PLEdzubo0VX3YYyXSBKeS2tY6hhwdVmWk3z9 ALnel8YP5mg3Ij8L1o/gjoDEm9UZ4eyOdU7Qti235SoH8Yhu+RQioTD9EmVdm8WbaX+FB7M93ri Eu+qa5klZ7YsMy73KOux3R+mbRfpT84YQpJZmM7wDMC6n8srbQBbamposXa2ceGaQykZqBUZIXI 74lYujasxgxFV36dptwaBcvSW0+UGJ83btPSy7Tef1P+dyDm1pflKujjHGNI0UM2Ak799lZJSXt t/LpFtlDt9GW8kAOx76h5yYMATNXKpPlJacdrRNmJPWbgeijes5Gr6HfGuueGLeLR2SrDHqkBrC vzXeSevnoHYLnjtEu8bUuX678RYiSM+T2Mgm6oH7Gye2WL9QZd83qvQykhbjON+TpXvB8GGLDab vsJKRAWYl/ZjJC5VE6mLDPPOOkRKg1bhaKbk1U7z6gZHI= X-Received: by 2002:a05:6000:4a05:b0:451:bee9:17c8 with SMTP id ffacd0b85a97d-45eb36b0275mr1133100f8f.6.1779408996789; Thu, 21 May 2026 17:16:36 -0700 (PDT) Received: from localhost ([2001:8a0:fae3:2600:cb04:347e:aaad:ca08]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-45eb4977c81sm862665f8f.11.2026.05.21.17.16.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 May 2026 17:16:36 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 4/5] Fix exit/signal code on Cygwin Date: Fri, 22 May 2026 01:16:25 +0100 Message-ID: <20260522001626.393908-5-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260522001626.393908-1-pedro@palves.net> References: <20260522001626.393908-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 I noticed that on native Cygwin, gdb.python/py-events.exp has this: [Thread 15952.0x534 (id 1) exited with code 12] ... Program terminated with signal SIGSYS, Bad system call. ... (gdb) FAIL: gdb.python/py-events.exp: Inferior 1 terminated. The program exits with normal exit code 12, not a signal. SIGSYS is 12. Similarly, gdb.base/exitsignal.exp has this: continue Continuing. [Thread 15220.0x219c (id 1) exited with code 2816] [Thread 15220.0x3a50 (id 3) exited with code 2816] [Thread 15220.0x25a0 (id 4) exited with code 2816] [Inferior 1 (process 15220) exited with code 05400] (gdb) FAIL: gdb.base/exitsignal.exp: program terminated with SIGSEGV (the program exited) Here, the program exits with SIGSEGV, not normal exit code 2816 (05400 in octal). The problem is that gdb/windows-nat.c does not know about Cygwin's exit codes as seen from the native Windows side. Same for gdbserver's win32-low.c. This commit fixes it. To avoid duplicating code, it adds a new native_exit_code_to_target_status function in nat/windows-nat.c used by both GDB and GDBserver, with the MinGW-specific logic added by commit 559e7e5056 ("Improve process exit status macros on MinGW") moved there too. Change-Id: I5c4d9cd81209d46598575518ef2fd205d77f9b66 commit-id: 153617c2 --- gdb/nat/windows-nat.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gdb/nat/windows-nat.h | 4 ++++ gdb/windows-nat.c | 14 ++------------ gdbserver/win32-low.cc | 13 ++----------- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index b093acda342..4c8c9ea32a8 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,46 @@ windows_process_info::add_all_dlls () /* See nat/windows-nat.h. */ +target_waitstatus +native_exit_code_to_target_status (DWORD exit_code) +{ + target_waitstatus tstatus; + +#ifdef __CYGWIN__ + /* /usr/include/cygwin/wait.h explains that a wait status is 16 + bits, and looks like: + + "<1 byte info> <1 byte code> + == 0, child has exited, info is the exit value + == 1..7e, child has exited, code is the signal number. + == 7f, child has stopped, info was the signal number. + == 80, there was a core dump." + + However, when passing the wait status to native ExitProcess as a + native exit code, cygwin1.dll swaps the / bytes. + Swap them back into a wait status here. */ + int wstatus = ((exit_code & 0xff) << 8) | ((exit_code >> 8) & 0xff); + if (!WIFSIGNALED (wstatus)) + tstatus.set_exited (WEXITSTATUS (wstatus)); + else + tstatus.set_signalled (gdb_signal_from_host (WTERMSIG (wstatus))); +#else + /* 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)); +#endif + + 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..1cabe288cee 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -347,6 +347,10 @@ struct windows_process_info int get_exec_module_filename (char *exe_name_ret, size_t exe_name_max_len); }; +/* Convert a native ExitProcess exit code to a target wait status. */ + +extern target_waitstatus native_exit_code_to_target_status (DWORD exit_code); + /* Return a string version of EVENT_CODE. */ extern std::string event_code_to_string (DWORD event_code); diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a284438bd36..54755a4c996 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,8 @@ 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)); + DWORD exit_code = current_event->u.ExitProcess.dwExitCode; + *ourstatus = native_exit_code_to_target_status (exit_code); thread_id = current_event->dwThreadId; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 6f1cf5ed025..23812c0689f 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; @@ -1062,16 +1061,8 @@ get_child_debug_event (DWORD *continue_status, 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)); + DWORD exit_code = current_event->u.ExitProcess.dwExitCode; + *ourstatus = native_exit_code_to_target_status (exit_code); } continue_last_debug_event (DBG_CONTINUE, debug_threads); break; -- 2.53.0