Skip to content

Commit 084ac77

Browse files
authored
Rollup merge of rust-lang#73715 - MaulingMonkey:pr-natvis-tuples, r=Amanieu
debuginfo: Mangle tuples to be natvis friendly, typedef basic types These changes are meant to unblock rust-lang#70052 "Update hashbrown to 0.8.0" by allowing the use of `tuple<u64, u64>` as a .natvis expression in MSVC style debuggers (MSVC, WinDbg, CDB, etc.) * f8eb81b does the actual mangling of `(u64, u64)` -> `tuple<u64, 64>` * 24a728a allows `u64` to resolve (fixing `$T1` / `$T2` when used to visualize `HashMap<u64, u64, ...>`)
2 parents 90f1d72 + 24a728a commit 084ac77

File tree

7 files changed

+334
-3
lines changed

7 files changed

+334
-3
lines changed

src/etc/natvis/intrinsic.natvis

+124
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,128 @@
2121
</ArrayItems>
2222
</Expand>
2323
</Type>
24+
<Type Name="tuple&lt;&gt;">
25+
<DisplayString>()</DisplayString>
26+
</Type>
27+
<Type Name="tuple&lt;*&gt;">
28+
<DisplayString>({__0})</DisplayString>
29+
<Expand>
30+
<Item Name="[0]">__0</Item>
31+
</Expand>
32+
</Type>
33+
<Type Name="tuple&lt;*,*&gt;">
34+
<DisplayString>({__0}, {__1})</DisplayString>
35+
<Expand>
36+
<Item Name="[0]">__0</Item>
37+
<Item Name="[1]">__1</Item>
38+
</Expand>
39+
</Type>
40+
<Type Name="tuple&lt;*,*,*&gt;">
41+
<DisplayString>({__0}, {__1}, {__2})</DisplayString>
42+
<Expand>
43+
<Item Name="[0]">__0</Item>
44+
<Item Name="[1]">__1</Item>
45+
<Item Name="[2]">__2</Item>
46+
</Expand>
47+
</Type>
48+
<Type Name="tuple&lt;*,*,*,*&gt;">
49+
<DisplayString>({__0}, {__1}, {__2}, {__3})</DisplayString>
50+
<Expand>
51+
<Item Name="[0]">__0</Item>
52+
<Item Name="[1]">__1</Item>
53+
<Item Name="[2]">__2</Item>
54+
<Item Name="[3]">__3</Item>
55+
</Expand>
56+
</Type>
57+
<Type Name="tuple&lt;*,*,*,*,*&gt;">
58+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4})</DisplayString>
59+
<Expand>
60+
<Item Name="[0]">__0</Item>
61+
<Item Name="[1]">__1</Item>
62+
<Item Name="[2]">__2</Item>
63+
<Item Name="[3]">__3</Item>
64+
<Item Name="[4]">__4</Item>
65+
</Expand>
66+
</Type>
67+
<Type Name="tuple&lt;*,*,*,*,*,*&gt;">
68+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4}, {__5})</DisplayString>
69+
<Expand>
70+
<Item Name="[0]">__0</Item>
71+
<Item Name="[1]">__1</Item>
72+
<Item Name="[2]">__2</Item>
73+
<Item Name="[3]">__3</Item>
74+
<Item Name="[4]">__4</Item>
75+
<Item Name="[5]">__5</Item>
76+
</Expand>
77+
</Type>
78+
<Type Name="tuple&lt;*,*,*,*,*,*,*&gt;">
79+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4}, {__5}, {__6})</DisplayString>
80+
<Expand>
81+
<Item Name="[0]">__0</Item>
82+
<Item Name="[1]">__1</Item>
83+
<Item Name="[2]">__2</Item>
84+
<Item Name="[3]">__3</Item>
85+
<Item Name="[4]">__4</Item>
86+
<Item Name="[5]">__5</Item>
87+
<Item Name="[6]">__6</Item>
88+
</Expand>
89+
</Type>
90+
<Type Name="tuple&lt;*,*,*,*,*,*,*,*&gt;">
91+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4}, {__5}, {__6}, {__7})</DisplayString>
92+
<Expand>
93+
<Item Name="[0]">__0</Item>
94+
<Item Name="[1]">__1</Item>
95+
<Item Name="[2]">__2</Item>
96+
<Item Name="[3]">__3</Item>
97+
<Item Name="[4]">__4</Item>
98+
<Item Name="[5]">__5</Item>
99+
<Item Name="[6]">__6</Item>
100+
<Item Name="[7]">__7</Item>
101+
</Expand>
102+
</Type>
103+
<Type Name="tuple&lt;*,*,*,*,*,*,*,*,*&gt;">
104+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4}, {__5}, {__6}, {__7}, {__8})</DisplayString>
105+
<Expand>
106+
<Item Name="[0]">__0</Item>
107+
<Item Name="[1]">__1</Item>
108+
<Item Name="[2]">__2</Item>
109+
<Item Name="[3]">__3</Item>
110+
<Item Name="[4]">__4</Item>
111+
<Item Name="[5]">__5</Item>
112+
<Item Name="[6]">__6</Item>
113+
<Item Name="[7]">__7</Item>
114+
<Item Name="[8]">__8</Item>
115+
</Expand>
116+
</Type>
117+
<Type Name="tuple&lt;*,*,*,*,*,*,*,*,*,*&gt;">
118+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4}, {__5}, {__6}, {__7}, {__8}, {__9})</DisplayString>
119+
<Expand>
120+
<Item Name="[0]">__0</Item>
121+
<Item Name="[1]">__1</Item>
122+
<Item Name="[2]">__2</Item>
123+
<Item Name="[3]">__3</Item>
124+
<Item Name="[4]">__4</Item>
125+
<Item Name="[5]">__5</Item>
126+
<Item Name="[6]">__6</Item>
127+
<Item Name="[7]">__7</Item>
128+
<Item Name="[8]">__8</Item>
129+
<Item Name="[9]">__9</Item>
130+
</Expand>
131+
</Type>
132+
<Type Name="tuple&lt;*,*,*,*,*,*,*,*,*,*,*&gt;">
133+
<DisplayString>({__0}, {__1}, {__2}, {__3}, {__4}, {__5}, {__6}, {__7}, {__8}, {__9}, ...)</DisplayString>
134+
<Expand>
135+
<Item Name="[0]">__0</Item>
136+
<Item Name="[1]">__1</Item>
137+
<Item Name="[2]">__2</Item>
138+
<Item Name="[3]">__3</Item>
139+
<Item Name="[4]">__4</Item>
140+
<Item Name="[5]">__5</Item>
141+
<Item Name="[6]">__6</Item>
142+
<Item Name="[7]">__7</Item>
143+
<Item Name="[8]">__8</Item>
144+
<Item Name="[9]">__9</Item>
145+
<Synthetic Name="[...]"><DisplayString>...</DisplayString></Synthetic>
146+
</Expand>
147+
</Type>
24148
</AutoVisualizer>

