mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:24:45 +01:00
rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option
Make warn_on() support DEBUG_BUGVERBOSE_DETAILED option, which was
introduced by the commit aec58b4851 ("bugs/core: Extend
__WARN_FLAGS() with the 'cond_str' parameter").
When the option is enabled, WARN splats now show the evaluated
warn_on() condition alongside the file path, e.g.:
------------[ cut here ]------------
WARNING: [val == 1] linux/samples/rust/rust_minimal.rs:27 at _RNvXCsk7t4azzUqHP_12rust_minimalNtB2_11RustMinimalNtCs8pcx3n4
Modules linked in: rust_minimal(+)
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260108013350.2880613-1-fujita.tomonori@gmail.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
abbe94591e
commit
966f79ce6f
1 changed files with 13 additions and 7 deletions
|
|
@ -11,9 +11,9 @@
|
|||
#[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
|
||||
#[cfg(CONFIG_DEBUG_BUGVERBOSE)]
|
||||
macro_rules! warn_flags {
|
||||
($flags:expr) => {
|
||||
($file:expr, $flags:expr) => {
|
||||
const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
|
||||
const _FILE: &[u8] = file!().as_bytes();
|
||||
const _FILE: &[u8] = $file.as_bytes();
|
||||
// Plus one for null-terminator.
|
||||
static FILE: [u8; _FILE.len() + 1] = {
|
||||
let mut bytes = [0; _FILE.len() + 1];
|
||||
|
|
@ -50,7 +50,7 @@ macro_rules! warn_flags {
|
|||
#[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
|
||||
#[cfg(not(CONFIG_DEBUG_BUGVERBOSE))]
|
||||
macro_rules! warn_flags {
|
||||
($flags:expr) => {
|
||||
($file:expr, $flags:expr) => {
|
||||
const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
|
||||
|
||||
// SAFETY:
|
||||
|
|
@ -75,7 +75,7 @@ macro_rules! warn_flags {
|
|||
#[doc(hidden)]
|
||||
#[cfg(all(CONFIG_BUG, CONFIG_UML))]
|
||||
macro_rules! warn_flags {
|
||||
($flags:expr) => {
|
||||
($file:expr, $flags:expr) => {
|
||||
// SAFETY: It is always safe to call `warn_slowpath_fmt()`
|
||||
// with a valid null-terminated string.
|
||||
unsafe {
|
||||
|
|
@ -93,7 +93,7 @@ macro_rules! warn_flags {
|
|||
#[doc(hidden)]
|
||||
#[cfg(all(CONFIG_BUG, any(CONFIG_LOONGARCH, CONFIG_ARM)))]
|
||||
macro_rules! warn_flags {
|
||||
($flags:expr) => {
|
||||
($file:expr, $flags:expr) => {
|
||||
// SAFETY: It is always safe to call `WARN_ON()`.
|
||||
unsafe { $crate::bindings::WARN_ON(true) }
|
||||
};
|
||||
|
|
@ -103,7 +103,7 @@ macro_rules! warn_flags {
|
|||
#[doc(hidden)]
|
||||
#[cfg(not(CONFIG_BUG))]
|
||||
macro_rules! warn_flags {
|
||||
($flags:expr) => {};
|
||||
($file:expr, $flags:expr) => {};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
|
|
@ -116,10 +116,16 @@ pub const fn bugflag_taint(value: u32) -> u32 {
|
|||
macro_rules! warn_on {
|
||||
($cond:expr) => {{
|
||||
let cond = $cond;
|
||||
|
||||
#[cfg(CONFIG_DEBUG_BUGVERBOSE_DETAILED)]
|
||||
const _COND_STR: &str = concat!("[", stringify!($cond), "] ", file!());
|
||||
#[cfg(not(CONFIG_DEBUG_BUGVERBOSE_DETAILED))]
|
||||
const _COND_STR: &str = file!();
|
||||
|
||||
if cond {
|
||||
const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
|
||||
|
||||
$crate::warn_flags!(WARN_ON_FLAGS);
|
||||
$crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
|
||||
}
|
||||
cond
|
||||
}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue