diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-12-14 16:47:18 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2018-12-24 08:32:57 -0800 |
| commit | 8d500572fa8f4110033fa3bc5e925831f6bbd18e (patch) | |
| tree | c21fb3a40f8f8a4f57879ed39a9ce5ddc1f66fbd /src/libstd/sys_common | |
| parent | 50f3d6eccb85a24a02b7c1daf5e242768dddf3b5 (diff) | |
| download | rust-8d500572fa8f4110033fa3bc5e925831f6bbd18e.tar.gz rust-8d500572fa8f4110033fa3bc5e925831f6bbd18e.zip | |
std: Use backtrace-sys from crates.io
This commit switches the standard library to using the `backtrace-sys` crate from crates.io instead of duplicating the logic here in the Rust repositor with the `backtrace-sys`'s crate's logic. Eventually this will hopefully be a good step towards using the `backtrace` crate directly from crates.io itself, but we're not quite there yet! Hopefully this is a small incremental first step we can take.
Diffstat (limited to 'src/libstd/sys_common')
| -rw-r--r-- | src/libstd/sys_common/backtrace.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys_common/gnu/libbacktrace.rs | 72 |
2 files changed, 29 insertions, 51 deletions
diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index e44113f76f4..08cd7b05e07 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -53,6 +53,14 @@ const MAX_NB_FRAMES: usize = 100; pub fn print(w: &mut dyn Write, format: PrintFormat) -> io::Result<()> { static LOCK: Mutex = Mutex::new(); + // There are issues currently linking libbacktrace into tests, and in + // general during libstd's own unit tests we're not testing this path. In + // test mode immediately return here to optimize away any references to the + // libbacktrace symbols + if cfg!(test) { + return Ok(()) + } + // Use a lock to prevent mixed output in multithreading context. // Some platforms also requires it, like `SymFromAddr` on Windows. unsafe { diff --git a/src/libstd/sys_common/gnu/libbacktrace.rs b/src/libstd/sys_common/gnu/libbacktrace.rs index c2589d477ee..9321242fec8 100644 --- a/src/libstd/sys_common/gnu/libbacktrace.rs +++ b/src/libstd/sys_common/gnu/libbacktrace.rs @@ -9,6 +9,7 @@ // except according to those terms. use libc; +use backtrace_sys::{self, backtrace_state}; use ffi::CStr; use io; @@ -39,11 +40,13 @@ where F: FnMut(&[u8], u32) -> io::Result<()> let mut fileline_win: &mut [FileLine] = &mut fileline_buf; let fileline_addr = &mut fileline_win as *mut &mut [FileLine]; ret = unsafe { - backtrace_pcinfo(state, - frame.exact_position as libc::uintptr_t, - pcinfo_cb, - error_cb, - fileline_addr as *mut libc::c_void) + backtrace_sys::backtrace_pcinfo( + state, + frame.exact_position as libc::uintptr_t, + pcinfo_cb, + error_cb, + fileline_addr as *mut libc::c_void, + ) }; FILELINE_SIZE - fileline_win.len() }; @@ -76,11 +79,13 @@ pub fn resolve_symname<F>(frame: Frame, let mut data: *const libc::c_char = ptr::null(); let data_addr = &mut data as *mut *const libc::c_char; let ret = unsafe { - backtrace_syminfo(state, - frame.symbol_addr as libc::uintptr_t, - syminfo_cb, - error_cb, - data_addr as *mut libc::c_void) + backtrace_sys::backtrace_syminfo( + state, + frame.symbol_addr as libc::uintptr_t, + syminfo_cb, + error_cb, + data_addr as *mut libc::c_void, + ) }; if ret == 0 || data.is_null() { None @@ -94,45 +99,6 @@ pub fn resolve_symname<F>(frame: Frame, } //////////////////////////////////////////////////////////////////////// -// libbacktrace.h API -//////////////////////////////////////////////////////////////////////// -type backtrace_syminfo_callback = -extern "C" fn(data: *mut libc::c_void, - pc: libc::uintptr_t, - symname: *const libc::c_char, - symval: libc::uintptr_t, - symsize: libc::uintptr_t); -type backtrace_full_callback = -extern "C" fn(data: *mut libc::c_void, - pc: libc::uintptr_t, - filename: *const libc::c_char, - lineno: libc::c_int, - function: *const libc::c_char) -> libc::c_int; -type backtrace_error_callback = -extern "C" fn(data: *mut libc::c_void, - msg: *const libc::c_char, - errnum: libc::c_int); -enum backtrace_state {} - -extern { - fn backtrace_create_state(filename: *const libc::c_char, - threaded: libc::c_int, - error: backtrace_error_callback, - data: *mut libc::c_void) - -> *mut backtrace_state; - fn backtrace_syminfo(state: *mut backtrace_state, - addr: libc::uintptr_t, - cb: backtrace_syminfo_callback, - error: backtrace_error_callback, - data: *mut libc::c_void) -> libc::c_int; - fn backtrace_pcinfo(state: *mut backtrace_state, - addr: libc::uintptr_t, - cb: backtrace_full_callback, - error: backtrace_error_callback, - data: *mut libc::c_void) -> libc::c_int; -} - -//////////////////////////////////////////////////////////////////////// // helper callbacks //////////////////////////////////////////////////////////////////////// @@ -210,7 +176,11 @@ unsafe fn init_state() -> *mut backtrace_state { Err(_) => ptr::null(), }; - STATE = backtrace_create_state(filename, 0, error_cb, - ptr::null_mut()); + STATE = backtrace_sys::backtrace_create_state( + filename, + 0, + error_cb, + ptr::null_mut(), + ); STATE } |
