Add libbacktrace support for Apple platforms

This commit is contained in:
John Colanduoni 2017-07-22 23:05:47 -07:00 committed by kennytm
parent f861b6ee46
commit e8121b3d16
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
8 changed files with 1458 additions and 7 deletions

View File

@ -11844,6 +11844,9 @@ elf*) FORMAT_FILE="elf.lo" ;;
pecoff) FORMAT_FILE="pecoff.lo"
backtrace_supports_data=no
;;
macho*) FORMAT_FILE="macho.lo"
backtrace_supports_data=no
;;
*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: could not determine output file type" >&5
$as_echo "$as_me: WARNING: could not determine output file type" >&2;}
FORMAT_FILE="unknown.lo"

View File

@ -231,6 +231,9 @@ elf*) FORMAT_FILE="elf.lo" ;;
pecoff) FORMAT_FILE="pecoff.lo"
backtrace_supports_data=no
;;
macho*) FORMAT_FILE="macho.lo"
backtrace_supports_data=no
;;
*) AC_MSG_WARN([could not determine output file type])
FORMAT_FILE="unknown.lo"
backtrace_supported=no

View File

@ -3,3 +3,9 @@
/\177ELF\002/ { if (NR == 1) { print "elf64"; exit } }
/\114\001/ { if (NR == 1) { print "pecoff"; exit } }
/\144\206/ { if (NR == 1) { print "pecoff"; exit } }
/\xFE\xED\xFA\xCE/ { if (NR == 1) { print "macho32"; exit } }
/\xCE\xFA\xED\xFE/ { if (NR == 1) { print "macho32"; exit } }
/\xFE\xED\xFA\xCF/ { if (NR == 1) { print "macho64"; exit } }
/\xCF\xFA\xED\xFE/ { if (NR == 1) { print "macho64"; exit } }
/\xCA\xFE\xBA\xBE/ { if (NR == 1) { print "macho-fat"; exit } }
/\xBE\xBA\xFE\xCA/ { if (NR == 1) { print "macho-fat"; exit } }

1414
src/libbacktrace/macho.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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);
}

View File

@ -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;

View File

@ -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};
}

View File

@ -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;