Skip to content

Commit

Permalink
Merge pull request #473 from tijlleenders/tijl/-/rustrover-debugging-…
Browse files Browse the repository at this point in the history
…instructions

Add RustRover debug instructions
  • Loading branch information
tijlleenders authored Dec 8, 2024
2 parents ccee1ee + 0aae02d commit 5e62d36
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
74 changes: 48 additions & 26 deletions documentation/technical/Debugging-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,80 @@
The ZinZen®-scheduler codebase uses the Chrono NaiveDateTime structs for representing
date and time. During debugging these are not printed in a convenient format.

To enable pretty printing of dates we can alter the way the debugger prints these values. This works differently for each
To enable pretty printing of dates we can alter the way the debugger prints these values. This works differently for
each
debugger and platform. A list of confirmed and unconfirmed solutions:

#### A.0) RustRover

- Pin the Rust toolchain to whatever version works with RustRover (in dec '24 I had to go back to 1.81.0),
by renaming "stable" to "1.81.0" in `rust-toolchain.toml`.
- Now we still need custom types for chrono.
Do this by setting the RustRover Settings=>Build, Execution, Deployment=>Debugger=>Data Views=>Rust LLDB Renderers
to 'Rust compiler's renderers'.
Now you can check the path used for launching LLDB commands in the LLDB tab of the debugger.
For me this is '~/.rustup/toolchains/1.81.0-x86_64-unknown-linux-gnu/lib/rustlib/etc/lldb_commands'.
Append the instructions in 'scripts/debug_formatter/chrono_formatter' to that file, but be careful to adjust the
chrono.py filepath.
I copied the 'scripts/debug_formatter/chrono.py' file to the lldb_commands directory, for easy reference.

#### A.1) Intellij with intellij-rust plugin

this solution is confirmed to work with Intellij using an LLDB-based debugger on MacOS:
https://github.com/intellij-rust/intellij-rust/issues/10219#issuecomment-1464970768

A similar solution should also work for GDB-based debuggers: https://github.com/intellij-rust/intellij-rust/issues/3639

#### A.2) debugger visualization attributes for rust-native debugging
Rust introduced debugger visualization attributes in 1.71.0: https://doc.rust-lang.org/nightly/reference/attributes/debugger.html#the-debugger_visualizer-attribute. This should also work, but is not yet tested in the context of this codebase.

Rust introduced debugger visualization attributes in
1.71.0: https://doc.rust-lang.org/nightly/reference/attributes/debugger.html#the-debugger_visualizer-attribute. This
should also work, but is not yet tested in the context of this codebase.

#### A.3) VSCode

Install the required extensions for debugging Rust.

- C/C++ for VSCode if you're running Windows
- CodeLLDB if you're running Linux

To debug tests with better `NaiveDateTime` formatter, kindly add custom configuration inside `launch.json` as below:

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug 'rust_tests' with pprint",
"cargo": {
"args": [
"test",
"--no-run",
"--test=rust_tests",
"--package=zinzen"
],
"filter": {
"name": "rust_tests",
"kind": "test"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"initCommands": [
"command source '${workspaceFolder}/scripts/debug_formatter/chrono_formatter'"
]
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug 'rust_tests' with pprint",
"cargo": {
"args": [
"test",
"--no-run",
"--test=rust_tests",
"--package=zinzen"
],
"filter": {
"name": "rust_tests",
"kind": "test"
}
]
},
"args": [],
"cwd": "${workspaceFolder}",
"initCommands": [
"command source '${workspaceFolder}/scripts/debug_formatter/chrono_formatter'"
]
}
]
}
```

If you get an error `no rust_tests found` do a `cargo build` and try again.

To debug a single, specific test, from the rust_tests:
add the test name to the root args (not the cargo args) as such:

```
"args": ["test_name_here"],
```
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "stable"
channel = "1.81.0"
components = ["rustfmt", "clippy", "rust-src"]
targets = ["wasm32-unknown-unknown"]
File renamed without changes.
8 changes: 4 additions & 4 deletions scripts/debug_formatter/chrono_formatter
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
command script import ./scripts/debug_formatter/simd.py
command script import ./scripts/debug_formatter/chrono.py

type summary add -F simd.ChronoNaiveDateTimeProvider chrono::naive::datetime::NaiveDateTime
type summary add -F simd.ChronoNaiveDateProvider chrono::naive::date::NaiveDate
type summary add -F simd.ChronoNaiveTimeProvider chrono::naive::time::NaiveTime
type summary add -F chrono.ChronoNaiveDateTimeProvider chrono::naive::datetime::NaiveDateTime
type summary add -F chrono.ChronoNaiveDateProvider chrono::naive::date::NaiveDate
type summary add -F chrono.ChronoNaiveTimeProvider chrono::naive::time::NaiveTime

0 comments on commit 5e62d36

Please sign in to comment.