Cause a debug break when a panic occurs on Windows.
In order to aid debugging it would be really useful if Rust would trigger a debug break whenever a panic occurs on Windows. Ideally using the __debugbreak intrinsic which is equivalent to int 3 on x86 platforms.
Why just on windows?
There used to be an instruction on the panic path that triggered the debugger on Unix at least. I recall it could be annoying.
Brian Anderson at 2016-06-27 20:13:11
When debugging C++ programs on windows, any uncaught exceptions will trigger the just-in-time debugger. The program will pause before unwinding if the exception would have been uncaught, and you're able to enter a debugging session as though the exception has not yet happened (such that the next instruction would cause the exception).
It would be really nice if the same experience was possible with rust.
Diggory Blake at 2016-06-27 20:38:39
In order to aid debugging it would be really useful if Rust would trigger a debug break whenever a panic occurs on Windows.
But in that case programs won't be able to unwind from panic without dropping into debugger. When debugger is not attached,
int 3crashes the program. You might be thinking ofif (IsDebuggerPresent()) DebugBreak();sort of thing, but even that is annoying, IMO, because the debugger will always do a breakpoint stop, even if you were debugging something else. What's wrong with setting a breakpoint onrust_panic?vadimcn at 2016-08-02 15:53:07
Having looked into it a little, I think the best option would be to remove the top-level exception handler which rustc installs, when compiling for windows.
When a panic is uncaught, it should then automatically trigger the windows JIT debugging feature, or if running in a debugger, it would break into the debugger. Setting a breakpoint on
rust_paniconly works if you've already got a debugger attached.Diggory Blake at 2016-08-02 17:43:48
Would you expect different behaviour for programs compiled in release mode in comparison to those compiled in debug mode with regards to the above ?
Cyryl Płotnicki at 2017-11-01 14:13:46
Seems reasonable. I would like to see an implementation of this in a PR, along with a brief writeup of how this improves the debugging experience and how it impacts non-debug use cases, and I think the libs team will be able to arrive at a discussion in the PR.
David Tolnay at 2017-11-15 03:58:27
How about using an environment variable, similar to
RUST_BACKTRACE, to make this optional?Artem at 2018-07-14 11:05:29
Triage; I'm not aware of any movement on this feature.
Steve Klabnik at 2019-10-17 12:54:51
It seem natural to support Windows JIT Debugger attaching same as in C++, I'm surprised this is not implemented yet.
Vlad Dev at 2020-08-18 11:30:59
I'm surprised this is not implemented yet.
nil-ref at 2023-12-04 08:36:32
This was attempted then reverted due to how invasive it is. It is not necessarily the case that every panic should break into the debugger (which is especially bad for projects that use
catch_unwind). And in any case debuggers can already be configured to break even on handled exceptions.Having looked into it a little, I think the best option would be to remove the top-level exception handler which rustc installs, when compiling for windows.
Yes, this would be the better approach imho. Then we would get the C/C++ behaviour "for free".
Chris Denton at 2024-10-18 09:19:18