Only generate backtraces with RUST_BACKTRACE set (closes #7) #27

Merged
merged 1 commit into from Aug 11, 2016

Conversation

Projects
None yet
3 participants
@birkenfeld
Contributor

birkenfeld commented Aug 6, 2016

No description provided.

src/lib.rs
-//! propagates it down the stack through `From` and `ChainErr`
-//! conversions.
+//! * If `RUST_BACKTRACE` is enabled, it collects a single backtrace at
+//! the earliest opportunity andpropagates it down the stack through

This comment has been minimized.

@cramertj

cramertj Aug 6, 2016

Contributor

Typo: "and propagates"

@cramertj

cramertj Aug 6, 2016

Contributor

Typo: "and propagates"

This comment has been minimized.

@birkenfeld

birkenfeld Aug 7, 2016

Contributor

Thanks!

@birkenfeld

birkenfeld Aug 7, 2016

Contributor

Thanks!

src/lib.rs
+ _ => None
+ }
+ };
+}

This comment has been minimized.

@brson

brson Aug 7, 2016

Contributor

Does this need to be a macro? Couldn't it also be a public function accessed with $crate::?

@brson

brson Aug 7, 2016

Contributor

Does this need to be a macro? Couldn't it also be a public function accessed with $crate::?

This comment has been minimized.

@birkenfeld

birkenfeld Aug 7, 2016

Contributor

I wanted to avoid an unrelated additional frame in the backtrace. However, since (at least for me) there are already 3 such frames I guess it's not particularly problematic - I'll make it into a function.

@birkenfeld

birkenfeld Aug 7, 2016

Contributor

I wanted to avoid an unrelated additional frame in the backtrace. However, since (at least for me) there are already 3 such frames I guess it's not particularly problematic - I'll make it into a function.

@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Aug 9, 2016

Contributor

@birkenfeld #[inline(always)] should fix the extra stack frame if you still want to do that.

Contributor

brson commented Aug 9, 2016

@birkenfeld #[inline(always)] should fix the extra stack frame if you still want to do that.

@birkenfeld

This comment has been minimized.

Show comment
Hide comment
@birkenfeld

birkenfeld Aug 9, 2016

Contributor

I thought so as well, but in debug mode it does not:

   0:     0x55615e0787c0 - backtrace::backtrace::libunwind::trace
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/libunwind.rs:54
                         - backtrace::backtrace::trace<closure>
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:70
   1:     0x55615e07913a - backtrace::capture::{{impl}}::new
                        at /home/gbr/devel/ext/error-chain/target/debug/build/backtrace-3bc1ff360ebb00cb/out/capture.rs:79
   2:     0x55615e070642 - {{inlined-root}}::make_backtrace
                        at /home/gbr/devel/ext/error-chain/src/lib.rs:685
                         - tests::has_backtrace_depending_on_env::{{impl}}::from
                        at /home/gbr/devel/ext/error-chain/<error_chain macros>:42
   3:     0x55615e0702e8 - tests::has_backtrace_depending_on_env
                        at /home/gbr/devel/ext/error-chain/tests/tests.rs:155
   4:     0x55615e08c6c6 - _<F as alloc..boxed..FnBox<A>>::call_box::h6c46b1f51a5f97cd
   5:     0x55615e0819eb - std::panicking::try::call::h8d6a00e6c0ac8b9e
   6:     0x55615e0cb0c6 - __rust_maybe_catch_panic
   7:     0x55615e08bf6c - _<F as alloc..boxed..FnBox<A>>::call_box::h173484225f9723d2
   8:     0x55615e0c12f7 - std::sys::thread::Thread::new::thread_start::h8f3bd45211e9f5ea
   9:     0x7fc160624423 - <unknown>
  10:     0x7fc160154ecc - clone
  11:                0x0 - <unknown>

Note the {{inlined-root}}::make_backtrace in there. Without inline(always):


   0:     0x55a6b9ade3a0 - backtrace::backtrace::libunwind::trace
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/libunwind.rs:54
                         - backtrace::backtrace::trace<closure>
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:70
   1:     0x55a6b9aded1a - backtrace::capture::{{impl}}::new
                        at /home/gbr/devel/ext/error-chain/target/debug/build/backtrace-3bc1ff360ebb00cb/out/capture.rs:79
   2:     0x55a6b9ad8c12 - error_chain::make_backtrace
                        at /home/gbr/devel/ext/error-chain/src/lib.rs:685
   3:     0x55a6b9ad52bf - tests::has_backtrace_depending_on_env::{{impl}}::from
                        at /home/gbr/devel/ext/error-chain/<error_chain macros>:42
   4:     0x55a6b9ad5038 - tests::has_backtrace_depending_on_env
                        at /home/gbr/devel/ext/error-chain/tests/tests.rs:155
   5:     0x55a6b9af22a6 - _<F as alloc..boxed..FnBox<A>>::call_box::h6c46b1f51a5f97cd
   6:     0x55a6b9ae75cb - std::panicking::try::call::h8d6a00e6c0ac8b9e
   7:     0x55a6b9b30ca6 - __rust_maybe_catch_panic
   8:     0x55a6b9af1b4c - _<F as alloc..boxed..FnBox<A>>::call_box::h173484225f9723d2
   9:     0x55a6b9b26ed7 - std::sys::thread::Thread::new::thread_start::h8f3bd45211e9f5ea
  10:     0x7f8a425b6423 - <unknown>
  11:     0x7f8a420e6ecc - clone
  12:                0x0 - <unknown>

In light of that, I think it's better to read with the explicit frame in there.

Contributor

birkenfeld commented Aug 9, 2016

I thought so as well, but in debug mode it does not:

   0:     0x55615e0787c0 - backtrace::backtrace::libunwind::trace
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/libunwind.rs:54
                         - backtrace::backtrace::trace<closure>
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:70
   1:     0x55615e07913a - backtrace::capture::{{impl}}::new
                        at /home/gbr/devel/ext/error-chain/target/debug/build/backtrace-3bc1ff360ebb00cb/out/capture.rs:79
   2:     0x55615e070642 - {{inlined-root}}::make_backtrace
                        at /home/gbr/devel/ext/error-chain/src/lib.rs:685
                         - tests::has_backtrace_depending_on_env::{{impl}}::from
                        at /home/gbr/devel/ext/error-chain/<error_chain macros>:42
   3:     0x55615e0702e8 - tests::has_backtrace_depending_on_env
                        at /home/gbr/devel/ext/error-chain/tests/tests.rs:155
   4:     0x55615e08c6c6 - _<F as alloc..boxed..FnBox<A>>::call_box::h6c46b1f51a5f97cd
   5:     0x55615e0819eb - std::panicking::try::call::h8d6a00e6c0ac8b9e
   6:     0x55615e0cb0c6 - __rust_maybe_catch_panic
   7:     0x55615e08bf6c - _<F as alloc..boxed..FnBox<A>>::call_box::h173484225f9723d2
   8:     0x55615e0c12f7 - std::sys::thread::Thread::new::thread_start::h8f3bd45211e9f5ea
   9:     0x7fc160624423 - <unknown>
  10:     0x7fc160154ecc - clone
  11:                0x0 - <unknown>

Note the {{inlined-root}}::make_backtrace in there. Without inline(always):


   0:     0x55a6b9ade3a0 - backtrace::backtrace::libunwind::trace
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/libunwind.rs:54
                         - backtrace::backtrace::trace<closure>
                        at /home/gbr/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.2.3/src/backtrace/mod.rs:70
   1:     0x55a6b9aded1a - backtrace::capture::{{impl}}::new
                        at /home/gbr/devel/ext/error-chain/target/debug/build/backtrace-3bc1ff360ebb00cb/out/capture.rs:79
   2:     0x55a6b9ad8c12 - error_chain::make_backtrace
                        at /home/gbr/devel/ext/error-chain/src/lib.rs:685
   3:     0x55a6b9ad52bf - tests::has_backtrace_depending_on_env::{{impl}}::from
                        at /home/gbr/devel/ext/error-chain/<error_chain macros>:42
   4:     0x55a6b9ad5038 - tests::has_backtrace_depending_on_env
                        at /home/gbr/devel/ext/error-chain/tests/tests.rs:155
   5:     0x55a6b9af22a6 - _<F as alloc..boxed..FnBox<A>>::call_box::h6c46b1f51a5f97cd
   6:     0x55a6b9ae75cb - std::panicking::try::call::h8d6a00e6c0ac8b9e
   7:     0x55a6b9b30ca6 - __rust_maybe_catch_panic
   8:     0x55a6b9af1b4c - _<F as alloc..boxed..FnBox<A>>::call_box::h173484225f9723d2
   9:     0x55a6b9b26ed7 - std::sys::thread::Thread::new::thread_start::h8f3bd45211e9f5ea
  10:     0x7f8a425b6423 - <unknown>
  11:     0x7f8a420e6ecc - clone
  12:                0x0 - <unknown>

In light of that, I think it's better to read with the explicit frame in there.

@brson brson merged commit 8854a15 into rust-lang-nursery:master Aug 11, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@brson

This comment has been minimized.

Show comment
Hide comment
@brson

brson Aug 11, 2016

Contributor

Thanks!

Contributor

brson commented Aug 11, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment