ckb_std/debug.rs
1/// debug macro
2///
3/// Output a debug message.
4///
5/// This macro only compiled under debug build and does nothing in release build. To debug the release build,
6/// include `--cfg debug_assertions` in the environment variable `RUSTFLAGS` before calling `cargo build`.
7/// For example:
8///
9/// ```
10/// RUSTFLAGS="--cfg debug_assertions" cargo build --release --target=riscv64imac-unknown-none-elf
11/// ```
12///
13/// For users of Capsule, the debug macro can be enabled in the release build by running
14/// `capsule build --release --debug-output`.
15///
16/// Notice: to see the debug output, you must turn on `ckb_script` debugging log in the CKB node configuration
17/// like this:
18///
19/// ```toml
20/// [logger]
21/// filter = "info,ckb-script=debug"
22/// ```
23///
24/// See the essay on more [Tips for Debugging CKB Scripts](https://docs.nervos.org/docs/essays/debug).
25///
26/// # Example
27///
28/// ```
29/// debug!("hello world");
30/// debug!("there is a universal error caused by {}", 42);
31/// ```
32#[macro_export]
33macro_rules! debug {
34 ($fmt:literal) => {
35 #[cfg(debug_assertions)]
36 $crate::syscalls::debug(alloc::format!($fmt));
37 };
38 ($fmt:literal, $($args:expr),+) => {
39 #[cfg(debug_assertions)]
40 $crate::syscalls::debug(alloc::format!($fmt, $($args), +));
41 };
42}