From: Pedro Alves <pedro@palves.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 4/5] Fix exit/signal code on Cygwin
Date: Mon, 25 May 2026 17:47:38 +0100 [thread overview]
Message-ID: <2f04d0f3-38dd-4941-a767-59c5119d97cb@palves.net> (raw)
In-Reply-To: <86se7jykxx.fsf@gnu.org>
On 2026-05-22 08:15, Eli Zaretskii wrote:
>> From: Pedro Alves <pedro@palves.net>
...
>> 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.
>
> AFAIU, this basically adds a Cygwin-specific branch to the code that
> determines the terminating signal and status of a program, leaving the
> code for the native Windows and MinGW programs intact.
Yes. For v2, I split the refactor to its own patch, which I think makes
that more obvious.
> I suggest to
> say this in the commit log message, because as written, it sounds like
> it does something for Cygwin that is not done for MinGW. Which is not
> true.
Done this too, thanks.
>
>> +#ifdef __CYGWIN__
>> + /* /usr/include/cygwin/wait.h explains that a wait status is 16
>> + bits, and looks like:
>> +
>> + "<1 byte info> <1 byte code>
>> + <code> == 0, child has exited, info is the exit value
>> + <code> == 1..7e, child has exited, code is the signal number.
>> + <code> == 7f, child has stopped, info was the signal number.
>> + <code> == 80, there was a core dump."
>> +
>> + However, when passing the wait status to native ExitProcess as a
>> + native exit code, cygwin1.dll swaps the <info>/<code> bytes.
>> + Swap them back into a wait status here. */
>> + int wstatus = ((exit_code & 0xff) << 8) | ((exit_code >> 8) & 0xff);
>
> Should the commentary say something about _why_ we swap the bytes
> here? I know very little about Cygwin, but my naïve view is that when
> a Cygwin program is run from another Cygwin program, no such swapping
> should be needed, is that right? One should just use the macros from
> the sys/wait.h header, right? If so, why do we need to swap the bytes
> here, and how is "passing the wait status to native ExitProcess as a
> native exit code" relevant to what this part of GDB needs to do?
Thanks for raising the question, it made me look deeper, dig into the Cygwin code
in mode detail, and realize that in the attach case, we shouldn't do the swap.
v2 has more and better comments explaining all this, as well as handling the
attach case, and testing it too. The new comments will implicitly answer your
questions. I'll be sending v2 shortly to the list.
Pedro Alves
>
> Other than these questions, the MinGW part of the code looks okay to
> me, thanks.
>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
>
next prev parent reply other threads:[~2026-05-25 16:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 0:16 [PATCH 0/5] Fix a few Cygwin/MinGW problems Pedro Alves
2026-05-22 0:16 ` [PATCH 1/5] Fix "set cwd ..." on Cygwin, part 1 Pedro Alves
2026-05-22 13:54 ` Tom Tromey
2026-05-22 0:16 ` [PATCH 2/5] Fix "set cwd ..." on Cygwin, part 2 Pedro Alves
2026-05-22 14:37 ` Tom Tromey
2026-05-25 16:43 ` Pedro Alves
2026-05-22 0:16 ` [PATCH 3/5] Adjust gdb.base/exitsignal.exp for Cygwin Pedro Alves
2026-05-22 15:09 ` Tom Tromey
2026-05-22 0:16 ` [PATCH 4/5] Fix exit/signal code on Cygwin Pedro Alves
2026-05-22 7:15 ` Eli Zaretskii
2026-05-25 16:47 ` Pedro Alves [this message]
2026-05-22 0:16 ` [PATCH 5/5] Adjust gdb.python/py-events.exp for Cygwin/MinGW Pedro Alves
2026-05-22 7:18 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2f04d0f3-38dd-4941-a767-59c5119d97cb@palves.net \
--to=pedro@palves.net \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox