4

Github Improve debugging experience for enums on windows-msvc by wesleywiser · P...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/85292
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Member

wesleywiser commented on May 14

This PR makes significant improvements over the status quo of debugging enums on the windows-msvc platform with either WinDbg or Visual Studio in three ways:

  1. Improves the debugger experience for directly tagged enums.
  2. Fixes a bug which caused the debugger to sometimes show the wrong debug info for niche layout enums. For example, Option<&u32> could sometimes use the debug info for Option<&f64> instead leading to nonsensical variable values in the debugger.
  3. Significantly improves the debugger experience for niche-layout enums.

Let's look at a few examples:

pub enum CStyleEnum {
    Base = 2,
    Exponent = 16,
}

pub enum NicheLayoutEnum {
    Tag1,
    Data { my_data: CStyleEnum },
    Tag2,
    Tag3,
    Tag4,
}

pub enum OtherEnum<T> {
    Case1(T),
    Case2(T),
}

fn main() {
    let a = Some(CStyleEnum::Base);
    let b = Option::<CStyleEnum>::None;
    let c = NicheLayoutEnum::Tag1;
    let d = NicheLayoutEnum::Data { my_data: CStyleEnum::Exponent };
    let e = NicheLayoutEnum::Tag2;
    let f = Some(&1u32);
    let g = Option::<&'static u32>::None;
    let h = Some(&2u64);
    let i = Option::<&'static u64>::None;
    let j = Some(12u32);
    let k = Option::<u32>::None;
    let l = Some(12.34f64);
    let m = Option::<f64>::None;
    let n = CStyleEnum::Base;
    let o = CStyleEnum::Exponent;
    let p = Some("IAMA optional string!".to_string());
    let q = OtherEnum::Case1(42u32);
}

This is what WinDbg Preview shows using the latest rustc nightly:

Most of the variables don't show a meaningful value expect for a few cases that we have targeted natvis definitions covering. Even worse, drilling into many of these variables shows information that can be difficult to interpret without an understanding of the layout of Rust types:

With the changes in this PR, we're able to write two natvis definitions that cover all enum cases generally. After building with these changes, WinDbg now shows this instead:

Drilling into the same variables, we can see much more useful information:

Fixes #84670
Fixes #84671


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK