From 7169fe57d66dedad21f2dcf4c615feb9ab7d3f5a Mon Sep 17 00:00:00 2001 From: kennytm Date: Sat, 2 Sep 2017 02:09:39 +0800 Subject: [PATCH] Fallback to dladdr-based resolve_symbol if backtrace failed. This programs compiled without -g on macOS still provide the resolve to actual symbols, instead of `` everywhere. --- .../sys/unix/backtrace/printing/dladdr.rs | 8 ----- src/libstd/sys/unix/backtrace/printing/mod.rs | 35 +++++++++++++++---- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/libstd/sys/unix/backtrace/printing/dladdr.rs b/src/libstd/sys/unix/backtrace/printing/dladdr.rs index 05a071a797838..3a3912af021ce 100644 --- a/src/libstd/sys/unix/backtrace/printing/dladdr.rs +++ b/src/libstd/sys/unix/backtrace/printing/dladdr.rs @@ -31,14 +31,6 @@ pub fn resolve_symname(frame: Frame, } } -pub fn foreach_symbol_fileline(_symbol_addr: Frame, - _f: F, - _: &BacktraceContext) -> io::Result - where F: FnMut(&[u8], libc::c_int) -> io::Result<()> -{ - Ok(false) -} - #[repr(C)] struct Dl_info { dli_fname: *const libc::c_char, diff --git a/src/libstd/sys/unix/backtrace/printing/mod.rs b/src/libstd/sys/unix/backtrace/printing/mod.rs index 857900e1e554d..8bd2d9eccd82a 100644 --- a/src/libstd/sys/unix/backtrace/printing/mod.rs +++ b/src/libstd/sys/unix/backtrace/printing/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2017 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,13 +8,36 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub use self::imp::{foreach_symbol_fileline, resolve_symname}; +mod dladdr; + +use sys::backtrace::BacktraceContext; +use sys_common::backtrace::Frame; +use io; + +#[cfg(target_os = "emscripten")] +pub use self::dladdr::resolve_symname; #[cfg(target_os = "emscripten")] -#[path = "dladdr.rs"] -mod imp; +pub fn foreach_symbol_fileline(_: Frame, _: F, _: &BacktraceContext) -> io::Result +where + F: FnMut(&[u8], ::libc::c_int) -> io::Result<()> +{ + Ok(false) +} + +#[cfg(not(target_os = "emscripten"))] +pub use sys_common::gnu::libbacktrace::foreach_symbol_fileline; #[cfg(not(target_os = "emscripten"))] -mod imp { - pub use sys_common::gnu::libbacktrace::{foreach_symbol_fileline, resolve_symname}; +pub fn resolve_symname(frame: Frame, callback: F, bc: &BacktraceContext) -> io::Result<()> +where + F: FnOnce(Option<&str>) -> io::Result<()> +{ + ::sys_common::gnu::libbacktrace::resolve_symname(frame, |symname| { + if symname.is_some() { + callback(symname) + } else { + dladdr::resolve_symname(frame, callback, bc) + } + }, bc) }