Add natvis for cell types

This commit is contained in:
Wesley Wiser 2021-06-29 15:32:03 -04:00
parent 9740dcc82f
commit cad42e0d33
3 changed files with 102 additions and 15 deletions

View File

@ -1,5 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="core::cell::Cell&lt;*&gt;">
<DisplayString>{value.value}</DisplayString>
<Expand>
<ExpandedItem>value.value</ExpandedItem>
</Expand>
</Type>
<Type Name="core::cell::Ref&lt;*&gt;">
<DisplayString>{value}</DisplayString>
<Expand>
<ExpandedItem>value</ExpandedItem>
</Expand>
</Type>
<Type Name="core::cell::RefMut&lt;*&gt;">
<DisplayString>{value}</DisplayString>
<Expand>
<ExpandedItem>value</ExpandedItem>
</Expand>
</Type>
<Type Name="core::cell::RefCell&lt;*&gt;">
<DisplayString>{value.value}</DisplayString>
<Expand>
<Item Name="[Borrow state]" Condition="borrow.value.value == 0">"Unborrowed",sb</Item>
<Item Name="[Borrow state]" Condition="borrow.value.value &gt; 0">"Immutably borrowed",sb</Item>
<Item Name="[Borrow state]" Condition="borrow.value.value &lt; 0">"Mutably borrowed",sb</Item>
<ExpandedItem>value.value</ExpandedItem>
</Expand>
</Type>
<Type Name="core::cell::UnsafeCell&lt;*&gt;">
<DisplayString>{value}</DisplayString>
<Expand>
<ExpandedItem>value</ExpandedItem>
</Expand>
</Type>
<Type Name="core::num::nonzero::NonZeroI8">
<DisplayString>{__0}</DisplayString>
</Type>

View File

@ -9,26 +9,64 @@
// cdb-command: g
// cdb-command:dx static_c,d
// cdb-check:static_c,d [Type: core::cell::Cell<i32>]
// cdb-check: [...] value [Type: core::cell::UnsafeCell<i32>]
// cdb-check:static_c,d : 10 [Type: core::cell::Cell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::Cell<i32>]
// cdb-command: dx static_c.value,d
// cdb-check:static_c.value,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [...] value : 10 [Type: int]
// cdb-check:static_c.value,d : 10 [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
// cdb-command: dx dynamic_c,d
// cdb-check:dynamic_c,d [Type: core::cell::RefCell<i32>]
// cdb-check: [...] borrow [Type: core::cell::Cell<isize>]
// cdb-check: [...] value [Type: core::cell::UnsafeCell<i32>]
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
// cdb-check: [Borrow state] : Unborrowed
// cdb-command: dx dynamic_c.value,d
// cdb-check:dynamic_c.value,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [...] value : 15 [Type: int]
// cdb-check:dynamic_c.value,d : 15 [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
// cdb-command: dx b,d
// cdb-check:b,d [Type: core::cell::RefMut<i32>]
// cdb-check: [...] value : [...] : 42 [Type: int *]
// cdb-check: [...] borrow [Type: core::cell::BorrowRefMut]
// cdb-check:b,d : 42 [Type: core::cell::RefMut<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefMut<i32>]
// cdb-check: 42 [Type: int]
// cdb-command: g
// cdb-command: dx dynamic_c,d
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
// cdb-check: [Borrow state] : Immutably borrowed
// cdb-command: dx r_borrow,d
// cdb-check:r_borrow,d : 15 [Type: core::cell::Ref<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::Ref<i32>]
// cdb-check: 15 [Type: int]
// cdb-command: g
// cdb-command: dx dynamic_c,d
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
// cdb-check: [Borrow state] : Unborrowed
// cdb-command: g
// cdb-command: dx dynamic_c,d
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
// cdb-check: [Borrow state] : Mutably borrowed
// cdb-command: dx r_borrow_mut,d
// cdb-check:r_borrow_mut,d : 15 [Type: core::cell::RefMut<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefMut<i32>]
// cdb-check: 15 [Type: int]
// cdb-command: g
// cdb-command: dx dynamic_c,d
// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::RefCell<i32>]
// cdb-check: [Borrow state] : Unborrowed
#![allow(unused_variables)]
@ -46,6 +84,21 @@ fn main() {
*b = 42;
zzz(); // #break
// Check that `RefCell`'s borrow state visualizes correctly
{
let r_borrow = dynamic_c.borrow();
zzz(); // #break
}
zzz(); // #break
{
let r_borrow_mut = dynamic_c.borrow_mut();
zzz(); // #break
}
zzz(); // #break
}
fn zzz() {()}

View File

@ -11,15 +11,15 @@
// cdb-command:dx l
// cdb-check:l [Type: std::sync::rwlock::RwLock<i32>]
// cdb-check: [...] poison [Type: std::sync::poison::Flag]
// cdb-check: [...] data [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [...] data : 0 [Type: core::cell::UnsafeCell<i32>]
//
// cdb-command:dx r
// cdb-check:r [Type: std::sync::rwlock::RwLockReadGuard<i32>]
// cdb-check: [...] lock : [...] [Type: std::sync::rwlock::RwLock<i32> *]
//
// cdb-command:dx r.lock->data,d
// cdb-check:r.lock->data,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [...] value : 0 [Type: int]
// cdb-check:r.lock->data,d : 0 [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
#[allow(unused_variables)]