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

Why "pub fn panic() -> !" is "#[inline(always)]" #824

Open
gobftald opened this issue Mar 29, 2024 · 5 comments
Open

Why "pub fn panic() -> !" is "#[inline(always)]" #824

gobftald opened this issue Mar 29, 2024 · 5 comments
Labels
type: bug Something isn't working

Comments

@gobftald
Copy link

I don't know whether is general, but in my case this causes that in a "backtrace list" we miss the most important item, the point where the "user code" exactly calls "defmt::panic!()".

When "backtrace" shows the "file-line-column" information for an address, in the current "#[inline(always)]" version "defmt::export::panic" is showed to be called from "user code" but one "stack frame" before, skipping the exact place where the call was really called. Which is not a really useful information. In the "#[inline(never)]" version, since the address of "defmt::export::panic" is really put into the stack, the "backtrace list" properly shows the exact place of this call in the "user code". And this is what we really needs.

@Urhengulas Urhengulas added the type: bug Something isn't working label Mar 29, 2024
@Urhengulas
Copy link
Member

@japaric can you shed some light?

@gobftald
Copy link
Author

gobftald commented Apr 3, 2024

As I mentioned, may be it is specific, but it is definitely happening in my environment. I'm programming an esp32c3 chip, so I use eps-backtrace, which simply collects addresses from stack to show a backtrace list. It works well in case of core::panic, but if I use defmt::panic the backtrace does not show the place where the user code called defmt::panic. That point the list shows a defmt internal address where defmt finally calls core::panic.

If I change #[inline(always)] to #[inline(never)] of 'pub fn panic() -> !' in 'defmt/defmt/src/export/mod.rs' the backtrace list works in a proper way again, showing properly where "defmt::panicked" was called in the user code.

Is it some 'light' for you?

@Urhengulas
Copy link
Member

Is it some 'light' for you?

No.

I would be interested in why it was implemented with inline(always).

Also probe-rs is (and probe-run was) able to show the exact location in the user code. So maybe it is supposed to be like that.

@gobftald
Copy link
Author

gobftald commented Apr 4, 2024

Maybe it is ESP specific. Since they/me use their own 'monitor' program and 'parser' logic in their 'espflash tool to decode your compression and then the address in the output.

Thank you for your attention/help. Anyway, I need to use this minor customisation of your code to get proper backtrace.

@Urhengulas
Copy link
Member

Anyway, I need to use this minor customisation of your code to get proper backtrace.

I get that. And in general I am happy to make this change. I just want to avoid to break other code, in case the inlining is actually necessary in the usual setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants