about summary refs log tree commit diff
path: root/src/libstd/sys/common/backtrace.rs
diff options
context:
space:
mode:
authorDiggory Blake <diggsey@googlemail.com>2015-08-26 01:44:55 +0100
committerDiggory Blake <diggsey@googlemail.com>2015-09-04 01:25:15 +0100
commitd4fc3ec208186f0a9de8d05a6802c95b07e058fd (patch)
tree6a5f95c3d8cfb20e65f08b3d67036a966308fffe /src/libstd/sys/common/backtrace.rs
parentac12c7f1ed7de4fb564ae637f55199eb553e5126 (diff)
Add line numbers to windows-gnu backtraces
Fix formatting
Remove unused imports
Refactor
Fix msvc build
Fix line lengths
Formatting
Enable backtrace tests
Fix using directive on mac
pwd info
Work-around buildbot PWD bug, and fix libbacktrace configuration
Use alternative to `env -u` which is not supported on bitrig
Disable tests on 32-bit windows gnu
Diffstat (limited to 'src/libstd/sys/common/backtrace.rs')
-rw-r--r--src/libstd/sys/common/backtrace.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs
index 7f56afc9e1f..7845714e7f6 100644
--- a/src/libstd/sys/common/backtrace.rs
+++ b/src/libstd/sys/common/backtrace.rs
@@ -8,9 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use io::prelude::*;
-
 use io;
+use io::prelude::*;
+use str;
+use libc;
 
 #[cfg(target_pointer_width = "64")]
 pub const HEX_WIDTH: usize = 18;
@@ -18,6 +19,31 @@ pub const HEX_WIDTH: usize = 18;
 #[cfg(target_pointer_width = "32")]
 pub const HEX_WIDTH: usize = 10;
 
+
+// These output functions should now be used everywhere to ensure consistency.
+pub fn output(w: &mut Write, idx: isize, addr: *mut libc::c_void,
+              s: Option<&[u8]>) -> io::Result<()> {
+    try!(write!(w, "  {:2}: {:2$?} - ", idx, addr, HEX_WIDTH));
+    match s.and_then(|s| str::from_utf8(s).ok()) {
+        Some(string) => try!(demangle(w, string)),
+        None => try!(write!(w, "<unknown>")),
+    }
+    w.write_all(&['\n' as u8])
+}
+
+#[allow(dead_code)]
+pub fn output_fileline(w: &mut Write, file: &[u8], line: libc::c_int,
+                       more: bool) -> io::Result<()> {
+    let file = str::from_utf8(file).unwrap_or("<unknown>");
+    // prior line: "  ##: {:2$} - func"
+    try!(write!(w, "      {:3$}at {}:{}", "", file, line, HEX_WIDTH));
+    if more {
+        try!(write!(w, " <... and possibly more>"));
+    }
+    w.write_all(&['\n' as u8])
+}
+
+
 // All rust symbols are in theory lists of "::"-separated identifiers. Some
 // assemblers, however, can't handle these characters in symbol names. To get
 // around this, we use C++-style mangling. The mangling method is: