summaryrefslogtreecommitdiffstats
path: root/src/etc/natvis/libstd.natvis
blob: 4371b9953181779ef464e5839af6ea13b2b720f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <!--
    std::collection::Hash* container visualizers

    Current std impls:
      std::collections::hash::set::HashSet<K, S>      is implemented in terms of...
      hashbrown::set::HashSet<K, S>                   is implemented in terms of...
      hashbrown::map::HashMap<K, V, S>                is implemented in terms of...
      hashbrown::raw::RawTable<(K, V)>

    Ideally, we'd teach rustc to scan dependencies/crates for .natvis files so
    the bulk of this could live alongside the hashbrown crate implementation,
    and std would just forward using e.g. <ExpandedItem>base</ExpandedItem>.

    However, Given that std...Hash*Set* is currently implemented in terms of
    hashbrown...Hash*Map*, which would visualize poorly, we want to customize the
    look/feel at the std type level *anyways*...

    References:
      https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/map.rs
      https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/set.rs
      https://github.com/rust-lang/hashbrown/blob/master/src/map.rs
      https://github.com/rust-lang/hashbrown/blob/master/src/set.rs
      https://github.com/rust-lang/hashbrown/blob/master/src/raw/mod.rs
  -->

  <Type Name="std::collections::hash::map::HashMap&lt;*,*,*&gt;">
    <DisplayString>{{ len={base.table.table.items} }}</DisplayString>
    <Expand>
      <Item Name="[len]">base.table.table.items</Item>
      <Item Name="[capacity]">base.table.table.items + base.table.table.growth_left</Item>
      <Item Name="[state]">base.hash_builder</Item>

      <CustomListItems>
        <Variable Name="i" InitialValue="0" />
        <Variable Name="n" InitialValue="base.table.table.items" />
        <Size>base.table.table.items</Size>
        <Loop>
          <Break Condition="n == 0" />
          <If Condition="(base.table.table.ctrl.pointer[i] &amp; 0x80) == 0">
            <!-- Bucket is populated -->
            <Exec>n--</Exec>
            <Item Name="{((tuple$&lt;$T1,$T2&gt;*)base.table.table.ctrl.pointer)[-(i + 1)].__0}">((tuple$&lt;$T1,$T2&gt;*)base.table.table.ctrl.pointer)[-(i + 1)].__1</Item>
          </If>
          <Exec>i++</Exec>
        </Loop>
      </CustomListItems>
    </Expand>
  </Type>

  <Type Name="std::collections::hash::set::HashSet&lt;*,*&gt;">
    <DisplayString>{{ len={base.map.table.table.items} }}</DisplayString>
    <Expand>
      <Item Name="[len]">base.map.table.table.items</Item>
      <Item Name="[capacity]">base.map.table.table.items + base.map.table.table.growth_left</Item>
      <Item Name="[state]">base.map.hash_builder</Item>

      <CustomListItems>
        <Variable Name="i" InitialValue="0" />
        <Variable Name="n" InitialValue="base.map.table.table.items" />
        <Size>base.map.table.table.items</Size>
        <Loop>
          <Break Condition="n == 0" />
          <If Condition="(base.map.table.table.ctrl.pointer[i] &amp; 0x80) == 0">
            <!-- Bucket is populated -->
            <Exec>n--</Exec>
            <Item>(($T1*)base.map.table.table.ctrl.pointer)[-(i + 1)]</Item>
          </If>
          <Exec>i++</Exec>
        </Loop>
      </CustomListItems>
    </Expand>
  </Type>

  <Type Name="std::ffi::c_str::CString">
    <DisplayString>{(char*)inner.data_ptr}</DisplayString>
    <Expand>
      <Synthetic Name="[chars]">
        <DisplayString>{(char*)inner.data_ptr}</DisplayString>
        <Expand>
          <ArrayItems>
            <Size>inner.length</Size>
            <ValuePointer>(char*)inner.data_ptr</ValuePointer>
          </ArrayItems>
        </Expand>
      </Synthetic>
    </Expand>
  </Type>

  <Type Name="std::ffi::c_str::CStr">
    <DisplayString>{(char*) inner}</DisplayString>
    <Expand>
      <Synthetic Name="[chars]">
        <DisplayString>{(char*) inner}</DisplayString>
        <Expand>
          <ArrayItems>
            <Size>strlen((char *) inner) + 1</Size>
            <ValuePointer>(char*)inner</ValuePointer>
          </ArrayItems>
        </Expand>
      </Synthetic>
    </Expand>
  </Type>

  <Type Name="std::ffi::os_str::OsString">
    <DisplayString>{(char*)inner.inner.bytes.buf.ptr.pointer.pointer,[inner.inner.bytes.len]}</DisplayString>
    <Expand>
      <Synthetic Name="[chars]">
        <DisplayString>{(char*)inner.inner.bytes.buf.ptr.pointer.pointer,[inner.inner.bytes.len]}</DisplayString>
        <Expand>
          <ArrayItems>
            <Size>inner.inner.bytes.len</Size>
            <ValuePointer>(char*)inner.inner.bytes.buf.ptr.pointer.pointer</ValuePointer>
          </ArrayItems>
        </Expand>
      </Synthetic>
    </Expand>
  </Type>
</AutoVisualizer>