From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH 1/5] Cygwin: Make 'ulimit -c' control writing a coredump
Date: Fri, 26 Jan 2024 12:12:37 +0100 [thread overview]
Message-ID: <ZbOTpaBfEZwAkxcf@calimero.vinschen.de> (raw)
In-Reply-To: <0613f2c3-4e1f-452a-8055-59d34d16c821@dronecode.org.uk>
On Jan 25 20:03, Jon Turney wrote:
> On 25/01/2024 18:21, Corinna Vinschen wrote:
> > On Jan 25 14:50, Jon Turney wrote:
> > > On 24/01/2024 14:39, Corinna Vinschen wrote:
> > > > On Jan 24 13:28, Jon Turney wrote:
> > > > > On 23/01/2024 14:29, Corinna Vinschen wrote:
> > > > > > On Jan 23 14:20, Jon Turney wrote:
> [...]
> > > So this situation with a JIT debugger is even stranger than my emendations
> > > to the documentation say.
> > >
> > > Because we're hitting try_to_debug() in exception::handle(), which has some
> > > code to replay the exception via ExceptionContinueExecution (which I guess
> > > the debugger will catch as a first-chance) (and goes into a mode where it
> > > ignores the next half-million exceptions... no idea what that's about!)
> > >
> > > That's not the same as signal_exit() with a coredumping signal (haven't
> > > checked if those are all generated from exceptions, but seems probable, so
> > > the try_to_debug() there maybe isn't doing anything?), where we're going to
> > > exit thereafter.
> >
> > try_to_debug() is only calling IsDebuggerPresent() as test, and that's
> > nothing but a flag in the PEB which is set by the OS after a debugger
> > attached to the process. So the test is by definition extremely
> > flaky, if the debugger is connecting and disconnecting, as you
> > already pointed out.
> >
> > I'm wondering if we can't define our own way to attach to a process,
> > allowing to "WaitForDebugger" as long as the debugger is a Cygwin
> > debugger. If we define a matching function (along the lines of
> > prctl(2) on Linux), we could change our debuggers, core dumpers
> > and stracers to call this attach function.
> >
> > The idea would be to define some shared mutex object, the inferior
> > waits for and the debugger releases after having attached.
> >
> > Is there really any need to support non-Cygwin debuggers?
>
> idk
>
> I think something like that used to exist a long time ago, see commit
> 8abeff1ead5f3824c70111bc0ff74ff835dafa55
Yeah, just, as was the default at the time, without any trace of a
*rational* why it has been removed. Also, it was too simple anyway.
First, if we want to support WIndows debugger, the inferior has to check
if the debugger is a Cygwin or native debugger. If a native debugger,
just stick to what we have today. Otherwise:
- Create a named mutex with a reproducible name (no need to use
the name as parameter) and immediately grab it.
- Call CreateProcess to start the debugger with CREATE_SUSPENDED
flag.
- Create a HANDLE array with the mutex and the process HANDLE.
- Call ResumeThread on the primary debugger thread.
- Call WFMO with timeout.
Later on, the debugger either fails and exits or it calls
ReleaseMutex after having attached to the process.
- WFMO returns
- If the mutex has triggered, we're being debugged (but check
IsDebuggerPresent() just to be sure)
- If the process has triggered, the debugger exited
- If the timeout triggers... oh well.
> That long predates my involvement with cygwin so I've no idea why that was
> removed.
It doesn't predate mine, but I know just as much as you do.
Maybe the mailing list archives help, but tht's no safe bet.
> > > The practical upshot of this is if the JIT debugger doesn't terminate or fix
> > > the erroring process, we'll just replay the faulting instruction and invoke
> > > the JIT debugger again.
> >
> > Hmm, ok. This signal stuff *is* complicated and I'd be happy
> > if anybody finds out how to fix that...
>
> To be clear, not a problem with "core dumping signals", as the process now
> always end up exiting, one way or another.
>
> It's only a problem when someone has set "CYGWIN=error_start:true" or
> something equally dumb.
Ok.
Corinna
next prev parent reply other threads:[~2024-01-26 11:12 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 [this message]
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 ` [PATCH 4/5] Cygwin: Treat api_fatal() similarly to a core-dumping signal Jon Turney
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=ZbOTpaBfEZwAkxcf@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--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).