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 v2 08/11] Windows gdb+gdbserver: Decode Cygwin ExitProcess codes
Date: Tue, 26 May 2026 14:31:19 +0300	[thread overview]
Message-ID: <86h5nuquew.fsf@gnu.org> (raw)
In-Reply-To: <20260525191829.984105-9-pedro@palves.net> (message from Pedro Alves on Mon, 25 May 2026 20:18:26 +0100)

> From: Pedro Alves <pedro@palves.net>
> Date: Mon, 25 May 2026 20:18:26 +0100
> 
> +void
> +windows_process_info::maybe_note_cygwin1_dll (const char *dll_path)
> +{
> +  const char *base = dll_path + strlen (dll_path);
> +  while (base > dll_path && base[-1] != '/' && base[-1] != '\\')
> +    base--;
> +  if (strcasecmp (base, "cygwin1.dll") == 0)
> +    cygwin1_dll_loaded = true;
> +}

I wonder if this should also detect the MSYS2 DLL, since (AFAIU) MSYS2
is a fork of Cygwin.  But I don't know what is the status of GDB
support for debugging MSYS2 executables.

> +  /* The inferior may also exit with a raw NTSTATUS error code, e.g.,
> +     STATUS_ACCESS_VIOLATION (0xc0000005), without going through the
> +     pinfo::exit at all -- for example, if the unhandled-exception
> +     filter didn't run, or for processes that don't link cygwin1.dll.
> +     Detect those and map them the same way Cygwin's set_exit_code
> +     does in winsup/cygwin/pinfo.cc.  */
> +  if (exit_code >= 0xc0000000)
> +    {
> +      gdb_signal sig;
> +      switch (exit_code)
> +	{
> +	case EXCEPTION_ACCESS_VIOLATION:
> +	  sig = GDB_SIGNAL_SEGV;
> +	  break;
> +	case EXCEPTION_ILLEGAL_INSTRUCTION:
> +	  sig = GDB_SIGNAL_ILL;
> +	  break;
> +	case STATUS_NO_MEMORY:
> +	  sig = GDB_SIGNAL_BUS;
> +	  break;
> +	case STATUS_CONTROL_C_EXIT:
> +	  sig = GDB_SIGNAL_INT;
> +	  break;
> +	default:
> +	  /* Cygwin maps any other NTSTATUS to exit 127.  */
> +	  tstatus.set_exited (127);
> +	  return tstatus;
> +	}
> +      tstatus.set_signalled (sig);
> +      return tstatus;
> +    }

This seems to be a subset of what windows_status_to_termsig already
does, or thereabouts.  Did you intentionally used separate and
slightly different code, and if so, why?  Perhaps the reason should be
in the commentary?

> +  /* Note: when GDB attaches to a Cygwin inferior and the inferior is
> +     then killed externally (e.g., taskkill /F with exit code 1), GDB
> +     and Cygwin disagree.  Cygwin's parent waitpid reports WIFEXITED,
> +     code=1; GDB reports SIGHUP (signal 1, no swap below because
> +     started_by_cygwin).  Cygwin's parent distinguishes "pinfo::exit
> +     ran" from "didn't run" via the child's wait pipe and only applies
> +     the swap-undo for the former.  GDB has only dwExitCode and can't
> +     tell.  This can't be solved without Cygwin's help.  OTOH, such an
> +     external termination steps out of Cygwin and arguably falls into
> +     undefined-behavior territory, so it is less important than the
> +     other cases.  */

This should be arguably reported to Cygwin developers, but until they
fix this, I wonder whether assuming that SIGHUP is much more rare than
TASKKILL (or any other way of natively killing a program on Windows),
and handle 1 as an exit code rather than a signal, will be more useful
in practice?

Thanks.

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

  reply	other threads:[~2026-05-26 11:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 19:18 [PATCH v2 00/11] Fix a few Cygwin/MinGW problems Pedro Alves
2026-05-25 19:18 ` [PATCH v2 01/11] Adjust gdb.base/exitsignal.exp for MinGW, trigger fault Pedro Alves
2026-05-25 19:18 ` [PATCH v2 02/11] Adjust gdb.base/exitsignal.exp for MinGW, second-chance SIGSEGV Pedro Alves
2026-05-26 11:18   ` Eli Zaretskii
2026-05-27 12:56     ` Pedro Alves
2026-05-25 19:18 ` [PATCH v2 03/11] Adjust gdb.base/exitsignal.exp for MinGW, separate program names Pedro Alves
2026-05-27 21:59   ` Thiago Jung Bauermann
2026-06-12 14:00     ` Pedro Alves
2026-05-25 19:18 ` [PATCH v2 04/11] gdb.base/exitsignal.exp: Exit with non-zero Pedro Alves
2026-05-25 19:18 ` [PATCH v2 05/11] gdb.base/exitsignal.exp: Test attaching too Pedro Alves
2026-05-25 19:18 ` [PATCH v2 06/11] gdb/testsuite: Add mechanism to compile Windows native programs on Cygwin Pedro Alves
2026-05-25 19:18 ` [PATCH v2 07/11] Windows gdb+gdbserver: Share exit status logic Pedro Alves
2026-05-25 19:18 ` [PATCH v2 08/11] Windows gdb+gdbserver: Decode Cygwin ExitProcess codes Pedro Alves
2026-05-26 11:31   ` Eli Zaretskii [this message]
2026-05-27 13:58     ` Pedro Alves
2026-05-27 14:12       ` Eli Zaretskii
2026-05-27 22:00   ` Thiago Jung Bauermann
2026-05-25 19:18 ` [PATCH v2 09/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, thread IDs Pedro Alves
2026-05-25 19:18 ` [PATCH v2 10/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, no fork Pedro Alves
2026-05-25 19:18 ` [PATCH v2 11/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, "info proc" => "inferior" Pedro Alves

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=86h5nuquew.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