-
Notifications
You must be signed in to change notification settings - Fork 19
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
ACP: core::arch::breakpoint
#491
Comments
what happens if an ISA doesn't have a breakpoint instruction? (e.g. wasm iirc) |
I'm concerned about portability: this works on x86 because, after handling an |
@Amanieu wrote:
This is entirely the problem of the debugger to deal with; it doesn't make the Rust program non-portable. (Also, I've recently learned that one standard workaround for that in x86 is to use |
@programmerjake wrote:
WebAssembly appears to implement the LLVM More generally: I would expect that there's always some way to trap, or failing that to abort, and that worst case it'll map to whatever |
@joshtriplett I think you misunderstand, if you try to continue after a breakpoint instruction:
Given that this only produces the expected behavior on x86, I don't think we can reasonably expose this as a platform-independent intrinsic. |
I understood that; my point is, dealing with that kind of variation is the job of a debugger. Some debuggers do recognize, for instance, the specific aarch64 brk produced by LLVM's
LLVM and C++ both have a platform-independent intrinsic for this. The platform-independent behavior is "this will trap, stopping execution; it may result in a core dump; a debugger may treat this as a breakpoint". |
From my experiments in the Unbug crate running in VSCode I've noticed that |
ok, I had assumed
Yeah I assumed the desired semantics were that a debugger would always be able to continue after hitting the breakpoint, however lowering it to an abort-like thing means that isn't really possible. |
The desired semantics are that it traps, in a target-specific way, which might dump core and might be possible to continue if you have a debugger attached, but the details will be target-specific and debugger-specific. |
You can achieve this in a portable way (at least UNIX) and which works with resuming execution in the debugger by calling |
@Amanieu That's not portable, though, and you can't do it using exclusively |
Accepted pending to documentation changes that were discussed in the meeting. |
I've updated the documentation. |
Approved in [ACP 491](rust-lang/libs-team#491).
Approved in [ACP 491](rust-lang/libs-team#491).
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites.
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites.
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Approved in [ACP 491](rust-lang/libs-team#491). Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a safe intrinsic to call and has no prerequisites. (Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)` logic.)
Add `core::arch::breakpoint` and test Approved in [ACP 491](rust-lang/libs-team#491).
Add `core::arch::breakpoint` and test Approved in [ACP 491](rust-lang/libs-team#491).
Rollup merge of rust-lang#133726 - joshtriplett:breakpoint, r=oli-obk Add `core::arch::breakpoint` and test Approved in [ACP 491](rust-lang/libs-team#491).
Add `core::arch::breakpoint` and test Approved in [ACP 491](rust-lang/libs-team#491).
Proposal
Problem statement
Sometimes, for debugging, users want to have a software breakpoint instruction to use with their debugger, or to generate a core dump for subsequent analysis.
core::intrinsics::breakpoint()
exists, but intrinsics are perma-unstable.Users can manually emit a breakpoint instruction using inline assembly, such as
core::arch::asm!("int3")
on x86, orcore::arch::asm!("brk #0xf000")
on ARM. However, this isn't portable.Solution sketch
In
core::arch
:Note that this should not be noreturn (
-> !
), because on some targets and environments, the user may be able to continue execution from the breakpoint in a debugger.Links and related work
The unbug crate provides macros that emit breakpoints (e.g. for assertions), but it depends on nightly Rust.
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: