backtrace-rs icon indicating copy to clipboard operation
backtrace-rs copied to clipboard

`Symbol` struct is not `Clone`

Open Diggsey opened this issue 5 years ago • 6 comments

It does not appear possible to use the raw backtrace functionality effectively, because the Symbol struct does not implement Clone, and the resolve_frame callback is passed a &Symbol reference which is not 'static. As a result, there's no way to store that symbol for later use.

Diggsey avatar Nov 16 '20 22:11 Diggsey

This is deliberate. The Symbol may borrow for example the name field from the mmapped object file. This is the case for the gimli backend. The gimli backend uses an LRU cache for those mmaps, so the Symbol may become invalid later on: https://github.com/rust-lang/backtrace-rs/blob/e7f61cc6b52791e0299bbd6ecfaa25e8ae02034a/src/symbolize/gimli.rs#L582

bjorn3 avatar Nov 16 '20 23:11 bjorn3

The Backtrace type can be resolved before it is formatted, but as a result of Symbol not being Clone, there's no way to do this with the raw API?

Diggsey avatar Nov 16 '20 23:11 Diggsey

Changing Symbol to be Clone will require adding a lifetime parameter to Symbol (because the 'static is a lie, the real lifetime is shorter than that). Doing that isn't going to solve the problem you have because you still won't be able to store the symbol for later use.

philipc avatar Nov 16 '20 23:11 philipc

Yes unfortunately Symbol can't easily be Clone unless it has some sort of cow-like representation. What might make sense though is to do something like impl From<&Symbol> for BacktraceSymbol which already does the cow-like thing, and that should give you an owned struct to persist.

alexcrichton avatar Nov 17 '20 06:11 alexcrichton

Yep 👍 I think I would also need a similar conversion for Frame in order to use the formatter?

Diggsey avatar Nov 17 '20 11:11 Diggsey

Yes I believe a similar conversion from &Frame to BacktraceFrame should be possible.

alexcrichton avatar Nov 17 '20 14:11 alexcrichton