Skip to content

Commit 08b1717

Browse files
authored
Rollup merge of #79184 - nanguye2496:nanguye2496/fix_slice_and_str_type_name, r=varkor
Stop adding '*' at the end of slice and str typenames for MSVC case When computing debug info for MSVC debuggers, Rust compiler emits C++ style type names for compatibility with .natvis visualizers. All Ref types are treated as equivalences of C++ pointers in this process, and, as a result, their type names end with a '\*'. Since Slice and Str are treated as Ref by the compiler, their type names also end with a '\*'. This causes the .natvis engine for WinDbg fails to display data of Slice and Str objects. We addressed this problem simply by removing the '*' at the end of type names for Slice and Str types. Debug info in WinDbg before the fix: ![image](https://user-images.githubusercontent.com/74681961/99594120-9a4dcf80-29a7-11eb-8cce-aedaf1da6d21.png) Debug info in WinDbg after the fix: ![image](https://user-images.githubusercontent.com/74681961/99597173-717c0900-29ac-11eb-861e-98143a9177cf.png) This change has also been tested with debuggers for Visual Studio, VS Code C++ and VS Code LLDB to make sure that it does not affect the behavior of other kinds of debugger.
2 parents b565fe2 + 36e6aa0 commit 08b1717

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ pub fn push_debuginfo_type_name<'tcx>(
9494
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
9595

9696
if cpp_like_names {
97-
output.push('*');
97+
// Slices and `&str` are treated like C++ pointers when computing debug
98+
// info for MSVC debugger. However, adding '*' at the end of these types' names
99+
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these
100+
// types out to aid debugging in MSVC.
101+
match *inner_type.kind() {
102+
ty::Slice(_) | ty::Str => {}
103+
_ => output.push('*'),
104+
}
98105
}
99106
}
100107
ty::Array(inner_type, len) => {

0 commit comments

Comments
 (0)