From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id 7FACC3858D1E; Wed, 24 Jan 2024 13:19:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FACC3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706102366; bh=KUiifGsV+MJG38z0MidWC8Yp5mrk2RxzO16kzuG8Ybs=; h=From:To:Subject:Date:From; b=CekeU3yiTK9afZqlo19zWHGRHwRyUuYsd8giSI2GOIlMHL02+tv0ChAyvkSrnVL8V iWtFpcYB3/Si0EKu/k/HdQIrQ3qCRmS6l0T81DniLyDsjGk79JOzu0vw3mN4uZ4V9p nE6JnKlL51hGzoOxn60zMFn25cFSXUDutOw0Lazc= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jon Turney To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: Don't terminate via dumper X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/main X-Git-Oldrev: 752489c76e2a3c8f4b658597ff7956466366961c X-Git-Newrev: 15140d6df667a71e660dc9da9ca9071fa3c5dbbd Message-Id: <20240124131926.7FACC3858D1E@sourceware.org> Date: Wed, 24 Jan 2024 13:19:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D15140d6df66= 7a71e660dc9da9ca9071fa3c5dbbd commit 15140d6df667a71e660dc9da9ca9071fa3c5dbbd Author: Jon Turney Date: Tue Jan 16 16:12:51 2024 +0000 Cygwin: Don't terminate via dumper =20 A process which is exiting due to a core dumping signal doesn't propagate the correct exist status after dumping core, because 'dumper' itself forcibly terminates the process. =20 Use 'dumper -n' to avoid killing the dumped process, so we continue to the end of signal_exit(), to exit with the 128+signal exit status. =20 Busy-wait in exec_prepared_command() in an attempt to reliably notice the dumper attaching, so we don't get stuck there. =20 Also: document these important facts for custom uses of error_start. Diff: --- winsup/cygwin/exceptions.cc | 7 +++---- winsup/doc/cygwinenv.xml | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 8b1c5493e..0e1a804ca 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -149,7 +149,7 @@ dumper_init (void) =20 /* Calculate the length of the command, allowing for an appended DWORD P= ID and terminating null */ - int cmd_len =3D 1 + wcslen(dll_dir) + 11 + 2 + 1 + wcslen(global_prognam= e) + 1 + 10 + 1; + int cmd_len =3D 1 + wcslen(dll_dir) + 11 + 5 + 1 + wcslen(global_prognam= e) + 1 + 10 + 1; if (cmd_len > 32767) { /* If this comes to more than the 32,767 characters CreateProcess() = can @@ -163,7 +163,7 @@ dumper_init (void) cp =3D wcpcpy (cp, L"\""); cp =3D wcpcpy (cp, dll_dir); cp =3D wcpcpy (cp, L"\\dumper.exe"); - cp =3D wcpcpy (cp, L"\" "); + cp =3D wcpcpy (cp, L"\" -n "); cp =3D wcpcpy (cp, L"\""); cp =3D wcpcpy (cp, global_progname); wcscat (cp, L"\""); @@ -570,9 +570,8 @@ int exec_prepared_command (PWCHAR command) system_printf ("Failed to start, %E"); else { - SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE); while (!being_debugged ()) - Sleep (1); + Sleep (0); Sleep (2000); } =20 diff --git a/winsup/doc/cygwinenv.xml b/winsup/doc/cygwinenv.xml index d97f2b77d..05672c404 100644 --- a/winsup/doc/cygwinenv.xml +++ b/winsup/doc/cygwinenv.xml @@ -46,6 +46,12 @@ to the command as arguments. Note: This has no effect if a debugger is already attached when the fatal error occurs. + + Note: The command invoked must either (i) attach to the errored process = with + DebugActiveProcess(), or (ii) forcibly terminate the + errored process (with TerminateProcess() or similar= ), as + otherwise the errored process will wait forever for a debugger to attach. + =20