src/librustc_codegen_llvm/debuginfo/metadata.rs

+71-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::llvm::debuginfo::{
1919
use crate::value::Value;
2020

2121
use log::debug;
22+
use rustc_ast::ast;
2223
use rustc_codegen_ssa::traits::*;
2324
use rustc_data_structures::const_cstr;
2425
use rustc_data_structures::fingerprint::Fingerprint;
@@ -827,14 +828,60 @@ fn file_metadata_raw(
827828
}
828829
}
829830

831+
trait MsvcBasicName {
832+
fn msvc_basic_name(self) -> &'static str;
833+
}
834+
835+
impl MsvcBasicName for ast::IntTy {
836+
fn msvc_basic_name(self) -> &'static str {
837+
match self {
838+
ast::IntTy::Isize => "ptrdiff_t",
839+
ast::IntTy::I8 => "__int8",
840+
ast::IntTy::I16 => "__int16",
841+
ast::IntTy::I32 => "__int32",
842+
ast::IntTy::I64 => "__int64",
843+
ast::IntTy::I128 => "__int128",
844+
}
845+
}
846+
}
847+
848+
impl MsvcBasicName for ast::UintTy {
849+
fn msvc_basic_name(self) -> &'static str {
850+
match self {
851+
ast::UintTy::Usize => "size_t",
852+
ast::UintTy::U8 => "unsigned __int8",
853+
ast::UintTy::U16 => "unsigned __int16",
854+
ast::UintTy::U32 => "unsigned __int32",
855+
ast::UintTy::U64 => "unsigned __int64",
856+
ast::UintTy::U128 => "unsigned __int128",
857+
}
858+
}
859+
}
860+
861+
impl MsvcBasicName for ast::FloatTy {
862+
fn msvc_basic_name(self) -> &'static str {
863+
match self {
864+
ast::FloatTy::F32 => "float",
865+
ast::FloatTy::F64 => "double",
866+
}
867+
}
868+
}
869+
830870
fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
831871
debug!("basic_type_metadata: {:?}", t);
832872

