Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 4/5] Fix exit/signal code on Cygwin
Date: Fri, 22 May 2026 10:15:06 +0300	[thread overview]
Message-ID: <86se7jykxx.fsf@gnu.org> (raw)
In-Reply-To: <20260522001626.393908-5-pedro@palves.net> (message from Pedro Alves on Fri, 22 May 2026 01:16:25 +0100)

> From: Pedro Alves <pedro@palves.net>
> Date: Fri, 22 May 2026 01:16:25 +0100
> 
> 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.

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.  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.

> +#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?

Other than these questions, the MinGW part of the code looks okay to
me, thanks.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

  reply	other threads:[~2026-05-22  7:15 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 [this message]
2026-05-25 16:47     ` Pedro Alves
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=86se7jykxx.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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