Skip to main content

Module dprintf

Module dprintf 

Source
Expand description

Debug logging (dprintf) mechanism for the Zircon kernel.

§Overview

This crate provides a Rust implementation of the global debug printing mechanism (dprintf!) used in the Zircon kernel. It is the Rust counterpart to the C++ header zircon/kernel/include/debug.h.

§Verbosity Levels

The macro dprintf! filters messages at compile time based on the global GN build argument kernel_debug_print_level.

This argument defaults to 2 (SPEW) in the kernel parameters (see zircon/kernel/params.gni).

To override this level in your local build, add the following to your args.gn:

kernel_debug_print_level = 1  # Restrict to INFO and CRITICAL

The following levels are defined, matching C++:

  • CRITICAL (0) / ALWAYS (0): Critical errors or messages that should always be printed.
  • INFO (1): Informational messages.
  • SPEW (2): Verbose debugging messages.

If a message’s level is greater than the configured kernel_debug_print_level, the macro call compiles down to nothing, incurring zero runtime overhead.

§Usage

To use global debug printing in a Rust file:

use debug::dprintf;

fn my_function() {
    dprintf!(INFO, "This is an info message: {}\n", 42);
    dprintf!(SPEW, "This is verbose spew\n");
}

The macro supports literal tokens CRITICAL, ALWAYS, INFO, and SPEW without needing to import them, but you can also use arbitrary expressions that evaluate to u32 (e.g. debug::dprintf::INFO or a local variable).

Constants§

ALWAYS
CRITICAL
INFO
SPEW