Skip to content

Commit 1ce1631

Browse files
authored
Merge pull request #452 from wedsonaf/pr_debug
rust: add `pr_debug`.
2 parents bc33ea8 + 4010fe9 commit 1ce1631

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

rust/kernel/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use macros::{module, module_misc_device};
1919

2020
pub use super::build_assert;
2121

22-
pub use super::{pr_alert, pr_crit, pr_emerg, pr_err, pr_info, pr_notice, pr_warn};
22+
pub use super::{pr_alert, pr_crit, pr_debug, pr_emerg, pr_err, pr_info, pr_notice, pr_warn};
2323

2424
pub use super::static_assert;
2525

rust/kernel/print.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,35 @@ macro_rules! pr_info (
384384
)
385385
);
386386

387+
/// Prints a debug-level message (level 7).
388+
///
389+
/// Use this level for debug messages.
390+
///
391+
/// Equivalent to the kernel's [`pr_debug`] macro, except that it doesn't support dynamic debug
392+
/// yet.
393+
///
394+
/// Mimics the interface of [`std::print!`]. See [`core::fmt`] and
395+
/// [`alloc::format!`] for information about the formatting syntax.
396+
///
397+
/// [`pr_debug`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_debug
398+
/// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html
399+
///
400+
/// # Examples
401+
///
402+
/// ```
403+
/// # use kernel::prelude::*;
404+
/// pr_debug!("hello {}\n", "there");
405+
/// ```
406+
#[macro_export]
407+
#[doc(alias = "print")]
408+
macro_rules! pr_debug (
409+
($($arg:tt)*) => (
410+
if cfg!(debug_assertions) {
411+
$crate::print_macro!($crate::print::format_strings::DEBUG, false, $($arg)*)
412+
}
413+
)
414+
);
415+
387416
/// Continues a previous log message in the same line.
388417
///
389418
/// Use only when continuing a previous `pr_*!` macro (e.g. [`pr_info!`]).

0 commit comments

Comments
 (0)