public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-patches@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH 4/5] Cygwin: Treat api_fatal() similarly to a core-dumping signal
Date: Fri, 12 Jan 2024 14:09:55 +0000	[thread overview]
Message-ID: <20240112140958.1694-5-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20240112140958.1694-1-jon.turney@dronecode.org.uk>

Provide the same debugging opportunities for api_fatal() as we do for a
core-dumping signal:

1) Break into any attached debugger
2) Start JIT debugger (if configured) (keeping these under DEBUGGING doesn't seem helpful)
3) Write a coredump (if rlim_core > 1MB)
4) Write a stackdump (if that failed, or 0 < rlim_core <= 1MB)
---
 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);
 }
 
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 05ffdc27e..32c64b3d7 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" */
 
+/* As above, but before exiting due to api_fatal */
+extern "C"
+void
+api_fatal_debug ()
+{
+  if (try_to_debug ())
+    return;
+
+  if (cygheap->rlim_core == 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_includes/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 = 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 ();
 
 void ld_preload ();
 void fixup_hooks_after_fork ();
-- 
2.43.0


  parent reply	other threads:[~2024-01-12 14:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12 14:09 [PATCH 0/5] Coredump under 'ulimit -c' control (v2) Jon Turney
2024-01-12 14:09 ` [PATCH 1/5] Cygwin: Make 'ulimit -c' control writing a coredump Jon Turney
2024-01-13 14:20   ` Jon Turney
2024-01-15  9:46     ` Corinna Vinschen
2024-01-15 13:27       ` Jon Turney
2024-01-15 14:28         ` Corinna Vinschen
2024-01-16 13:52           ` Jon Turney
2024-01-16 13:54             ` Corinna Vinschen
2024-01-23 14:20   ` Jon Turney
2024-01-23 14:29     ` Corinna Vinschen
2024-01-24 13:28       ` Jon Turney
2024-01-24 14:39         ` Corinna Vinschen
2024-01-25 14:50           ` Jon Turney
2024-01-25 18:21             ` Corinna Vinschen
2024-01-25 20:03               ` Jon Turney
2024-01-26 11:12                 ` Corinna Vinschen
2024-01-26 11:52                   ` Corinna Vinschen
2024-01-27 15:12                     ` Jon Turney
2024-01-29 11:16                       ` Corinna Vinschen
2024-01-12 14:09 ` [PATCH 2/5] Cygwin: Disable writing core dumps by default Jon Turney
2024-01-12 14:09 ` [PATCH 3/5] Cygwin: Define and use __WCOREFLAG Jon Turney
2024-01-12 14:09 ` Jon Turney [this message]
2024-01-12 14:09 ` [PATCH 5/5] Cygwin: Update documentation for cygwin_stackdump Jon Turney
2024-01-12 18:44   ` Corinna Vinschen
2024-01-13 13:40     ` Jon Turney
2024-01-12 18:41 ` [PATCH 0/5] Coredump under 'ulimit -c' control (v2) Corinna Vinschen

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=20240112140958.1694-5-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-patches@cygwin.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).