Skip to content

Commit eca8599

Browse files
committed
Require type_map::stub callers to supply file information
This change attaches file information (`DIFile` reference and line number) to struct debug info nodes. Before: ``` ; foo.ll ... !5 = !DIFile(filename: "<unknown>", directory: "") ... !16 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", scope: !2, file: !5, size: 32, align: 32, elements: !17, templateParams: !19, identifier: "4cb373851db92e732c4cb5651b886dd0") ... ``` After: ``` ; foo.ll ... !3 = !DIFile(filename: "foo.rs", directory: "/home/matt/src/rust98678", checksumkind: CSK_SHA1, checksum: "bcb9f08512c8f3b8181ef4726012bc6807bc9be4") ... !16 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", scope: !2, file: !3, line: 3, size: 32, align: 32, elements: !17, templateParams: !19, identifier: "9e5968c7af39c148acb253912b7f409f") ... ``` Fixes rust-lang#98678
1 parent 21f6839 commit eca8599

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+25
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
213213
Stub::Struct,
214214
unique_type_id,
215215
&ptr_type_debuginfo_name,
216+
unknown_file_metadata(cx),
217+
UNKNOWN_LINE_NUMBER,
216218
cx.size_and_align_of(ptr_type),
217219
NO_SCOPE_METADATA,
218220
DIFlags::FlagZero,
@@ -367,6 +369,8 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
367369
Stub::Struct,
368370
unique_type_id,
369371
&type_name,
372+
unknown_file_metadata(cx),
373+
UNKNOWN_LINE_NUMBER,
370374
cx.size_and_align_of(dyn_type),
371375
NO_SCOPE_METADATA,
372376
DIFlags::FlagZero,
@@ -748,6 +752,8 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
748752
Stub::Struct,
749753
unique_type_id,
750754
&compute_debuginfo_type_name(cx.tcx, t, false),
755+
unknown_file_metadata(cx),
756+
UNKNOWN_LINE_NUMBER,
751757
cx.size_and_align_of(t),
752758
Some(get_namespace_for_item(cx, def_id)),
753759
DIFlags::FlagZero,
@@ -978,13 +984,24 @@ fn build_struct_type_di_node<'ll, 'tcx>(
978984
let struct_type_and_layout = cx.layout_of(struct_type);
979985
let variant_def = adt_def.non_enum_variant();
980986

987+
let tcx = cx.tcx;
988+
let struct_span = tcx.def_span(adt_def.did());
989+
let (file_metadata, line_number) = if !struct_span.is_dummy() {
990+
let loc = cx.lookup_debug_loc(struct_span.lo());
991+
(file_metadata(cx, &loc.file), loc.line)
992+
} else {
993+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
994+
};
995+
981996
type_map::build_type_with_children(
982997
cx,
983998
type_map::stub(
984999
cx,
9851000
Stub::Struct,
9861001
unique_type_id,
9871002
&compute_debuginfo_type_name(cx.tcx, struct_type, false),
1003+
file_metadata,
1004+
line_number,
9881005
size_and_align_of(struct_type_and_layout),
9891006
Some(containing_scope),
9901007
DIFlags::FlagZero,
@@ -1095,6 +1112,8 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
10951112
Stub::Struct,
10961113
unique_type_id,
10971114
&type_name,
1115+
unknown_file_metadata(cx),
1116+
UNKNOWN_LINE_NUMBER,
10981117
size_and_align_of(tuple_type_and_layout),
10991118
NO_SCOPE_METADATA,
11001119
DIFlags::FlagZero,
@@ -1140,6 +1159,8 @@ fn build_closure_env_di_node<'ll, 'tcx>(
11401159
Stub::Struct,
11411160
unique_type_id,
11421161
&type_name,
1162+
unknown_file_metadata(cx),
1163+
UNKNOWN_LINE_NUMBER,
11431164
cx.size_and_align_of(closure_env_type),
11441165
Some(containing_scope),
11451166
DIFlags::FlagZero,
@@ -1171,6 +1192,8 @@ fn build_union_type_di_node<'ll, 'tcx>(
11711192
Stub::Union,
11721193
unique_type_id,
11731194
&type_name,
1195+
unknown_file_metadata(cx),
1196+
UNKNOWN_LINE_NUMBER,
11741197
size_and_align_of(union_ty_and_layout),
11751198
Some(containing_scope),
11761199
DIFlags::FlagZero,
@@ -1356,6 +1379,8 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
13561379
Stub::VTableTy { vtable_holder },
13571380
unique_type_id,
13581381
&vtable_type_name,
1382+
unknown_file_metadata(cx),
1383+
UNKNOWN_LINE_NUMBER,
13591384
(size, pointer_align),
13601385
NO_SCOPE_METADATA,
13611386
DIFlags::FlagArtificial,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

+6
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
213213
type_map::Stub::Union,
214214
unique_type_id,
215215
&enum_type_name,
216+
unknown_file_metadata(cx),
217+
UNKNOWN_LINE_NUMBER,
216218
cx.size_and_align_of(enum_type),
217219
NO_SCOPE_METADATA,
218220
DIFlags::FlagZero,
@@ -288,6 +290,8 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
288290
type_map::Stub::Union,
289291
unique_type_id,
290292
&generator_type_name,
293+
unknown_file_metadata(cx),
294+
UNKNOWN_LINE_NUMBER,
291295
size_and_align_of(generator_type_and_layout),
292296
NO_SCOPE_METADATA,
293297
DIFlags::FlagZero,
@@ -490,6 +494,8 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
490494
variant_index,
491495
),
492496
&variant_struct_wrapper_type_name(variant_index),
497+
unknown_file_metadata(cx),
498+
UNKNOWN_LINE_NUMBER,
493499
// NOTE: We use size and align of enum_type, not from variant_layout:
494500
size_and_align_of(enum_or_generator_type_and_layout),
495501
Some(enum_or_generator_type_di_node),

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
261261
variant_index,
262262
),
263263
variant_def.name.as_str(),
264+
unknown_file_metadata(cx),
265+
UNKNOWN_LINE_NUMBER,
264266
// NOTE: We use size and align of enum_type, not from variant_layout:
265267
size_and_align_of(enum_type_and_layout),
266268
Some(enum_type_di_node),
@@ -343,6 +345,8 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
343345
Stub::Struct,
344346
unique_type_id,
345347
&variant_name,
348+
unknown_file_metadata(cx),
349+
UNKNOWN_LINE_NUMBER,
346350
size_and_align_of(generator_type_and_layout),
347351
Some(generator_type_di_node),
348352
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
7272
Stub::Struct,
7373
unique_type_id,
7474
&enum_type_name,
75+
unknown_file_metadata(cx),
76+
UNKNOWN_LINE_NUMBER,
7577
size_and_align_of(enum_type_and_layout),
7678
Some(containing_scope),
7779
DIFlags::FlagZero,
@@ -150,6 +152,8 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
150152
Stub::Struct,
151153
unique_type_id,
152154
&generator_type_name,
155+
unknown_file_metadata(cx),
156+
UNKNOWN_LINE_NUMBER,
153157
size_and_align_of(generator_type_and_layout),
154158
Some(containing_scope),
155159
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use crate::{
1616
debuginfo::utils::{create_DIArray, debug_context, DIB},
1717
llvm::{
1818
self,
19-
debuginfo::{DIFlags, DIScope, DIType},
19+
debuginfo::{DIFile, DIFlags, DIScope, DIType},
2020
},
2121
};
2222

23-
use super::{unknown_file_metadata, SmallVec, UNKNOWN_LINE_NUMBER};
23+
use super::SmallVec;
2424

2525
mod private {
2626
// This type cannot be constructed outside of this module because
@@ -183,6 +183,8 @@ pub(super) fn stub<'ll, 'tcx>(
183183
kind: Stub<'ll>,
184184
unique_type_id: UniqueTypeId<'tcx>,
185185
name: &str,
186+
file_metadata: &'ll DIFile,
187+
line_number: u32,
186188
(size, align): (Size, Align),
187189
containing_scope: Option<&'ll DIScope>,
188190
flags: DIFlags,
@@ -202,8 +204,8 @@ pub(super) fn stub<'ll, 'tcx>(
202204
containing_scope,
203205
name.as_ptr().cast(),
204206
name.len(),
205-
unknown_file_metadata(cx),
206-
UNKNOWN_LINE_NUMBER,
207+
file_metadata,
208+
line_number,
207209
size.bits(),
208210
align.bits() as u32,
209211
flags,
@@ -222,8 +224,8 @@ pub(super) fn stub<'ll, 'tcx>(
222224
containing_scope,
223225
name.as_ptr().cast(),
224226
name.len(),
225-
unknown_file_metadata(cx),
226-
UNKNOWN_LINE_NUMBER,
227+
file_metadata,
228+
line_number,
227229
size.bits(),
228230
align.bits() as u32,
229231
flags,

0 commit comments

Comments
 (0)