From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2201) id CEA0C3858018; Tue, 16 Jan 2024 14:11:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEA0C3858018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1705414315; bh=sNoqOaUO8g8IwbO6I1iLlUO2vkqN6HocuH9BWGPS0Ns=; h=From:To:Subject:Date:From; b=VuCqddfZlbRO+04uh4kgc8lrYTgT2xDKo+1ZRDPdcB+jBv5GL+BskuMlIh4q3STTw nfY7IVX4X5CK1wRvIcJFTNn89hREyjARQNyEyJ9Qfg++SxJz+p4vDgVccXIkvHInIY +olPTGROJKEuQRrAohFDgHT5uTOEFPHg/HNH0IWE= 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: Treat api_fatal() similarly to a core-dumping signal X-Act-Checkin: newlib-cygwin X-Git-Author: Jon Turney X-Git-Refname: refs/heads/main X-Git-Oldrev: a83b93e662b0e65fd181ed50de7e960b311f4a94 X-Git-Newrev: aa8224826cb4d7d436757688e8cb3fb760f1aabc Message-Id: <20240116141155.CEA0C3858018@sourceware.org> Date: Tue, 16 Jan 2024 14:11:54 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Daa8224826cb= 4d7d436757688e8cb3fb760f1aabc commit aa8224826cb4d7d436757688e8cb3fb760f1aabc Author: Jon Turney Date: Thu Jan 11 21:34:27 2024 +0000 Cygwin: Treat api_fatal() similarly to a core-dumping signal =20 Provide the same debugging opportunities for api_fatal() as we do for a core-dumping signal: =20 1) Break into any attached debugger 2) Start JIT debugger (if configured) (keeping these under DEBUGGING do= esn't seem helpful) 3) Write a coredump (if rlim_core > 1MB) 4) Write a stackdump (if that failed, or 0 < rlim_core <=3D 1MB) Diff: --- winsup/cygwin/dcrt0.cc | 6 +----- winsup/cygwin/exceptions.cc | 18 ++++++++++++++++++ winsup/cygwin/local_includes/winsup.h | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 130d652aa..17c9be731 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -1250,11 +1250,7 @@ vapi_fatal (const char *fmt, va_list ap) __small_vsprintf (buf + n, fmt, ap); va_end (ap); strace.prntf (_STRACE_SYSTEM, NULL, "%s", buf); - -#ifdef DEBUGGING - try_to_debug (); -#endif - cygwin_stackdump (); + api_fatal_debug(); myself.exit (__api_fatal_exit_val); } =20 diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 362ad69a5..8b1c5493e 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -1396,6 +1396,24 @@ signal_exit (int sig, siginfo_t *si, void *) } } /* extern "C" */ =20 +/* As above, but before exiting due to api_fatal */ +extern "C" +void +api_fatal_debug () +{ + if (try_to_debug ()) + return; + + if (cygheap->rlim_core =3D=3D 0Ul) + return; + + if (cygheap->rlim_core > 1024*1024) + if (exec_prepared_command (dumper_command)) + return; + + cygwin_stackdump(); +} + /* Attempt to carefully handle SIGCONT when we are stopped. */ void _cygtls::handle_SIGCONT () diff --git a/winsup/cygwin/local_includes/winsup.h b/winsup/cygwin/local_in= cludes/winsup.h index 76957618b..38313962d 100644 --- a/winsup/cygwin/local_includes/winsup.h +++ b/winsup/cygwin/local_includes/winsup.h @@ -181,6 +181,7 @@ void close_all_files (bool =3D false); extern "C" void error_start_init (const char*); extern "C" void dumper_init (void); extern "C" int try_to_debug (); +extern "C" void api_fatal_debug (); =20 void ld_preload (); void fixup_hooks_after_fork ();