A tracer for cairo-rs which gives you a visualization of how your memory and registers change line after line as the VM executes the code.

How does it work?

The tracer keeps track of two things during the program run

  1. The registers (ap, pc, fp)
  2. The memory segments

Using this information, it's possible to calculate your dst, op0 and op1 addresses. The compiled cairo code also has information regarding the code line number which executes corresponding to each pc (stored inside instruction_locations). The tracer combines all this information and gives a easy to use interface to visualize your program run.

Setting up the tracer

All tracer functionality is behind a feature flag. This ensures that the tracer (which is meant to be a debugging tool) doesn't affect release benchmarking. To use the tracer, you need to build the VM using the `with_tracer` feature flag.

cargo build --release --features with_tracer

Running the tracer

Once the build in the above step is complete, you can use the cairo-vm-cli as you do normally with an additional argument --tracer true. This tells the VM to start a server where you can visualize the execution of your cairo program.

target/release/cairo-vm-cli <path_to_compiled_cairo_json> --layout <layout> --memory_file <path_to_store_memory_binary> --trace_file <path_to_store_tracer_binary> --tracer true

Using the tracer

You can go to to see the tracer.

Use the following commands to visualize the code execution

- s to go to the next step

- Shift + s to go to the previous step

- n to step over

- N to previous step over

- o to step out

- b to run until you reach the next breakpoint

- B to run until you reach the previous breakpoint