Skip to content

Commit 0cd2dd7

Browse files
[debuginfo] Make debuginfo type names for slices and str consistent.
Before this PR, the compiler would emit the debuginfo name `slice$<T>` for all kinds of slices, regardless of whether they are behind a reference or not and regardless of the kind of reference. As a consequence, the types `Foo<&[T]>`, `Foo<[T]>`, and `Foo<&mut [T]>` would end up with the same type name `Foo<slice$<T> >` in debuginfo, making it impossible to disambiguate between them by name. Similarly, `&str` would get the name `str` in debuginfo, so the debuginfo name for `Foo<str>` and `Foo<&str>` would be the same. In contrast, `*const [bool]` and `*mut [bool]` would be `ptr_const$<slice$<bool> >` and `ptr_mut$<slice$<bool> >`, i.e. the encoding does not lose information about the type. This PR removes all special handling for slices and `str`. The types `&[bool]`, `&mut [bool]`, and `&str` thus get the names `ref$<slice2$<bool> >`, `ref_mut$<slice2$<bool> >`, and `ref$<str$>` respectively -- as one would expect.
1 parent 1481fd9 commit 0cd2dd7

File tree

11 files changed

+56
-48
lines changed

11 files changed

+56
-48
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ fn push_debuginfo_type_name<'tcx>(
5959
match *t.kind() {
6060
ty::Bool => output.push_str("bool"),
6161
ty::Char => output.push_str("char"),
62-
ty::Str => output.push_str("str"),
62+
ty::Str => {
63+
if cpp_like_debuginfo {
64+
output.push_str("str$")
65+
} else {
66+
output.push_str("str")
67+
}
68+
}
6369
ty::Never => {
6470
if cpp_like_debuginfo {
6571
output.push_str("never$");
@@ -152,25 +158,19 @@ fn push_debuginfo_type_name<'tcx>(
152158
}
153159
}
154160
ty::Ref(_, inner_type, mutbl) => {
155-
// Slices and `&str` are treated like C++ pointers when computing debug
156-
// info for MSVC debugger. However, wrapping these types' names in a synthetic type
157-
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these
158-
// types out to aid debugging in MSVC.
159-
let is_slice_or_str = matches!(*inner_type.kind(), ty::Slice(_) | ty::Str);
160-
161-
if !cpp_like_debuginfo {
162-
output.push('&');
163-
output.push_str(mutbl.prefix_str());
164-
} else if !is_slice_or_str {
161+
if cpp_like_debuginfo {
165162
match mutbl {
166163
Mutability::Not => output.push_str("ref$<"),
167164
Mutability::Mut => output.push_str("ref_mut$<"),
168165
}
166+
} else {
167+
output.push('&');
168+
output.push_str(mutbl.prefix_str());
169169
}
170170

171171
push_debuginfo_type_name(tcx, inner_type, qualified, output, visited);
172172

173-
if cpp_like_debuginfo && !is_slice_or_str {
173+
if cpp_like_debuginfo {
174174
push_close_angle_bracket(cpp_like_debuginfo, output);
175175
}
176176
}
@@ -195,7 +195,7 @@ fn push_debuginfo_type_name<'tcx>(
195195
}
196196
ty::Slice(inner_type) => {
197197
if cpp_like_debuginfo {
198-
output.push_str("slice$<");
198+
output.push_str("slice2$<");
199199
} else {
200200
output.push('[');
201201
}

src/etc/natvis/intrinsic.natvis

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
3-
<Type Name="str">
3+
<Type Name="ref$&lt;str$&gt;">
4+
<AlternativeType Name="ref_mut$&lt;str$&gt;" />
5+
<AlternativeType Name="ptr_const$&lt;str$&gt;" />
6+
<AlternativeType Name="ptr_mut$&lt;str$&gt;" />
7+
48
<DisplayString>{(char*)data_ptr,[length]s8}</DisplayString>
59
<StringView>(char*)data_ptr,[length]s8</StringView>
610
<Expand>
@@ -15,7 +19,11 @@
1519
</Synthetic>
1620
</Expand>
1721
</Type>
18-
<Type Name="slice$&lt;*&gt;">
22+
<Type Name="ref$&lt;slice2$&lt;*&gt; &gt;">
23+
<AlternativeType Name="ref_mut$&lt;slice2$&lt;*&gt; &gt;" />
24+
<AlternativeType Name="ptr_const$&lt;slice2$&lt;*&gt; &gt;" />
25+
<AlternativeType Name="ptr_mut$&lt;slice2$&lt;*&gt; &gt;" />
26+
1927
<DisplayString>{{ len={length} }}</DisplayString>
2028
<Expand>
2129
<Item Name="[len]" ExcludeView="simple">length</Item>

src/etc/natvis/liballoc.natvis

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</Type>
8686

8787
<!-- alloc::rc::Rc<[T]> -->
88-
<Type Name="alloc::rc::Rc&lt;slice$&lt;*&gt; &gt;">
88+
<Type Name="alloc::rc::Rc&lt;slice2$&lt;*&gt; &gt;">
8989
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
9090
<Expand>
9191
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
@@ -115,7 +115,7 @@
115115
</Type>
116116

117117
<!-- alloc::rc::Weak<[T]> -->
118-
<Type Name="alloc::rc::Weak&lt;slice$&lt;*&gt; &gt;">
118+
<Type Name="alloc::rc::Weak&lt;slice2$&lt;*&gt; &gt;">
119119
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
120120
<Expand>
121121
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
@@ -144,7 +144,7 @@
144144
</Type>
145145

146146
<!-- alloc::sync::Arc<[T]> -->
147-
<Type Name="alloc::sync::Arc&lt;slice$&lt;*&gt; &gt;">
147+
<Type Name="alloc::sync::Arc&lt;slice2$&lt;*&gt; &gt;">
148148
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
149149
<Expand>
150150
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
@@ -173,7 +173,7 @@
173173
</Type>
174174

175175
<!-- alloc::sync::Weak<[T]> -->
176-
<Type Name="alloc::sync::Weak&lt;slice$&lt;*&gt; &gt;">
176+
<Type Name="alloc::sync::Weak&lt;slice2$&lt;*&gt; &gt;">
177177
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
178178
<Expand>
179179
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>

src/test/debuginfo/basic-types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
// gdbg-check:$15 = {data_ptr = [...] "Hello, World!", length = 13}
4848
// gdbr-check:$15 = "Hello, World!"
4949

50-
5150
// === LLDB TESTS ==================================================================================
5251

5352
// lldb-command:run
@@ -96,7 +95,6 @@
9695
// lldbg-check:[...]$12 = 3.5
9796
// lldbr-check:(f64) f64 = 3.5
9897

99-
10098
// === CDB TESTS ===================================================================================
10199

102100
// cdb-command:g
@@ -131,7 +129,7 @@
131129
// cdb-command:.enable_unicode 1
132130
// FIXME(#88840): The latest version of the Windows SDK broke the visualizer for str.
133131
// cdb-command:dx s
134-
// cdb-check:s : [...] [Type: str]
132+
// cdb-check:s : [...] [Type: ref$<str$>]
135133

136134
#![allow(unused_variables)]
137135
#![feature(omit_gdb_pretty_printer_section)]
@@ -156,4 +154,6 @@ fn main() {
156154
_zzz(); // #break
157155
}
158156

159-
fn _zzz() {()}
157+
fn _zzz() {
158+
()
159+
}

src/test/debuginfo/msvc-pretty-enums.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@
116116
// cdb-check: niche_w_fields_3_niche5,d : F [Type: enum2$<msvc_pretty_enums::NicheLayoutWithFields3>]
117117

118118
// cdb-command: dx -r3 niche_w_fields_std_result_ok,d
119-
// cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
120-
// cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>]
119+
// cdb-check: niche_w_fields_std_result_ok,d : Ok [Type: enum2$<core::result::Result<alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>,u64> >]
120+
// cdb-check: [+0x[...]] __0 [Type: alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>]
121121
// cdb-check: [+0x[...]] data_ptr : [...]
122122
// cdb-check: [+0x[...]] length : 3 [...]
123123

124124
// cdb-command: dx -r3 niche_w_fields_std_result_err,d
125-
// cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$<core::result::Result<alloc::boxed::Box<slice$<u8>,alloc::alloc::Global>,u64> >]
125+
// cdb-check: niche_w_fields_std_result_err,d : Err [Type: enum2$<core::result::Result<alloc::boxed::Box<slice2$<u8>,alloc::alloc::Global>,u64> >]
126126
// cdb-check: [+0x[...]] __0 : 789 [Type: unsigned __int64]
127127

128128
// cdb-command: dx -r2 arbitrary_discr1,d

src/test/debuginfo/msvc-scalarpair-params.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
// cdb-command: g
3939

4040
// cdb-command: dx s
41-
// cdb-check:s : "this is a static str" [Type: str]
41+
// cdb-check:s : "this is a static str" [Type: ref$<str$>]
4242
// cdb-check: [len] : 0x14 [Type: unsigned [...]]
4343
// cdb-check: [chars]
4444

4545
// cdb-command: g
4646

4747
// cdb-command: dx s
48-
// cdb-check:s : { len=0x5 } [Type: slice$<u8>]
48+
// cdb-check:s : { len=0x5 } [Type: ref$<slice2$<u8> >]
4949
// cdb-check: [len] : 0x5 [Type: unsigned [...]]
5050
// cdb-check: [0] : 0x1 [Type: unsigned char]
5151
// cdb-check: [1] : 0x2 [Type: unsigned char]

src/test/debuginfo/pretty-std.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
// cdb-command: g
7070

7171
// cdb-command: dx slice,d
72-
// cdb-check:slice,d : { len=4 } [Type: slice$<i32>]
72+
// cdb-check:slice,d : { len=4 } [Type: ref$<slice2$<i32> >]
7373
// cdb-check: [len] : 4 [Type: [...]]
7474
// cdb-check: [0] : 0 [Type: int]
7575
// cdb-check: [1] : 1 [Type: int]
@@ -86,7 +86,7 @@
8686
// cdb-check: [3] : 7 [Type: unsigned __int64]
8787

8888
// cdb-command: dx str_slice
89-
// cdb-check:str_slice : "IAMA string slice!" [Type: str]
89+
// cdb-check:str_slice : "IAMA string slice!" [Type: ref$<str$>]
9090

9191
// cdb-command: dx string
9292
// cdb-check:string : "IAMA string!" [Type: [...]::String]

src/test/debuginfo/rc_arc.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
5858

5959
// cdb-command:dx slice_rc,d
60-
// cdb-check:slice_rc,d : { len=3 } [Type: alloc::rc::Rc<slice$<u32> >]
60+
// cdb-check:slice_rc,d : { len=3 } [Type: alloc::rc::Rc<slice2$<u32> >]
6161
// cdb-check: [Length] : 3 [Type: [...]]
6262
// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>]
6363
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
@@ -66,7 +66,7 @@
6666
// cdb-check: [2] : 3 [Type: u32]
6767

6868
// cdb-command:dx slice_rc_weak,d
69-
// cdb-check:slice_rc_weak,d : { len=3 } [Type: alloc::rc::Weak<slice$<u32> >]
69+
// cdb-check:slice_rc_weak,d : { len=3 } [Type: alloc::rc::Weak<slice2$<u32> >]
7070
// cdb-check: [Length] : 3 [Type: [...]]
7171
// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>]
7272
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
@@ -85,7 +85,7 @@
8585
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
8686

8787
// cdb-command:dx slice_arc,d
88-
// cdb-check:slice_arc,d : { len=3 } [Type: alloc::sync::Arc<slice$<u32> >]
88+
// cdb-check:slice_arc,d : { len=3 } [Type: alloc::sync::Arc<slice2$<u32> >]
8989
// cdb-check: [Length] : 3 [Type: [...]]
9090
// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
9191
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
@@ -94,7 +94,7 @@
9494
// cdb-check: [2] : 6 [Type: u32]
9595

9696
// cdb-command:dx slice_arc_weak,d
97-
// cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice$<u32> >]
97+
// cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice2$<u32> >]
9898
// cdb-check: [Length] : 3 [Type: [...]]
9999
// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
100100
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]

src/test/debuginfo/result-types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// cdb-command: g
88

99
// cdb-command: dx x,d
10-
// cdb-check:x,d : Ok [Type: enum2$<core::result::Result<i32,str> >]
10+
// cdb-check:x,d : Ok [Type: enum2$<core::result::Result<i32,ref$<str$> > >]
1111
// cdb-check: [...] __0 : -3 [Type: int]
1212

1313
// cdb-command: dx y
14-
// cdb-check:y : Err [Type: enum2$<core::result::Result<i32,str> >]
15-
// cdb-check: [...] __0 : "Some error message" [Type: str]
14+
// cdb-check:y : Err [Type: enum2$<core::result::Result<i32,ref$<str$> > >]
15+
// cdb-check: [...] __0 : "Some error message" [Type: ref$<str$>]
1616

1717
fn main() {
1818
let x: Result<i32, &str> = Ok(-3);

src/test/debuginfo/type-names.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
// gdb-check:type = &[usize]
9696

9797
// gdb-command:whatis slice2
98-
// gdb-check:type = &[type_names::mod1::Enum2]
98+
// gdb-check:type = &mut [type_names::mod1::Enum2]
9999

100100
// TRAITS
101101
// gdb-command:whatis box_trait
@@ -218,8 +218,8 @@
218218
// cdb-check:struct alloc::vec::Vec<usize,alloc::alloc::Global> vec1 = [...]
219219
// cdb-check:struct alloc::vec::Vec<enum2$<type_names::mod1::Enum2>,alloc::alloc::Global> vec2 = [...]
220220
// cdb-command:dv /t slice*
221-
// cdb-check:struct slice$<usize> slice1 = [...]
222-
// cdb-check:struct slice$<enum2$<type_names::mod1::Enum2> > slice2 = [...]
221+
// cdb-check:struct ref$<slice2$<usize> > slice1 = [...]
222+
// cdb-check:struct ref_mut$<slice2$<enum2$<type_names::mod1::Enum2> > > slice2 = [...]
223223

224224
// TRAITS
225225
// cdb-command:dv /t *_trait
@@ -417,8 +417,8 @@ fn main() {
417417

418418
let vec1 = vec![0_usize, 2, 3];
419419
let slice1 = &*vec1;
420-
let vec2 = vec![mod1::Enum2::Variant2(Struct1)];
421-
let slice2 = &*vec2;
420+
let mut vec2 = vec![mod1::Enum2::Variant2(Struct1)];
421+
let slice2 = &mut *vec2;
422422

423423
// Trait Objects
424424
let box_trait = Box::new(0_isize) as Box<dyn Trait1>;

src/test/debuginfo/unsized.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232

3333
// cdb-command: g
3434
// cdb-command:dx a
35-
// cdb-check:a [Type: ref$<unsized::Foo<slice$<u8> > >]
36-
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: unsized::Foo<slice$<u8> > *]
35+
// cdb-check:a [Type: ref$<unsized::Foo<slice2$<u8> > >]
36+
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: unsized::Foo<slice2$<u8> > *]
3737
// cdb-check: [...] length : 0x4 [Type: unsigned [...]int[...]
3838

3939
// cdb-command:dx b
40-
// cdb-check:b [Type: ref$<unsized::Foo<unsized::Foo<slice$<u8> > > >]
41-
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: unsized::Foo<unsized::Foo<slice$<u8> > > *]
40+
// cdb-check:b [Type: ref$<unsized::Foo<unsized::Foo<slice2$<u8> > > >]
41+
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: unsized::Foo<unsized::Foo<slice2$<u8> > > *]
4242
// cdb-check: [...] length : 0x4 [Type: unsigned [...]int[...]
4343

4444
// cdb-command:dx c
@@ -53,8 +53,8 @@
5353
// cdb-check:[...] vtable : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
5454

5555
// cdb-command:dx tuple_slice
56-
// cdb-check:tuple_slice [Type: ref$<tuple$<i32,i32,slice$<i32> > >]
57-
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: tuple$<i32,i32,slice$<i32> > *]
56+
// cdb-check:tuple_slice [Type: ref$<tuple$<i32,i32,slice2$<i32> > >]
57+
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: tuple$<i32,i32,slice2$<i32> > *]
5858
// cdb-check: [...] length : 0x2 [Type: unsigned [...]int[...]
5959

6060
// cdb-command:dx tuple_dyn

0 commit comments

Comments
 (0)