Skip to content

Commit

Permalink
fix: enable trace_thread_unsynchronized only on windows and noop
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 10, 2022
1 parent 68e1927 commit 48a0058
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use core::ffi::c_void;
use core::fmt;

use self::dbghelp::trace_thread;

/// Inspects the current call-stack, passing all active frames into the closure
/// provided to calculate a stack trace.
///
Expand Down Expand Up @@ -79,11 +77,12 @@ pub unsafe fn trace_unsynchronized<F: FnMut(&Frame) -> bool>(mut cb: F) {
/// # Panics
///
/// See information on `trace` for caveats on `cb` panicking.
#[cfg(all(windows, not(target_vendor = "uwp")))]
pub unsafe fn trace_thread_unsynchronized<F: FnMut(&Frame) -> bool>(
thread: *mut c_void,
mut cb: F,
) {
trace_thread(&mut cb, thread)
trace_thread_imp(&mut cb, thread)
}

/// A trait representing one frame of a backtrace, yielded to the `trace`
Expand Down Expand Up @@ -171,12 +170,15 @@ cfg_if::cfg_if! {
} else if #[cfg(all(windows, not(target_vendor = "uwp")))] {
mod dbghelp;
use self::dbghelp::trace as trace_imp;
use self::dbghelp::trace_thread as trace_thread_imp;
pub(crate) use self::dbghelp::Frame as FrameImp;
#[cfg(target_env = "msvc")] // only used in dbghelp symbolize
pub(crate) use self::dbghelp::StackFrame;
} else {
mod noop;
use self::noop::trace as trace_imp;
use self::noop::trace_thread as trace_thread_imp;
use self::noop::trace_thread_unsynchronized;
pub(crate) use self::noop::Frame as FrameImp;
}
}
5 changes: 5 additions & 0 deletions src/backtrace/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use core::ffi::c_void;
#[inline(always)]
pub fn trace(_cb: &mut dyn FnMut(&super::Frame) -> bool) {}

#[inline(always)]
pub fn trace_thread(cb: &mut dyn FnMut(&super::Frame) -> bool, thread: *mut c_void) {}

pub fn trace_thread_unsynchronized<F: FnMut(&Frame) -> bool>(thread: *mut c_void, mut cb: F) {}

#[derive(Clone)]
pub struct Frame;

Expand Down

0 comments on commit 48a0058

Please sign in to comment.