loom icon indicating copy to clipboard operation
loom copied to clipboard

error reporting: consider capturing the stack frames of accesses

Open hawkw opened this issue 6 years ago • 0 comments

When a causality violation occurs during a CausalCell access, the cell panics, failing the test. If backtraces are enabled (i.e. RUST_BACKTRACE=1), the panic message will print the stack trace of the access during which the causality violation was detected. However, it is harder to determine where in the program the concurrent accesses that also participated in the violation occurred. The panic message will include the current state of the causal cell in that execution, like this:

"Causality violation: Concurrent mutable access and immutable access(es): cell.with_mut: v=VersionVec { versions: [6, 4, 4, 0] }; mut v=VersionVec { versions: [4, 0, 0, 0] }; thread=VersionVec { versions: [5, 12, 0, 0] }"

but this debug output can be difficult for users to interpret.

I'd like to propose a feature to allow loom to capture the backtraces of all accesses to a CausalCell. If this feature is enabled (e.g. by the RUST_BACKTRACE env var, or a separate LOOM_BACKTRACE env var?), every time a causal cell is accessed, the stack backtrace in which that access occurred would be recorded. If a causality violation is detected, loom could print a message that includes all the stack frames responsible for the violation. For example:

Causality violation: concurrent mutable and immutable access(es): cell.with_mut:
Accessed mutably from:
  1:  loom::sync::causal::cell::CausalCell<T>::with_mut
             at /Users/eliza/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.2.8/src/sync/causal/cell.rs:136
  2: my_crate::MyType::do_causality_violation
             at src/lib.rs:178
  3: my_crate::MyType::maybe_do_a_bad_thing
             at src/lib.rs:422
  4: my_crate::MyType::some_function
             at src/lib.rs:339
   ...
Concurrently accessed immutably from:
  1: loom::sync::causal::cell::CausalCell<T>::with
             at /Users/eliza/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.2.8/src/sync/causal/cell.rs:81
  2: my_crate::MyType::some_other_function
             at src/lib.rs:320
  3: my_crate::my_mod::my_function             
             at src/my_mod.rs:112
  3: my_crate::do_something     
             at src/lib.rs:412
  ...
Concurrently accessed immutably from:
  1: loom::sync::causal::cell::CausalCell<T>::with
             at /Users/eliza/.cargo/registry/src/github.com-1ecc6299db9ec823/loom-0.2.8/src/sync/causal/cell.rs:81
  2: my_crate::MyType::some_other_function
             at src/lib.rs:320
  3: my_crate::my_mod::my_great_function             
             at src/my_mod.rs:261
  ...

Additionally, it could be helpful to process the captured backtraces to remove stack frames inside of loom, since they're not relevant to the user code being simulated and make the backtrace much longer.

hawkw avatar Oct 12 '19 20:10 hawkw