Skip to content

Commit 69ed392

Browse files
authored
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).
2 parents ae20aa7 + a43b76e commit 69ed392

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

core/src/arch.rs

+27
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,30 @@ pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?)
4242
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
4343
/* compiler built-in */
4444
}
45+
46+
/// Compiles to a target-specific software breakpoint instruction or equivalent.
47+
///
48+
/// This will typically abort the program. It may result in a core dump, and/or the system logging
49+
/// debug information. Additional target-specific capabilities may be possible depending on
50+
/// debuggers or other tooling; in particular, a debugger may be able to resume execution.
51+
///
52+
/// If possible, this will produce an instruction sequence that allows a debugger to resume *after*
53+
/// the breakpoint, rather than resuming *at* the breakpoint; however, the exact behavior is
54+
/// target-specific and debugger-specific, and not guaranteed.
55+
///
56+
/// If the target platform does not have any kind of debug breakpoint instruction, this may compile
57+
/// to a trapping instruction (e.g. an undefined instruction) instead, or to some other form of
58+
/// target-specific abort that may or may not support convenient resumption.
59+
///
60+
/// The precise behavior and the precise instruction generated are not guaranteed, except that in
61+
/// normal execution with no debug tooling involved this will not continue executing.
62+
///
63+
/// - On x86 targets, this produces an `int3` instruction.
64+
/// - On aarch64 targets, this produces a `brk #0xf000` instruction.
65+
// When stabilizing this, update the comment on `core::intrinsics::breakpoint`.
66+
#[unstable(feature = "breakpoint", issue = "133724")]
67+
#[inline(always)]
68+
#[cfg(not(bootstrap))]
69+
pub fn breakpoint() {
70+
core::intrinsics::breakpoint();
71+
}

core/src/intrinsics/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,18 @@ pub unsafe fn prefetch_write_instruction<T>(_data: *const T, _locality: i32) {
13811381
#[rustc_intrinsic]
13821382
#[rustc_intrinsic_must_be_overridden]
13831383
#[rustc_nounwind]
1384+
#[cfg(not(bootstrap))]
1385+
pub fn breakpoint() {
1386+
unreachable!()
1387+
}
1388+
1389+
/// Executes a breakpoint trap, for inspection by a debugger.
1390+
///
1391+
/// This intrinsic does not have a stable counterpart.
1392+
#[rustc_intrinsic]
1393+
#[rustc_intrinsic_must_be_overridden]
1394+
#[rustc_nounwind]
1395+
#[cfg(bootstrap)]
13841396
pub unsafe fn breakpoint() {
13851397
unreachable!()
13861398
}

0 commit comments

Comments
 (0)