diff options
| author | John Colanduoni <john@colanduoni.com> | 2017-07-22 23:05:47 -0700 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2017-09-02 03:24:15 +0800 |
| commit | e8121b3d163f90a8f1cefca07352d3780eed933d (patch) | |
| tree | 5d3cef5f0030de9f4f04619d081facbbad6c3290 /src/libstd | |
| parent | f861b6ee46465097eec266c160ac53e230df7cf0 (diff) | |
| download | rust-e8121b3d163f90a8f1cefca07352d3780eed933d.tar.gz rust-e8121b3d163f90a8f1cefca07352d3780eed933d.zip | |
Add libbacktrace support for Apple platforms
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/build.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/backtrace/mod.rs | 29 | ||||
| -rw-r--r-- | src/libstd/sys/unix/backtrace/printing/mod.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys_common/mod.rs | 2 |
4 files changed, 32 insertions, 7 deletions
diff --git a/src/libstd/build.rs b/src/libstd/build.rs index f57dec98b79..ebd0db2edd0 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -20,7 +20,7 @@ use build_helper::{run, native_lib_boilerplate}; fn main() { let target = env::var("TARGET").expect("TARGET was not set"); let host = env::var("HOST").expect("HOST was not set"); - if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") && + if cfg!(feature = "backtrace") && !target.contains("msvc") && !target.contains("emscripten") && !target.contains("fuchsia") { let _ = build_libbacktrace(&host, &target); } diff --git a/src/libstd/sys/unix/backtrace/mod.rs b/src/libstd/sys/unix/backtrace/mod.rs index bf52da2ed4a..5bb34fe60cc 100644 --- a/src/libstd/sys/unix/backtrace/mod.rs +++ b/src/libstd/sys/unix/backtrace/mod.rs @@ -91,15 +91,42 @@ mod tracing; // symbol resolvers: mod printing; -#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] pub mod gnu { use io; use fs; use libc::c_char; + #[cfg(not(any(target_os = "macos", target_os = "ios")))] pub fn get_executable_filename() -> io::Result<(Vec<c_char>, fs::File)> { Err(io::Error::new(io::ErrorKind::Other, "Not implemented")) } + + #[cfg(any(target_os = "macos", target_os = "ios"))] + pub fn get_executable_filename() -> io::Result<(Vec<c_char>, fs::File)> { + use ptr; + use slice; + use ffi::OsStr; + use os::unix::ffi::OsStrExt; + use libc::c_int; + + extern { + fn _NSGetExecutablePath(buf: *mut c_char, + bufsize: *mut u32) -> c_int; + } + unsafe { + let mut bufsize: u32 = 0; + _NSGetExecutablePath(ptr::null_mut(), &mut bufsize); + if bufsize == 0 { return Err(io::Error::last_os_error()); } + let mut buffer: Vec<c_char> = Vec::with_capacity(bufsize as usize); + let ret = _NSGetExecutablePath(buffer.as_mut_ptr(), &mut bufsize); + if ret != 0 { return Err(io::Error::last_os_error()); } + buffer.set_len(bufsize as usize); + let file = fs::File::open(OsStr::from_bytes( + slice::from_raw_parts(buffer.as_ptr() as *const u8, buffer.len()-1)))?; + Ok((buffer, file)) + } + } } pub struct BacktraceContext; diff --git a/src/libstd/sys/unix/backtrace/printing/mod.rs b/src/libstd/sys/unix/backtrace/printing/mod.rs index 1ae82e01100..857900e1e55 100644 --- a/src/libstd/sys/unix/backtrace/printing/mod.rs +++ b/src/libstd/sys/unix/backtrace/printing/mod.rs @@ -10,13 +10,11 @@ pub use self::imp::{foreach_symbol_fileline, resolve_symname}; -#[cfg(any(target_os = "macos", target_os = "ios", - target_os = "emscripten"))] +#[cfg(target_os = "emscripten")] #[path = "dladdr.rs"] mod imp; -#[cfg(not(any(target_os = "macos", target_os = "ios", - target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] mod imp { pub use sys_common::gnu::libbacktrace::{foreach_symbol_fileline, resolve_symname}; } diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs index ccd4b91a7b7..30241819bd5 100644 --- a/src/libstd/sys_common/mod.rs +++ b/src/libstd/sys_common/mod.rs @@ -51,7 +51,7 @@ pub use sys::net; pub mod net; #[cfg(feature = "backtrace")] -#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))), +#[cfg(any(all(unix, not(target_os = "emscripten")), all(windows, target_env = "gnu"), target_os = "redox"))] pub mod gnu; |
