From 2f584229d4e9dab4f1eb4cb548756b708619ae15 Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Tue, 22 Dec 2020 14:02:07 -0800 Subject: [PATCH] Improvements to NatVis support NatVis files describe how to display types in some Windows debuggers, such as Visual Studio, WinDbg, and VS Code. This commit makes several improvements: * Adds visualizers for Rc, Weak, and Arc. * Changes [size] to [len], for consistency with the Rust API. Visualizers often use [size] to mirror the size() method on C++ STL collections. * Several visualizers used the PVOID and ULONG typedefs. These are part of the Windows API; they are not guaranteed to always be defined in a pure Rust DLL/EXE. I converted PVOID to `void*` and `ULONG` to `unsigned long`. * Cosmetic change: Removed {} braces around the visualized display for `Option` types. They now display simply as `Some(value)` or `None`, which reflects what is written in source code. * The visualizer for `alloc::string::String` makes assumptions about the layout of `String` (it casts `String*` to another type), rather than using symbolic expressions. This commit changes the visualizer so that it simply uses symbolic expressions to access the string data and string length. --- src/etc/natvis/intrinsic.natvis | 18 +++++--- src/etc/natvis/liballoc.natvis | 46 ++++++++++++++----- src/etc/natvis/libcore.natvis | 26 ++++------- src/etc/natvis/libstd.natvis | 8 ++-- .../debuginfo/pretty-std-collections-hash.rs | 8 ++-- src/test/debuginfo/pretty-std.rs | 14 +++--- 6 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/etc/natvis/intrinsic.natvis b/src/etc/natvis/intrinsic.natvis index 874550da8b0c9..030892a432b31 100644 --- a/src/etc/natvis/intrinsic.natvis +++ b/src/etc/natvis/intrinsic.natvis @@ -4,17 +4,21 @@ {data_ptr,[length]s8} data_ptr,[length]s8 - length - - length - data_ptr - + length + + + + length + data_ptr + + + - {{ length={length} }} + {{ len={length} }} - length + length length data_ptr diff --git a/src/etc/natvis/liballoc.natvis b/src/etc/natvis/liballoc.natvis index de30b58526a13..cfaafc5734bce 100644 --- a/src/etc/natvis/liballoc.natvis +++ b/src/etc/natvis/liballoc.natvis @@ -1,9 +1,9 @@ - {{ size={len} }} + {{ len={len} }} - len + len buf.cap len @@ -12,9 +12,9 @@ - {{ size={tail <= head ? head - tail : buf.cap - tail + head} }} + {{ len={tail <= head ? head - tail : buf.cap - tail + head} }} - tail <= head ? head - tail : buf.cap - tail + head + tail <= head ? head - tail : buf.cap - tail + head buf.cap @@ -31,7 +31,7 @@ - {{ size={len} }} + {{ len={len} }} len @@ -42,15 +42,37 @@ - {*(char**)this,[vec.len]s8} - *(char**)this,[vec.len]s8 + {(char*)vec.buf.ptr.pointer,[vec.len]s8} + (char*)vec.buf.ptr.pointer,[vec.len]s8 - vec.len + vec.len vec.buf.cap - - vec.len - *(char**)this - + + + + vec.len + (char*)vec.buf.ptr.pointer + + + + + + + {ptr.pointer->value} + + ptr.pointer->value + + + + {ptr.pointer->data} + + ptr.pointer->data + + + + {ptr.pointer->data} + + ptr.pointer->data diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index 0e703b3b95026..984a8bfb13c7c 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -6,34 +6,28 @@ pointer + {{ Shared {pointer} }} pointer + - {{ None }} - {{ Some {__0} }} + None + Some({__0}) - (ULONG)(RUST$ENUM$DISR != 0) - __0 - - (ULONG)(RUST$ENUM$DISR != 0) - &__0 - + __0 + - {{ None }} - {{ Some {($T1 *)this} }} + None + Some({($T1 *)this}) - (ULONG)(*(PVOID *)this != nullptr) - ($T1 *)this - - (ULONG)(*(PVOID *)this != nullptr) - ($T1 *)this - + ($T1 *)this + \ No newline at end of file diff --git a/src/etc/natvis/libstd.natvis b/src/etc/natvis/libstd.natvis index 9550c25f2fcfe..7e5ee7b13daf1 100644 --- a/src/etc/natvis/libstd.natvis +++ b/src/etc/natvis/libstd.natvis @@ -26,9 +26,9 @@ --> - {{ size={base.table.items} }} + {{ len={base.table.items} }} - base.table.items + base.table.items base.table.items + base.table.growth_left base.hash_builder @@ -50,9 +50,9 @@ - {{ size={base.map.table.items} }} + {{ len={base.map.table.items} }} - base.map.table.items + base.map.table.items base.map.table.items + base.map.table.growth_left base.map.hash_builder diff --git a/src/test/debuginfo/pretty-std-collections-hash.rs b/src/test/debuginfo/pretty-std-collections-hash.rs index 9f59936a92d10..7115aec1041af 100644 --- a/src/test/debuginfo/pretty-std-collections-hash.rs +++ b/src/test/debuginfo/pretty-std-collections-hash.rs @@ -10,8 +10,8 @@ // cdb-command: g // cdb-command: dx hash_set,d -// cdb-check:hash_set,d [...] : { size=15 } [Type: [...]::HashSet] -// cdb-check: [size] : 15 [Type: [...]] +// cdb-check:hash_set,d [...] : { len=15 } [Type: [...]::HashSet] +// cdb-check: [len] : 15 [Type: [...]] // cdb-check: [capacity] : [...] // cdb-check: [[...]] [...] : 0 [Type: u64] // cdb-command: dx hash_set,d @@ -44,8 +44,8 @@ // cdb-check: [[...]] [...] : 14 [Type: u64] // cdb-command: dx hash_map,d -// cdb-check:hash_map,d [...] : { size=15 } [Type: [...]::HashMap] -// cdb-check: [size] : 15 [Type: [...]] +// cdb-check:hash_map,d [...] : { len=15 } [Type: [...]::HashMap] +// cdb-check: [len] : 15 [Type: [...]] // cdb-check: [capacity] : [...] // cdb-check: ["0x0"] : 0 [Type: unsigned __int64] // cdb-command: dx hash_map,d diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 6632488171dad..1a99f8412504a 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -74,8 +74,8 @@ // NOTE: While slices have a .natvis entry that works in VS & VS Code, it fails in CDB 10.0.18362.1 // cdb-command: dx vec,d -// cdb-check:vec,d [...] : { size=4 } [Type: [...]::Vec] -// cdb-check: [size] : 4 [Type: [...]] +// cdb-check:vec,d [...] : { len=4 } [Type: [...]::Vec] +// cdb-check: [len] : 4 [Type: [...]] // cdb-check: [capacity] : [...] [Type: [...]] // cdb-check: [0] : 4 [Type: unsigned __int64] // cdb-check: [1] : 5 [Type: unsigned __int64] @@ -89,8 +89,10 @@ // cdb-command: dx string // cdb-check:string : "IAMA string!" [Type: [...]::String] // cdb-check: [] [Type: [...]::String] -// cdb-check: [size] : 0xc [Type: [...]] +// cdb-check: [len] : 0xc [Type: [...]] // cdb-check: [capacity] : 0xc [Type: [...]] + +// cdb-command: dx -r2 string // cdb-check: [0] : 73 'I' [Type: char] // cdb-check: [1] : 65 'A' [Type: char] // cdb-check: [2] : 77 'M' [Type: char] @@ -109,11 +111,11 @@ // NOTE: OsString doesn't have a .natvis entry yet. // cdb-command: dx some -// cdb-check:some : { Some 8 } [Type: [...]::Option] +// cdb-check:some : Some(8) [Type: [...]::Option] // cdb-command: dx none -// cdb-check:none : { None } [Type: [...]::Option] +// cdb-check:none : None [Type: [...]::Option] // cdb-command: dx some_string -// cdb-check:some_string : { Some "IAMA optional string!" } [[...]::Option<[...]::String>] +// cdb-check:some_string : Some("IAMA optional string!") [[...]::Option<[...]::String>] #![allow(unused_variables)] use std::ffi::OsString;