873+
// When targeting MSVC, emit MSVC style type names for compatibility with
874+
// .natvis visualizers (and perhaps other existing native debuggers?)
875+
let msvc_like_names = cx.tcx.sess.target.target.options.is_like_msvc;
876+
833877
let (name, encoding) = match t.kind {
834878
ty::Never => ("!", DW_ATE_unsigned),
835879
ty::Tuple(ref elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
836880
ty::Bool => ("bool", DW_ATE_boolean),
837881
ty::Char => ("char", DW_ATE_unsigned_char),
882+
ty::Int(int_ty) if msvc_like_names => (int_ty.msvc_basic_name(), DW_ATE_signed),
883+
ty::Uint(uint_ty) if msvc_like_names => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
884+
ty::Float(float_ty) if msvc_like_names => (float_ty.msvc_basic_name(), DW_ATE_float),
838885
ty::Int(int_ty) => (int_ty.name_str(), DW_ATE_signed),
839886
ty::Uint(uint_ty) => (uint_ty.name_str(), DW_ATE_unsigned),
840887
ty::Float(float_ty) => (float_ty.name_str(), DW_ATE_float),
@@ -851,7 +898,30 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
851898
)
852899
};
853900

854-
ty_metadata
901+
if !msvc_like_names {
902+
return ty_metadata;
903+
}
904+
905+
let typedef_name = match t.kind {
906+
ty::Int(int_ty) => int_ty.name_str(),
907+
ty::Uint(uint_ty) => uint_ty.name_str(),
908+
ty::Float(float_ty) => float_ty.name_str(),
909+
_ => return ty_metadata,
910+
};
911+
912+
let typedef_metadata = unsafe {
913+
llvm::LLVMRustDIBuilderCreateTypedef(
914+
DIB(cx),
915+
ty_metadata,
916+
typedef_name.as_ptr().cast(),
917+
typedef_name.len(),
918+
unknown_file_metadata(cx),
919+
0,
920+
None,
921+
)
922+
};
923+
924+
typedef_metadata
855925
}
856926

857927
fn foreign_type_metadata(

src/librustc_codegen_llvm/llvm/ffi.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,16 @@ extern "C" {
17031703
Encoding: c_uint,
17041704
) -> &'a DIBasicType;
17051705

1706+
pub fn LLVMRustDIBuilderCreateTypedef(
1707+
Builder: &DIBuilder<'a>,
1708+
Type: &'a DIBasicType,
1709+
Name: *const c_char,
1710+
NameLen: size_t,
1711+
File: &'a DIFile,
1712+
LineNo: c_uint,
1713+
Scope: Option<&'a DIScope>,
1714+
) -> &'a DIDerivedType;
1715+
17061716
pub fn LLVMRustDIBuilderCreatePointerType(
17071717
Builder: &DIBuilder<'a>,
17081718
PointeeTy: &'a DIType,

src/librustc_codegen_ssa/debuginfo/type_names.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ pub fn push_debuginfo_type_name<'tcx>(
4747
push_type_params(tcx, substs, output, visited);
4848
}
4949
ty::Tuple(component_types) => {
50-
output.push('(');
50+
if cpp_like_names {
51+
output.push_str("tuple<");
52+
} else {
53+
output.push('(');
54+
}
55+
5156
for component_type in component_types {
5257
push_debuginfo_type_name(tcx, component_type.expect_ty(), true, output, visited);
5358
output.push_str(", ");
@@ -56,7 +61,12 @@ pub fn push_debuginfo_type_name<'tcx>(
5661
output.pop();
5762
output.pop();
5863
}
59-
output.push(')');
64+
65+
if cpp_like_names {
66+
output.push('>');
67+
} else {
68+
output.push(')');
69+
}
6070
}
6171
ty::RawPtr(ty::TypeAndMut { ty: inner_type, mutbl }) => {
6272
if !cpp_like_names {

src/rustllvm/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,14 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateBasicType(
762762
return wrap(Builder->createBasicType(StringRef(Name, NameLen), SizeInBits, Encoding));
763763
}
764764

765+
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTypedef(
766+
LLVMRustDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen,
767+
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope) {
768+
return wrap(Builder->createTypedef(
769+
unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File),
770+
LineNo, unwrap<DIScope>(Scope)));
771+
}
772+
765773
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
766774
LLVMRustDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
767775
uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,

src/test/debuginfo/simple-tuple.rs

+42
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,48 @@
123123
// lldbg-check:[...]$6 = { 0 = 15 1 = 16 }
124124
// lldbr-check:((i32, i16)) paddingAtEnd = { 0 = 15 1 = 16 }
125125

126+
127+
// === CDB TESTS ==================================================================================
128+
129+
// cdb-command: g
130+
131+
// cdb-command:dx noPadding8,d
132+
// cdb-check:noPadding8,d [...]: (-100, 100) [Type: tuple<i8, u8>]
133+
// cdb-check:[...][0] : -100 [Type: [...]]
134+
// cdb-check:[...][1] : 100 [Type: [...]]
135+
// cdb-command:dx noPadding16,d
136+
// cdb-check:noPadding16,d [...]: (0, 1, 2) [Type: tuple<i16, i16, u16>]
137+
// cdb-check:[...][0] : 0 [Type: [...]]
138+
// cdb-check:[...][1] : 1 [Type: [...]]
139+
// cdb-check:[...][2] : 2 [Type: [...]]
140+
// cdb-command:dx noPadding32,d
141+
// cdb-check:noPadding32,d [...]: (3, 4.5[...], 5) [Type: tuple<i32, f32, u32>]
142+
// cdb-check:[...][0] : 3 [Type: [...]]
143+
// cdb-check:[...][1] : 4.5[...] [Type: [...]]
144+
// cdb-check:[...][2] : 5 [Type: [...]]
145+
// cdb-command:dx noPadding64,d
146+
// cdb-check:noPadding64,d [...]: (6, 7.5[...], 8) [Type: tuple<i64, f64, u64>]
147+
// cdb-check:[...][0] : 6 [Type: [...]]
148+
// cdb-check:[...][1] : 7.500000 [Type: [...]]
149+
// cdb-check:[...][2] : 8 [Type: [...]]
150+
151+
// cdb-command:dx internalPadding1,d
152+
// cdb-check:internalPadding1,d [...]: (9, 10) [Type: tuple<i16, i32>]
153+
// cdb-check:[...][0] : 9 [Type: short]
154+
// cdb-check:[...][1] : 10 [Type: int]
155+
// cdb-command:dx internalPadding2,d
156+
// cdb-check:internalPadding2,d [...]: (11, 12, 13, 14) [Type: tuple<i16, i32, u32, u64>]
157+
// cdb-check:[...][0] : 11 [Type: [...]]
158+
// cdb-check:[...][1] : 12 [Type: [...]]
159+
// cdb-check:[...][2] : 13 [Type: [...]]
160+
// cdb-check:[...][3] : 14 [Type: [...]]
161+
162+
// cdb-command:dx paddingAtEnd,d
163+
// cdb-check:paddingAtEnd,d [...]: (15, 16) [Type: tuple<i32, i16>]
164+
// cdb-check:[...][0] : 15 [Type: [...]]
165+
// cdb-check:[...][1] : 16 [Type: [...]]
166+
167+
126168
#![allow(unused_variables)]
127169
#![allow(dead_code)]
128170
#![feature(omit_gdb_pretty_printer_section)]

0 commit comments

Comments
 (0)