Skip to content

Commit

Permalink
Fallback to dladdr-based resolve_symbol if backtrace failed.
Browse files Browse the repository at this point in the history
This programs compiled without -g on macOS still provide the resolve to
actual symbols, instead of `<unknown>` everywhere.
  • Loading branch information
kennytm committed Sep 1, 2017
1 parent 09f572b commit 7169fe5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/libstd/sys/unix/backtrace/printing/dladdr.rs
Expand Up @@ -31,14 +31,6 @@ pub fn resolve_symname<F>(frame: Frame,
}
}

pub fn foreach_symbol_fileline<F>(_symbol_addr: Frame,
_f: F,
_: &BacktraceContext) -> io::Result<bool>
where F: FnMut(&[u8], libc::c_int) -> io::Result<()>
{
Ok(false)
}

#[repr(C)]
struct Dl_info {
dli_fname: *const libc::c_char,
Expand Down
35 changes: 29 additions & 6 deletions 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.
//
Expand All @@ -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<F>(_: Frame, _: F, _: &BacktraceContext) -> io::Result<bool>
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<F>(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)
}

0 comments on commit 7169fe5

Please sign in to comment.