Skip to content

Commit 0dc0332

Browse files
committed
move platform specific backtrace into ./platform
Signed-off-by: Christian Jordan <[email protected]>
1 parent d3daf2f commit 0dc0332

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

src/backtrace/mod.rs renamed to src/backtrace.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use libc::c_void;
44
use std::path::PathBuf;
55

6+
pub use crate::platform::TraceImpl;
7+
68
pub trait Symbol: Sized {
79
fn name(&self) -> Option<Vec<u8>>;
810
fn addr(&self) -> Option<*mut c_void>;
@@ -43,25 +45,3 @@ pub trait Trace {
4345
where
4446
Self: Sized;
4547
}
46-
47-
#[cfg(not(all(
48-
any(target_arch = "x86_64", target_arch = "aarch64"),
49-
feature = "frame-pointer"
50-
)))]
51-
mod backtrace_rs;
52-
#[cfg(not(all(
53-
any(target_arch = "x86_64", target_arch = "aarch64"),
54-
feature = "frame-pointer"
55-
)))]
56-
pub use backtrace_rs::Trace as TraceImpl;
57-
58-
#[cfg(all(
59-
any(target_arch = "x86_64", target_arch = "aarch64"),
60-
feature = "frame-pointer"
61-
))]
62-
pub mod frame_pointer;
63-
#[cfg(all(
64-
any(target_arch = "x86_64", target_arch = "aarch64"),
65-
feature = "frame-pointer"
66-
))]
67-
pub use frame_pointer::Trace as TraceImpl;

src/backtrace/backtrace_rs.rs renamed to src/platform/backtrace_rs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
impl super::Frame for backtrace::Frame {
1+
impl crate::backtrace::Frame for backtrace::Frame {
22
type S = backtrace::Symbol;
33

44
fn ip(&self) -> usize {
@@ -16,7 +16,7 @@ impl super::Frame for backtrace::Frame {
1616

1717
pub struct Trace {}
1818

19-
impl super::Trace for Trace {
19+
impl crate::backtrace::Trace for Trace {
2020
type Frame = backtrace::Frame;
2121

2222
fn trace<F: FnMut(&Self::Frame) -> bool>(_: *mut libc::c_void, cb: F) {

src/platform/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,43 @@ mod nix_impl {
33
pub mod addr_validate;
44
pub mod profiler;
55
pub mod timer;
6+
7+
#[cfg(all(
8+
any(target_arch = "x86_64", target_arch = "aarch64"),
9+
feature = "frame-pointer",
10+
))]
11+
mod frame_pointer;
12+
#[cfg(all(
13+
any(target_arch = "x86_64", target_arch = "aarch64"),
14+
feature = "frame-pointer",
15+
))]
16+
pub use frame_pointer::Trace as TraceImpl;
17+
18+
#[cfg(not(all(
19+
any(target_arch = "x86_64", target_arch = "aarch64"),
20+
feature = "frame-pointer",
21+
)))]
22+
#[path = "../backtrace_rs.rs"]
23+
mod backtrace_rs;
24+
#[cfg(not(all(
25+
any(target_arch = "x86_64", target_arch = "aarch64"),
26+
feature = "frame-pointer",
27+
)))]
28+
pub use backtrace_rs::Trace as TraceImpl;
629
}
730

831
#[cfg(target_os = "windows")]
932
mod windows_impl {
1033
pub mod addr_validate;
1134
pub mod profiler;
1235
pub mod timer;
36+
37+
#[cfg(feature = "frame-pointer")]
38+
std::compile_error!("frame-pointer feature is currently not supported on windows.");
39+
40+
#[path = "../backtrace_rs.rs"]
41+
mod backtrace_rs;
42+
pub use backtrace_rs::Trace as TraceImpl;
1343
}
1444

1545
#[cfg(any(target_os = "linux", target_os = "macos"))]

src/backtrace/frame_pointer.rs renamed to src/platform/nix_impl/frame_pointer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ptr::null_mut;
44

55
use libc::c_void;
66

7-
use crate::addr_validate::validate;
7+
use crate::validate;
88

99
#[derive(Clone, Debug)]
1010
pub struct Frame {
@@ -16,7 +16,7 @@ extern "C" {
1616

1717
}
1818

19-
impl super::Frame for Frame {
19+
impl crate::backtrace::Frame for Frame {
2020
type S = backtrace::Symbol;
2121

2222
fn ip(&self) -> usize {
@@ -37,7 +37,7 @@ impl super::Frame for Frame {
3737
}
3838

3939
pub struct Trace {}
40-
impl super::Trace for Trace {
40+
impl crate::backtrace::Trace for Trace {
4141
type Frame = Frame;
4242

4343
fn trace<F: FnMut(&Self::Frame) -> bool>(ucontext: *mut libc::c_void, mut cb: F) {

0 commit comments

Comments
 (0)