Skip to content

rust: report file and line number that caused a panic. #485

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

Merged
merged 1 commit into from
Aug 20, 2021

Conversation

wedsonaf
Copy link

At the moment we get a mangled call stack. This prints a message that
allows us to pinpoint the source of the panic.

Signed-off-by: Wedson Almeida Filho wedsonaf@google.com

@nbdd0121
Copy link
Member

Well, I guess a better approach is to move the panic handler to kernel::print and just call pr_emerg!. I don't think this needs to be in the compiler_builtin crate.

@nbdd0121
Copy link
Member

Using pr_emerg!("{}", info) would also be more helpful since it will print the panic message as well.

@wedsonaf
Copy link
Author

You're right, it doesn't have to have to be in the compiler_builtins crate. Moving it to the kernel crate allows to use pr_*.

Updated the code.

@wedsonaf
Copy link
Author

rusttest is failing. Pinging @ojeda -- is there a way to fix this?

  RUSTC T  rust/kernel/lib.rs
error[E0152]: found duplicate lang item `panic_impl`
   --> rust/kernel/lib.rs:231:1
    |
231 | fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the lang item is first defined in crate `std` (which `test` depends on)
    = note: first definition in `std` loaded from /home/runner/work/linux/linux/rust/test/sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4bf57c4df90bbdf9.rlib, /home/runner/work/linux/linux/rust/test/sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4bf57c4df90bbdf9.rmeta
    = note: second definition in the local crate (`kernel`)

error: aborting due to previous error

@nbdd0121
Copy link
Member

#[cfg(not(testlib))]

@wedsonaf
Copy link
Author

#[cfg(not(testlib))]

I'm still getting the same error even with this.

@nbdd0121
Copy link
Member

Maybe #[cfg(not(any(testlib,doctest)))]?

@wedsonaf
Copy link
Author

Maybe #[cfg(not(any(testlib,doctest)))]?

Doesn't work either.

I'm reverting back to the previous implementation. I'll open a bug to move it to the kernel crate and use pr_emerg.

@nbdd0121
Copy link
Member

#[cfg(not(any(testlib,test,doctest)))] seems to be working for me.

At the moment we get a mangled call stack. This prints the panic message
and source location.

Moving the panic handler do the `kernel` crate allows us to use
`pr_emerg` to print the panic info.

Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
@wedsonaf
Copy link
Author

#[cfg(not(any(testlib,test,doctest)))] seems to be working for me.

Thanks, Gary! It looks like it's sufficient to exclude it on testlib and test.

@wedsonaf wedsonaf merged commit d04e27c into Rust-for-Linux:rust Aug 20, 2021
@wedsonaf wedsonaf deleted the panic-source branch August 20, 2021 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants