Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] should document on how to support backtrace when size optimize #14611

Closed
loynoir opened this issue Sep 29, 2024 · 6 comments
Closed

[feat] should document on how to support backtrace when size optimize #14611

loynoir opened this issue Sep 29, 2024 · 6 comments
Labels
A-debugging Area: debug builds and debugging generated code C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@loynoir
Copy link

loynoir commented Sep 29, 2024

Problem

When use size optimize config, backtrace is not working.

[profile.reproduce]
inherits = "release"

debug = false
strip = true
backtrace::Backtrace    0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: __libc_start_main
   5: <unknown>

544K    bt

When use backtrace working config, size is much larger than size optimize config.

[profile.reproduce]
inherits = "release"

debug = true
strip = false
backtrace::Backtrace    0: bt::show_backtrace
             at /path/to/reproduce/src/bin/bt.rs:2:21
      bt::f4
             at /path/to/reproduce/src/bin/bt.rs:7:5
      bt::f3
             at /path/to/reproduce/src/bin/bt.rs:11:5
      bt::f2
             at /path/to/reproduce/src/bin/bt.rs:15:5
      bt::f1
             at /path/to/reproduce/src/bin/bt.rs:19:5
      bt::main
             at /path/to/reproduce/src/bin/bt.rs:23:5
   1: core::ops::function::FnOnce::call_once
             at /rustc/9b72238eb813e9d06e9e9d270168512fbffd7ee7/library/core/src/ops/function.rs:250:5
      std::sys::backtrace::__rust_begin_short_backtrace
             at /rustc/9b72238eb813e9d06e9e9d270168512fbffd7ee7/library/std/src/sys/backtrace.rs:154:18
   2: main
   3: <unknown>
   4: __libc_start_main
   5: _start

5.4M    bt

Proposed Solution

Should document on how to find a balance like something like below.

[profile.reproduce]
inherits = "release"

debug = false_but_keep_user_backtrace
strip = true_but_not_user_backtrace
backtrace::Backtrace    0: bt::show_backtrace
             at /path/to/reproduce/src/bin/bt.rs:2:21
      bt::f4
             at /path/to/reproduce/src/bin/bt.rs:7:5
      bt::f3
             at /path/to/reproduce/src/bin/bt.rs:11:5
      bt::f2
             at /path/to/reproduce/src/bin/bt.rs:15:5
      bt::f1
             at /path/to/reproduce/src/bin/bt.rs:19:5
      bt::main
             at /path/to/reproduce/src/bin/bt.rs:23:5
   **/rustc/xxx are not kept **
   **main, <unknown>, __libc_start_main, _start are not kept**

544K    bt

Notes

feat on backtrace side

rust-lang/backtrace-rs#675

@loynoir loynoir added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Sep 29, 2024
@ChrisDenton
Copy link
Member

There is already documentation, can you suggest an improvement? https://doc.rust-lang.org/cargo/reference/profiles.html

If you want to keep backtrace info intact then try:

debug = "line-tables-only"
strip = "debuginfo"

@loynoir
Copy link
Author

loynoir commented Sep 29, 2024

Actually, f1 f2 f3 f4 are missing.

[profile.reproduce]
inherits = "release"

debug = "line-tables-only"
strip = "debuginfo"
backtrace::Backtrace    0: bt::main
   1: std::sys::backtrace::__rust_begin_short_backtrace
   2: main
   3: <unknown>
   4: __libc_start_main
   5: _start

620K    bt

@ChrisDenton
Copy link
Member

Then try debug = "limited" as noted in the docs.

If a function is inlined then it essentially doesn't exist in the final binary. Therefore you need more debug information to reconstruct the full trace.

@ChrisDenton
Copy link
Member

In any case, this isn't a Cargo issue. The debug field exposes the options rustc provides. If you think there's something more that rust could do here then file an issue on rust-lang,/rust. But removing debug information is always going to be in tension with providing a full backtrace.

@loynoir
Copy link
Author

loynoir commented Sep 29, 2024

Emm, f1 f2 f3 f4 are still missing.

[profile.reproduce]
inherits = "release"

debug = "limited"
strip = "debuginfo"
backtrace::Backtrace    0: bt::main
   1: std::sys::backtrace::__rust_begin_short_backtrace
   2: main
   3: <unknown>
   4: __libc_start_main
   5: _start

620K    bt

@weihanglo
Copy link
Member

In any case, this isn't a Cargo issue. The debug field exposes the options rustc provides. If you think there's something more that rust could do here then file an issue on rust-lang,/rust.

Agree with Chris.

Since the same issue has been opened twice, let's keep the discussion in one place. Close in favor of rust-lang/backtrace-rs#675.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2024
@weihanglo weihanglo added A-debugging Area: debug builds and debugging generated code and removed S-triage Status: This issue is waiting on initial triage. labels Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debugging Area: debug builds and debugging generated code C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

3 participants