trace

A syntax extension for tracing the execution of functions. Adding #[trace] to the top of any function will insert println! statements at the beginning and end of that function, notifying you of when that function was entered and exited and printing the argument and return values. This is useful for quickly debugging whether functions that are supposed to be called are actually called without manually inserting print statements.

Note that this extension requires all arguments to the function and the return value to have types that implement Debug. You can disable the printing of certain arguments if necessary (described below).

Installation

Add trace = "*" to your Cargo.toml.

Example

Here is an example you can find in the examples folder. If you've cloned the project, you can run this with cargo run --example example.

```

![feature(custom_attribute, plugin)]

![plugin(trace)]

static mut depth: u32 = 0;

fn main() { foo(1, 2); }

[trace]

fn foo(a: i32, b: i32) { println!("I'm in foo!"); bar((a, b)); }

[trace(prefixenter="[ENTER]", prefixexit="[EXIT]")]

fn bar((a, b): (i32, i32)) -> i32 { println!("I'm in bar!"); if a == 1 { 2 } else { b } } ```

Output: [+] Entering foo(a: 1, b: 2) I'm in foo! [ENTER] Entering bar(a: 1, b: 2) I'm in bar! [EXIT] Exiting bar = 2 [-] Exiting foo = ()

Optional Arguments

Trace takes a few optional arguments, described below:

Note that enable and disable can not be used together, and doing so will result in an error.

All of these options are covered in the examples folder.