Skip to content

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

Merged
wedsonaf merged 1 commit into
Rust-for-Linux:rustfrom
wedsonaf:panic-source
Aug 20, 2021
Merged

rust: report file and line number that caused a panic.#485
wedsonaf merged 1 commit into
Rust-for-Linux:rustfrom
wedsonaf:panic-source

Conversation

@wedsonaf

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Member

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

@wedsonaf

Copy link
Copy Markdown
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.

Comment threadrust/kernel/lib.rs
@wedsonaf

Copy link
Copy Markdown
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
Copy Markdown
Member

#[cfg(not(testlib))]

@wedsonaf

Copy link
Copy Markdown
Author

#[cfg(not(testlib))]

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

@nbdd0121

Copy link
Copy Markdown
Member

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

@wedsonaf

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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:rustAug 20, 2021
@wedsonaf
wedsonaf deleted the panic-source branch August 20, 2021 03:51
Sign up for freeto 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

@wedsonaf@nbdd0121