aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/sys/unix/backtrace/tracing
diff options
context:
space:
mode:
Diffstat (limited to 'ctr-std/src/sys/unix/backtrace/tracing')
-rw-r--r--ctr-std/src/sys/unix/backtrace/tracing/backtrace_fn.rs49
-rw-r--r--ctr-std/src/sys/unix/backtrace/tracing/gcc_s.rs109
-rw-r--r--ctr-std/src/sys/unix/backtrace/tracing/mod.rs18
3 files changed, 0 insertions, 176 deletions
diff --git a/ctr-std/src/sys/unix/backtrace/tracing/backtrace_fn.rs b/ctr-std/src/sys/unix/backtrace/tracing/backtrace_fn.rs
deleted file mode 100644
index 6293eeb..0000000
--- a/ctr-std/src/sys/unix/backtrace/tracing/backtrace_fn.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-/// As always - iOS on arm uses SjLj exceptions and
-/// _Unwind_Backtrace is even not available there. Still,
-/// backtraces could be extracted using a backtrace function,
-/// which thanks god is public
-///
-/// As mentioned in a huge comment block in `super::super`, backtrace
-/// doesn't play well with green threads, so while it is extremely nice and
-/// simple to use it should be used only on iOS devices as the only viable
-/// option.
-
-use io;
-use libc;
-use sys::backtrace::BacktraceContext;
-use sys_common::backtrace::Frame;
-
-#[inline(never)] // if we know this is a function call, we can skip it when
- // tracing
-pub fn unwind_backtrace(frames: &mut [Frame])
- -> io::Result<(usize, BacktraceContext)>
-{
- const FRAME_LEN: usize = 100;
- assert!(FRAME_LEN >= frames.len());
- let mut raw_frames = [::ptr::null_mut(); FRAME_LEN];
- let nb_frames = unsafe {
- backtrace(raw_frames.as_mut_ptr(), raw_frames.len() as libc::c_int)
- } as usize;
- for (from, to) in raw_frames.iter().zip(frames.iter_mut()).take(nb_frames) {
- *to = Frame {
- exact_position: *from as *mut u8,
- symbol_addr: *from as *mut u8,
- inline_context: 0,
- };
- }
- Ok((nb_frames as usize, BacktraceContext))
-}
-
-extern {
- fn backtrace(buf: *mut *mut libc::c_void, sz: libc::c_int) -> libc::c_int;
-}
diff --git a/ctr-std/src/sys/unix/backtrace/tracing/gcc_s.rs b/ctr-std/src/sys/unix/backtrace/tracing/gcc_s.rs
deleted file mode 100644
index 6e84156..0000000
--- a/ctr-std/src/sys/unix/backtrace/tracing/gcc_s.rs
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use error::Error;
-use io;
-use libc;
-use sys::backtrace::BacktraceContext;
-use sys_common::backtrace::Frame;
-
-use unwind as uw;
-
-struct Context<'a> {
- idx: usize,
- frames: &'a mut [Frame],
-}
-
-#[derive(Debug)]
-struct UnwindError(uw::_Unwind_Reason_Code);
-
-impl Error for UnwindError {
- fn description(&self) -> &'static str {
- "unexpected return value while unwinding"
- }
-}
-
-impl ::fmt::Display for UnwindError {
- fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
- write!(f, "{}: {:?}", self.description(), self.0)
- }
-}
-
-#[inline(never)] // if we know this is a function call, we can skip it when
- // tracing
-pub fn unwind_backtrace(frames: &mut [Frame])
- -> io::Result<(usize, BacktraceContext)>
-{
- let mut cx = Context {
- idx: 0,
- frames,
- };
- let result_unwind = unsafe {
- uw::_Unwind_Backtrace(trace_fn,
- &mut cx as *mut Context
- as *mut libc::c_void)
- };
- // See libunwind:src/unwind/Backtrace.c for the return values.
- // No, there is no doc.
- match result_unwind {
- // These return codes seem to be benign and need to be ignored for backtraces
- // to show up properly on all tested platforms.
- uw::_URC_END_OF_STACK | uw::_URC_FATAL_PHASE1_ERROR | uw::_URC_FAILURE => {
- Ok((cx.idx, BacktraceContext))
- }
- _ => {
- Err(io::Error::new(io::ErrorKind::Other,
- UnwindError(result_unwind)))
- }
- }
-}
-
-extern fn trace_fn(ctx: *mut uw::_Unwind_Context,
- arg: *mut libc::c_void) -> uw::_Unwind_Reason_Code {
- let cx = unsafe { &mut *(arg as *mut Context) };
- if cx.idx >= cx.frames.len() {
- return uw::_URC_NORMAL_STOP;
- }
-
- let mut ip_before_insn = 0;
- let mut ip = unsafe {
- uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void
- };
- if !ip.is_null() && ip_before_insn == 0 {
- // this is a non-signaling frame, so `ip` refers to the address
- // after the calling instruction. account for that.
- ip = (ip as usize - 1) as *mut _;
- }
-
- // dladdr() on osx gets whiny when we use FindEnclosingFunction, and
- // it appears to work fine without it, so we only use
- // FindEnclosingFunction on non-osx platforms. In doing so, we get a
- // slightly more accurate stack trace in the process.
- //
- // This is often because panic involves the last instruction of a
- // function being "call std::rt::begin_unwind", with no ret
- // instructions after it. This means that the return instruction
- // pointer points *outside* of the calling function, and by
- // unwinding it we go back to the original function.
- let symaddr = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
- ip
- } else {
- unsafe { uw::_Unwind_FindEnclosingFunction(ip) }
- };
-
- cx.frames[cx.idx] = Frame {
- symbol_addr: symaddr as *mut u8,
- exact_position: ip as *mut u8,
- inline_context: 0,
- };
- cx.idx += 1;
-
- uw::_URC_NO_REASON
-}
diff --git a/ctr-std/src/sys/unix/backtrace/tracing/mod.rs b/ctr-std/src/sys/unix/backtrace/tracing/mod.rs
deleted file mode 100644
index c9c8e26..0000000
--- a/ctr-std/src/sys/unix/backtrace/tracing/mod.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-pub use self::imp::*;
-
-#[cfg(not(all(target_os = "ios", target_arch = "arm")))]
-#[path = "gcc_s.rs"]
-mod imp;
-#[cfg(all(target_os = "ios", target_arch = "arm"))]
-#[path = "backtrace_fn.rs"]
-mod imp;