about summary refs log tree commit diff
path: root/src/libstd/sys/unix
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-09-02 02:09:39 +0800
committerkennytm <kennytm@gmail.com>2017-09-02 03:24:17 +0800
commit7169fe57d66dedad21f2dcf4c615feb9ab7d3f5a (patch)
treefd4ba028cbbe25c3909c6af82cdc9b03ef005c65 /src/libstd/sys/unix
parent09f572b7dccb65ba148d42070f65663c947f93a3 (diff)
downloadrust-7169fe57d66dedad21f2dcf4c615feb9ab7d3f5a.tar.gz
rust-7169fe57d66dedad21f2dcf4c615feb9ab7d3f5a.zip
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 `<unknown>` everywhere.
Diffstat (limited to 'src/libstd/sys/unix')
-rw-r--r--src/libstd/sys/unix/backtrace/printing/dladdr.rs8
-rw-r--r--src/libstd/sys/unix/backtrace/printing/mod.rs35
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 05a071a7978..3a3912af021 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<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,
diff --git a/src/libstd/sys/unix/backtrace/printing/mod.rs b/src/libstd/sys/unix/backtrace/printing/mod.rs
index 857900e1e55..8bd2d9eccd8 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<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)
 }