rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.15k stars 12.8k forks source link

Incorrect HashMap visualization in WinDbg #82674

Open nanguye2496 opened 3 years ago

nanguye2496 commented 3 years ago

I tried to debug this program in WinDbg.

use std::fmt;

#[derive(PartialEq, Eq, Hash)]
struct Student {
    name: String,
    country: String,
}

impl fmt::Display for Student {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({}, {})", self.name, self.country)
    }
}

fn main() {
    use std::collections::HashMap;
    let mut map = HashMap::new();
    let s1 = Student { name: String::from("Tom"), country: String::from("UK") };
    let s2 = Student { name: String::from("Alex"), country: String::from("US")};
    map.insert(s1, 10);
    map.insert(s2, 8);
    for (k,v) in map.iter() {
        println!("{}, {}", k, v);
    }
}

When examining the variable map in WinDbg, I got this visualization: image

The screenshot illustrates two problems:

These two problems are filed under the same bug report since I've discovered that they can both be tied to the same cause - WinDbg's failure to perform the casting of base.table.ctrl.pointer to tuple&lt;$T1, $T2&gt;* in HashMap's natvis entry.

<Item Name="{((tuple&lt;$T1, $T2&gt;*)base.table.ctrl.pointer)[-(i + 1)].__0}">((tuple&lt;$T1, $T2&gt;*)base.table.ctrl.pointer)[-(i + 1)].__1</Item>

Meta

This bug is discovered on rustc 1.52.0-dev and WinDbg debugger engine version: 10.0.21306.10

nanguye2496 commented 3 years ago

I've attempted to remove the whitespace between $T1 and $T2. This fix does yield the correct visualization on WinDbg, but makes VSCode and VS C++ debuggers unable to visualize Rust HashMap. Since this bug is debugger specific, the proper solution should come from the WinDbg side.

ChrisDenton commented 1 year ago

Did this issue every get fixed on the WinDbg side?