-
Notifications
You must be signed in to change notification settings - Fork 497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Natvis definitions for types defined in the core
module of the windows
crate
#2023
Conversation
core
types defined in the Windows cratewindows::core
module of the windows
crate
windows::core
module of the windows
cratecore
module of the windows
crate
Thanks Ridwan, this looks exciting! I'll take it for a spin when I get a moment. Can the same natvis be applied to both |
No, I don't believe they can. For starters, the Natvis definitions depend on the fully qualified type name which includes the crate name. This means for the Natvis definitions I added here, they would only apply to the Also, looking at the definitions for the |
They have the exact same memory layouts, but if the debugger just looks at the underlying types then you may have a problem. |
Sorry, I meant from the debuggers aspect in terms of which type is being rendered. The debugger uses the underlying type for type definitions which makes creating specific Natvis for them difficult. |
Hi Ridwan! Sorry for the delay on that PR. Been a little swamped. I took it for a quick spin with the VS debugger and it looks great. Any ideas when it will be stabilized? I'd like to avoid carrying unstable features indefinitely. Other than that, I'd probably just recommend moving the windows.natvis into the crates/libs/windows folder as its specific to that crate and doesn't need its own top-level folder. The readme could go into the docs folder as it seems very useful. |
Honestly speaking I was trying to show the value of this unstable feature by applying it directly to crates. I plan on trying to get this stabilized in the near future but that also depends on the responses from the Rust team.
Sounds good. I'll make those changes and push out an update. |
…d readme to docs/.
I recently debugged some BSTRs. A windows 0.40-friendly .natvis that could be merged into this or a future PR: <?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!--
This could be simplified with the `x,bstr` format specifier.
However, that doesn't appear to be supported by VS Code?
-->
<Type Name="windows::core::strings::bstr::BSTR">
<DisplayString Condition="__0">{(wchar_t*)__0,[((unsigned int *)__0)[-1] / 2]su}</DisplayString>
<DisplayString Condition="!__0">{(wchar_t*)__0,su}</DisplayString>
<Expand>
<Item Condition="__0" Name="[len]" >((unsigned int *)__0)[-1] / 2</Item>
<Item Condition="__0" Name="[bytes]" >((unsigned int *)__0)[-1]</Item>
<Item Condition="__0" Name="[code units]" >(wchar_t*)__0,[((unsigned int *)__0)[-1] / 2]su</Item>
<Item Condition="!__0" Name="[len]" >0</Item>
<Item Condition="!__0" Name="[bytes]" >0</Item>
<Item Condition="!__0" Name="[code units]" >(wchar_t*)0,su</Item>
</Expand>
</Type>
</AutoVisualizer> I'm finding it awkward to build Might drop the
I'll take this opportunity to plug my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I still need to get my head around how this is tested but this looks like a great start. I'd love to expand on it once we have it merged in.
@MaulingMonkey feel free to contribute something for BSTR! Yes, we should strive for something that works across the WinDbg/VS/Code debuggers. |
The
This one has me confused, too. While I do not doubt that the tests initially succeeded, they should have started failing when #2078 changed struct HSTRING(*mut Header); to struct HSTRING(Option<std::ptr::NonNull<Header>>); The tests, however, continue to succeed to this day. I may be misunderstanding how CDB or GitHub workflows or
which is (meaningfully) distinct from the expected output:
My verification was run against this binary crate: main.rs: use windows::core::HSTRING;
fn main() {
let empty = HSTRING::new();
println!("{empty}");
} Cargo.toml: [package]
name = "windows_natvis"
version = "0.0.0"
edition = "2021"
[dependencies.windows]
version = "0.52.0"
features = [] .cargo/config.toml: [build]
rustflags = ["--cfg=windows_debugger_visualizer"] I'd love to continue on my week-long Yak Shave, though I believe we should get rigorous testing set up before moving forward. Thoughts? (@ridwanabdillahi @kennykerr @MaulingMonkey @riverar @TimMisiak @wesleywiser) |
Test-expected output involves
Are you sure it didn't? Actions/debugger_visualizer doesn't retain history that far back, (edit:) and it appears to be catching recent visualizer breakage in pull requests just fine. |
Not seeing any test issues here; you can harvest cdb output from (cdb 10.0.22621.2428) Snippet:
|
Hello @tim-weis, the debugger_visualizer tests did indeed fail after PR #2078 was opened. Since the debugger_visualizer tests were part of the github workflows, it actually stopped Kenny from being able to commit his change. I was able to publish two additional PRs #2077 to unblock his changes and ensure the HSTRING natvis was representative of the memory layout of the HSTRING type as opposed to relying on internal fields. Once #2077 was merged directly into master Kenny was able to update his branch and the tests succeeded. I hope this clarifies how the tests work and why they were still passing after the changes made in the PR you mentioned. |
As recently as #2819 I have been keeping those tests working. |
Thanks for the feedback. This has been rather insightful. I went ahead and did some more research. The TL;DR is: The First, though, the For reference, here's the full repro (slightly modified from my previous comment). Cargo.toml [package]
name = "win_nv"
version = "0.0.0"
edition = "2021"
[dependencies]
windows = { version = "0.52.0", features = [] } .cargo/config.toml [build]
# Request that visualizers are embedded into the PDB
rustflags = ["--cfg=windows_debugger_visualizer"] src/main.rs use windows::core::HSTRING;
#[inline(never)]
fn __break() {}
fn main() {
let empty = HSTRING::new();
println!("{empty}");
let hstring = HSTRING::from("This is an HSTRING");
println!("{hstring}");
__break();
} This is following a pattern I first discovered in Ridwan's debugger_test crate: It introduces a function ( With the crate set up the following command line launches right into the CDB debugger:
Once in the debugger, we can set the breakpoint, run to the checkpoint and inspect the
That explains why the tests are succeeding. Moving to WinDbg had some surprises, though: Setting the breakpoint the same way as in CDB behaved differently. The Once there, the debugger produced unexpected results for the
Can anyone please verify my observations? Rust: 1.75.0 (stable) While this is starting to feel like I'm losing my mind, here are a few more things I tried to make sure I'm looking at the same thing the debugger is:
None of the above had any observable effect so I'm confident that |
If you think there's an issue here that needs addressing, please hit the "reference in new issue" so we can track it. |
I am fighting GitHub's UI now. Apparently, I cannot create a new issue using the "Reference in new issue" option (the "Create issue" button is grayed out...). I'll just go through the manual process then. |
Done: #2836 |
This change adds Natvis visualizations for types in the
windows
crate to help improve the debugging experience on Windows.Natvis is a framework that can be used to specify how types should be viewed under a supported debugger, such as the Windows debugger (WinDbg) and the Visual Studio debugger.
The Rust compiler does have Natvis support for some types, but this is limited to some of the core libraries and not supported for external crates.
rust-lang/rfcs#3191 proposes adding support for embedding debugging visualizations such as Natvis in a Rust crate. This RFC has been approved, merged and implemented.
This PR adds:
windows::core
module.windows
crate.windows
crate to enable the unstable debugger_visualizer Rust feature.Fixes: #2022