Skip to content

Commit

Permalink
describe how to debug for contributors (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed May 9, 2023
1 parent 959be77 commit 0b81087
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -35,6 +35,35 @@ cargo fmt -- --check

If you use [cargo-watch][], `cargo watch-check` alias is useful to run checks automatically on writing to a file.

## Print debug

Since this crate uses stdout, `println!` is not available for debugging. Instead, stderr through [`eprintln!`][eprintln]
or [`dbg!`][dbg] are useful.

At first, add prints where you want to debug:

```rust
eprintln!("some value is {:?}", some_value);
dbg!(&some_value);
```

Then redirect stderr to some file:

```sh
cargo run -- --example minimal 2>debug.txt
```

Then the debug prints are output to the `debug.txt` file. If timing is important or you want to see the output in real-time,
printing the file content with `tail` command would be useful.

```sh
# In a terminal, reproduce the issue
cargo run -- --example minimal 2>debug.txt

# In another terminal, run `tail` command to monitor the content
tail -F debug.txt
```

## Running a fuzzer

To run fuzzing tests, [cargo-fuzz][] is necessary.
Expand All @@ -61,3 +90,5 @@ See [README in bench/](./bench/README.md) for more details.
[cargo-watch]: https://crates.io/crates/cargo-watch
[cargo-fuzz]: https://github.com/rust-fuzz/cargo-fuzz
[criterion]: https://github.com/bheisler/criterion.rs
[eprintln]: https://doc.rust-lang.org/std/macro.eprintln.html
[dbg]: https://doc.rust-lang.org/std/macro.dbg.html

0 comments on commit 0b81087

Please sign in to comment.