Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cause a debug break when a panic occurs on Windows. #34502

Open
Tracked by #9 ...
retep998 opened this issue Jun 27, 2016 · 11 comments
Open
Tracked by #9 ...

Cause a debug break when a panic occurs on Windows. #34502

retep998 opened this issue Jun 27, 2016 · 11 comments
Labels
C-feature-accepted Category: A feature request that has been accepted pending implementation. O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@retep998
Copy link
Member

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.

@brson
Copy link
Contributor

brson commented Jun 27, 2016

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.

@brson brson added O-windows Operating system: Windows A-libs labels Jun 27, 2016
@Diggsey
Copy link
Contributor

Diggsey commented Jun 27, 2016

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.

@vadimcn
Copy link
Contributor

vadimcn commented Aug 2, 2016

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 of if (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 on rust_panic?

@Diggsey
Copy link
Contributor

Diggsey commented Aug 2, 2016

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_panic only works if you've already got a debugger attached.

@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 25, 2017
@cyplo
Copy link
Contributor

cyplo commented Nov 1, 2017

Would you expect different behaviour for programs compiled in release mode in comparison to those compiled in debug mode with regards to the above ?

@dtolnay dtolnay added C-feature-accepted Category: A feature request that has been accepted pending implementation. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Nov 15, 2017
@dtolnay
Copy link
Member

dtolnay commented Nov 15, 2017

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.

@ArtemGr
Copy link
Contributor

ArtemGr commented Jul 14, 2018

How about using an environment variable, similar to RUST_BACKTRACE, to make this optional?

@steveklabnik
Copy link
Member

Triage; I'm not aware of any movement on this feature.

@AqlaSolutions
Copy link

It seem natural to support Windows JIT Debugger attaching same as in C++, I'm surprised this is not implemented yet.

@yaahc yaahc added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 18, 2022
@nil-ref
Copy link

nil-ref commented Dec 4, 2023

I'm surprised this is not implemented yet.

@ChrisDenton
Copy link
Member

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-accepted Category: A feature request that has been accepted pending implementation. O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests