Skip to content

Commit 0a0e366

Browse files
committed
Auto merge of #1733 - Smittyvb:breakpoint-intrinsic, r=RalfJung
Support breakpoint intrinsic The `breakpoint` intrinsic raises a `SIGTRAP` signal. If a debugger is attached to a normal program, then `SIGTRAP` can be used to trigger breakpoints in debuggers like `gdb`. If there is no debugger, then the program exits with a message like `Trace/breakpoint trap (core dumped)`. This adds support for the intrinsic in Miri. While actually passing through the `SIGTRAP` doesn't make sense in a Miri context (if it just raised the signal normally then it would allow for debugging Miri itself, not the program being evaluated). As such, it just raises an error.
2 parents d6d0109 + 8d43d72 commit 0a0e366

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/shims/intrinsics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
654654

655655
"try" => return this.handle_try(args, dest, ret),
656656

657+
"breakpoint" => {
658+
let &[] = check_arg_count(args)?;
659+
// normally this would raise a SIGTRAP, which aborts if no debugger is connected
660+
throw_machine_stop!(TerminationInfo::Abort("Trace/breakpoint trap".to_string()))
661+
}
662+
657663
name => throw_unsup_format!("unimplemented intrinsic: {}", name),
658664
}
659665

tests/compile-fail/breakpoint.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(core_intrinsics)]
2+
3+
fn main() {
4+
unsafe {
5+
core::intrinsics::breakpoint() //~ ERROR Trace/breakpoint trap
6+
};
7+
}

0 commit comments

Comments
 (0)