rust-lang / backtrace-rs

Backtraces in Rust
https://docs.rs/backtrace
Other
537 stars 246 forks source link

add support for illumos systems #416

Closed jclulow closed 3 years ago

jclulow commented 3 years ago

Uses dlinfo(3C) to access the current link map on illumos systems. From there we can construct a list of program headers for each mapping and get the same unwinding information available on other platforms.

jclulow commented 3 years ago

There is a Rust toolchain issue which under some conditions prevents correct unwinding on illumos systems, but I have submitted rust-lang/rust#84254 to correct that. Using a toolchain built with that fix, I am able to get the tests to pass on an illumos system:

$ cargo test
   Compiling dylib-dep v0.1.0 (/ws/safari/backtrace-rs/crates/dylib-dep)
   Compiling backtrace v0.3.56 (/ws/safari/backtrace-rs)
    Finished test [unoptimized + debuginfo] target(s) in 2.10s
     Running unittests (target/debug/deps/backtrace-50b93c93201296af)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/accuracy/main.rs (target/debug/deps/accuracy-b67fe8242b4d4db7)

running 1 test
test doit ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.13s

     Running tests/concurrent-panics.rs (target/debug/deps/concurrent_panics-293a4d3fc65c038f)
test result: ok
     Running tests/long_fn_name.rs (target/debug/deps/long_fn_name-97f42ffa7bdded33)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/skip_inner_frames.rs (target/debug/deps/skip_inner_frames-b4e39140ce62f8ad)

running 2 tests
test backtrace_new_unresolved_should_start_with_call_site_trace ... ok
test backtrace_new_should_start_with_call_site_trace ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/smoke.rs (target/debug/deps/smoke-55c9dbf5ff738143)

running 3 tests
test sp_smoke_test ... ok
test many_threads ... ok
test smoke_test_frames ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.28s

   Doc-tests backtrace

running 6 tests
test src/backtrace/mod.rs - backtrace::trace (line 39) ... ok
test src/symbolize/mod.rs - symbolize::resolve (line 45) ... ok
test src/capture.rs - capture::Backtrace::new (line 128) ... ok
test src/lib.rs - (line 20) ... ok
test src/symbolize/mod.rs - symbolize::resolve_frame (line 89) ... ok
test src/capture.rs - capture::Backtrace::new_unresolved (line 155) ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.86s

I am also able to run all of the examples:

$ for e in backtrace raw; do for f in '' --release; do cargo run $f --example $e; done; done
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/examples/backtrace`
   0: backtrace::main
             at examples/backtrace.rs:4:22
   1: core::ops::function::FnOnce::call_once
             at /ws/rust/library/core/src/ops/function.rs:227:5
   2: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /ws/rust/library/std/src/sys_common/backtrace.rs:125:18
   3: std::rt::lang_start::{{closure}}
             at /ws/rust/library/std/src/rt.rs:66:18
   4: std::rt::lang_start_internal
   5: std::rt::lang_start
             at /ws/rust/library/std/src/rt.rs:65:5
   6: main
   7: _start_crt
   8: _start

    Finished release [optimized] target(s) in 0.02s
     Running `target/release/examples/backtrace`
   0: backtrace::main
   1: std::sys_common::backtrace::__rust_begin_short_backtrace
   2: std::rt::lang_start::{{closure}}
   3: std::rt::lang_start_internal
   4: main
   5: _start_crt
   6: _start

    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/examples/raw`
frame #0  - 0x00000000000067a515 - backtrace::backtrace::libunwind::trace::h897e79eec925edf3
                                 @ /ws/safari/backtrace-rs/src/backtrace/libunwind.rs:90
                                 - backtrace::backtrace::trace_unsynchronized::h606dc662e7578328
                                 @ /ws/safari/backtrace-rs/src/backtrace/mod.rs:66
frame #1  - 0x00000000000067a561 - backtrace::backtrace::trace::hbfa284cca77c011e
                                 @ /ws/safari/backtrace-rs/src/backtrace/mod.rs:53
frame #2  - 0x00000000000067a350 - raw::print::hdbaff1dbca174ec2
                                 @ /ws/safari/backtrace-rs/examples/raw.rs:22
frame #3  - 0x00000000000067a329 - raw::baz::h7f854dc1a927557e
                                 @ /ws/safari/backtrace-rs/examples/raw.rs:12
frame #4  - 0x00000000000067a319 - raw::bar::h420179ee28fe4a36
                                 @ /ws/safari/backtrace-rs/examples/raw.rs:9
frame #5  - 0x00000000000067a309 - raw::foo::ha1d89d4956960e61
                                 @ /ws/safari/backtrace-rs/examples/raw.rs:6
frame #6  - 0x00000000000067a2f9 - raw::main::h6620733050112742
                                 @ /ws/safari/backtrace-rs/examples/raw.rs:2
frame #7  - 0x00000000000067df9e - core::ops::function::FnOnce::call_once::hdbbe226adbd7762f
                                 @ /ws/rust/library/core/src/ops/function.rs:227
frame #8  - 0x00000000000067e391 - std::sys_common::backtrace::__rust_begin_short_backtrace::h36ebdacaf0899339
                                 @ /ws/rust/library/std/src/sys_common/backtrace.rs:125
frame #9  - 0x00000000000067a4c4 - std::rt::lang_start::{{closure}}::hbfe4d29a21797069
                                 @ /ws/rust/library/std/src/rt.rs:66
frame #10 - 0x00000000000083f8a7 - std::rt::lang_start_internal::hf6f9412528033aa6
frame #11 - 0x00000000000067a4a1 - std::rt::lang_start::ha23c0f6074035bb6
                                 @ /ws/rust/library/std/src/rt.rs:65
frame #12 - 0x00000000000067a38b - main
frame #13 - 0x000000000000679637 - _start_crt
frame #14 - 0x000000000000679598 - _start

    Finished release [optimized] target(s) in 0.02s
     Running `target/release/examples/raw`
frame #0  - 0x00000000000053112f - backtrace::backtrace::trace::hf9bee92a8d2cc49b
frame #1  - 0x000000000000530548 - raw::main::h962bc507e8e3909c
frame #2  - 0x0000000000005305ba - std::sys_common::backtrace::__rust_begin_short_backtrace::h7516bb51d68fa788
frame #3  - 0x00000000000053104c - std::rt::lang_start::{{closure}}::h04d0f3d16fa8d83a
frame #4  - 0x0000000000005c2947 - std::rt::lang_start_internal::hf6f9412528033aa6
frame #5  - 0x000000000000530579 - main
frame #6  - 0x00000000000052fbc7 - _start_crt
frame #7  - 0x00000000000052fb28 - _start
alexcrichton commented 3 years ago

Awesome, thanks!