From 0b81087035a747d2c21712a4267eae438182370c Mon Sep 17 00:00:00 2001 From: rhysd Date: Tue, 9 May 2023 22:48:29 +0900 Subject: [PATCH] describe how to debug for contributors (#17) --- CONTRIBUTING.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8e83986..fb7fc75 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. @@ -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