Skip to content

Commit d196947

Browse files
committed
YJIT: Pass panic message to rb_bug()
So that the Rust panic message is forwarded to the RUBY_CRASH_REPORT system, instead of only the static "YJIT panicked" message done so previously. This helps with triaging crashes since it's easier than trying to parse stderr output. Sample: <internal:yjit_hook>:2: [BUG] YJIT: panicked at src/codegen.rs:1197:5: explicit panic ...
1 parent fbe35bc commit d196947

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

yjit/src/yjit.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::stats::YjitExitLocations;
77
use crate::stats::incr_counter;
88
use crate::stats::with_compile_time;
99

10-
use std::os::raw;
10+
use std::os::raw::{c_char, c_int};
1111
use crate::log::Log;
1212

1313
/// Is YJIT on? The interpreter uses this variable to decide whether to trigger
@@ -19,7 +19,7 @@ pub static mut rb_yjit_enabled_p: bool = false;
1919
/// Parse one command-line option.
2020
/// This is called from ruby.c
2121
#[no_mangle]
22-
pub extern "C" fn rb_yjit_parse_option(str_ptr: *const raw::c_char) -> bool {
22+
pub extern "C" fn rb_yjit_parse_option(str_ptr: *const c_char) -> bool {
2323
return parse_option(str_ptr).is_some();
2424
}
2525

@@ -102,7 +102,10 @@ fn rb_bug_panic_hook() {
102102
env::set_var("RUST_BACKTRACE", "1");
103103
previous_hook(panic_info);
104104

105-
unsafe { rb_bug(b"YJIT panicked\0".as_ref().as_ptr() as *const raw::c_char); }
105+
// Abort with rb_bug(). It has a length limit on the message.
106+
let panic_message = &format!("{}", panic_info)[..];
107+
let len = std::cmp::min(0x100, panic_message.len()) as c_int;
108+
unsafe { rb_bug(b"YJIT: %*s\0".as_ref().as_ptr() as *const c_char, len, panic_message.as_ptr()); }
106109
}));
107110
}
108111

0 commit comments

Comments
 (0)