Skip to content

Commit 2f00b6a

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 #98678
1 parent c07aa1e commit 2f00b6a

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+25
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
204204
Stub::Struct,
205205
unique_type_id,
206206
&ptr_type_debuginfo_name,
207+
unknown_file_metadata(cx),
208+
UNKNOWN_LINE_NUMBER,
207209
cx.size_and_align_of(ptr_type),
208210
NO_SCOPE_METADATA,
209211
DIFlags::FlagZero,
@@ -371,6 +373,8 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
371373
Stub::Struct,
372374
unique_type_id,
373375
&type_name,
376+
unknown_file_metadata(cx),
377+
UNKNOWN_LINE_NUMBER,
374378
cx.size_and_align_of(dyn_type),
375379
NO_SCOPE_METADATA,
376380
DIFlags::FlagZero,
@@ -841,6 +845,8 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
841845
Stub::Struct,
842846
unique_type_id,
843847
&compute_debuginfo_type_name(cx.tcx, t, false),
848+
unknown_file_metadata(cx),
849+
UNKNOWN_LINE_NUMBER,
844850
cx.size_and_align_of(t),
845851
Some(get_namespace_for_item(cx, def_id)),
846852
DIFlags::FlagZero,
@@ -1044,13 +1050,24 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10441050
let struct_type_and_layout = cx.layout_of(struct_type);
10451051
let variant_def = adt_def.non_enum_variant();
10461052

1053+
let tcx = cx.tcx;
1054+
let struct_span = tcx.def_span(adt_def.did());
1055+
let (file_metadata, line_number) = if !struct_span.is_dummy() {
1056+
let loc = cx.lookup_debug_loc(struct_span.lo());
1057+
(file_metadata(cx, &loc.file), loc.line)
1058+
} else {
1059+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
1060+
};
1061+
10471062
type_map::build_type_with_children(
10481063
cx,
10491064
type_map::stub(
10501065
cx,
10511066
Stub::Struct,
10521067
unique_type_id,
10531068
&compute_debuginfo_type_name(cx.tcx, struct_type, false),
1069+
file_metadata,
1070+
line_number,
10541071
size_and_align_of(struct_type_and_layout),
10551072
Some(containing_scope),
10561073
visibility_di_flags(cx, adt_def.did(), adt_def.did()),
@@ -1154,6 +1171,8 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
11541171
Stub::Struct,
11551172
unique_type_id,
11561173
&type_name,
1174+
unknown_file_metadata(cx),
1175+
UNKNOWN_LINE_NUMBER,
11571176
size_and_align_of(tuple_type_and_layout),
11581177
NO_SCOPE_METADATA,
11591178
DIFlags::FlagZero,
@@ -1200,6 +1219,8 @@ fn build_closure_env_di_node<'ll, 'tcx>(
12001219
Stub::Struct,
12011220
unique_type_id,
12021221
&type_name,
1222+
unknown_file_metadata(cx),
1223+
UNKNOWN_LINE_NUMBER,
12031224
cx.size_and_align_of(closure_env_type),
12041225
Some(containing_scope),
12051226
DIFlags::FlagZero,
@@ -1231,6 +1252,8 @@ fn build_union_type_di_node<'ll, 'tcx>(
12311252
Stub::Union,
12321253
unique_type_id,
12331254
&type_name,
1255+
unknown_file_metadata(cx),
1256+
UNKNOWN_LINE_NUMBER,
12341257
size_and_align_of(union_ty_and_layout),
12351258
Some(containing_scope),
12361259
DIFlags::FlagZero,
@@ -1423,6 +1446,8 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14231446
Stub::VTableTy { vtable_holder },
14241447
unique_type_id,
14251448
&vtable_type_name,
1449+
unknown_file_metadata(cx),
1450+
UNKNOWN_LINE_NUMBER,
14261451
(size, pointer_align),
14271452
NO_SCOPE_METADATA,
14281453
DIFlags::FlagArtificial,

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

+6
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
199199
type_map::Stub::Union,
200200
unique_type_id,
201201
&enum_type_name,
202+
unknown_file_metadata(cx),
203+
UNKNOWN_LINE_NUMBER,
202204
cx.size_and_align_of(enum_type),
203205
NO_SCOPE_METADATA,
204206
visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()),
@@ -274,6 +276,8 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
274276
type_map::Stub::Union,
275277
unique_type_id,
276278
&coroutine_type_name,
279+
unknown_file_metadata(cx),
280+
UNKNOWN_LINE_NUMBER,
277281
size_and_align_of(coroutine_type_and_layout),
278282
NO_SCOPE_METADATA,
279283
DIFlags::FlagZero,
@@ -481,6 +485,8 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
481485
variant_index,
482486
),
483487
&variant_struct_wrapper_type_name(variant_index),
488+
unknown_file_metadata(cx),
489+
UNKNOWN_LINE_NUMBER,
484490
// NOTE: We use size and align of enum_type, not from variant_layout:
485491
size_and_align_of(enum_or_coroutine_type_and_layout),
486492
Some(enum_or_coroutine_type_di_node),

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
204204
variant_index,
205205
),
206206
variant_def.name.as_str(),
207+
unknown_file_metadata(cx),
208+
UNKNOWN_LINE_NUMBER,
207209
// NOTE: We use size and align of enum_type, not from variant_layout:
208210
size_and_align_of(enum_type_and_layout),
209211
Some(enum_type_di_node),
@@ -286,6 +288,8 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
286288
Stub::Struct,
287289
unique_type_id,
288290
&variant_name,
291+
unknown_file_metadata(cx),
292+
UNKNOWN_LINE_NUMBER,
289293
size_and_align_of(coroutine_type_and_layout),
290294
Some(coroutine_type_di_node),
291295
DIFlags::FlagZero,
@@ -351,7 +355,11 @@ enum DiscrResult {
351355

352356
impl DiscrResult {
353357
fn opt_single_val(&self) -> Option<u128> {
354-
if let Self::Value(d) = *self { Some(d) } else { None }
358+
if let Self::Value(d) = *self {
359+
Some(d)
360+
} else {
361+
None
362+
}
355363
}
356364
}
357365

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

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
6262
Stub::Struct,
6363
unique_type_id,
6464
&enum_type_name,
65+
unknown_file_metadata(cx),
66+
UNKNOWN_LINE_NUMBER,
6567
size_and_align_of(enum_type_and_layout),
6668
Some(containing_scope),
6769
visibility_flags,
@@ -141,6 +143,8 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
141143
Stub::Struct,
142144
unique_type_id,
143145
&coroutine_type_name,
146+
unknown_file_metadata(cx),
147+
UNKNOWN_LINE_NUMBER,
144148
size_and_align_of(coroutine_type_and_layout),
145149
Some(containing_scope),
146150
DIFlags::FlagZero,

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1111
use super::{SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata};
1212
use crate::common::{AsCCharPtr, CodegenCx};
1313
use crate::debuginfo::utils::{DIB, create_DIArray, debug_context};
14-
use crate::llvm::debuginfo::{DIFlags, DIScope, DIType};
14+
use crate::llvm::debuginfo::{DIFile, DIFlags, DIScope, DIType};
1515
use crate::llvm::{self};
1616

1717
mod private {
@@ -174,6 +174,8 @@ pub(super) fn stub<'ll, 'tcx>(
174174
kind: Stub<'ll>,
175175
unique_type_id: UniqueTypeId<'tcx>,
176176
name: &str,
177+
file_metadata: &'ll DIFile,
178+
line_number: u32,
177179
(size, align): (Size, Align),
178180
containing_scope: Option<&'ll DIScope>,
179181
flags: DIFlags,
@@ -193,8 +195,8 @@ pub(super) fn stub<'ll, 'tcx>(
193195
containing_scope,
194196
name.as_c_char_ptr(),
195197
name.len(),
196-
unknown_file_metadata(cx),
197-
UNKNOWN_LINE_NUMBER,
198+
file_metadata,
199+
line_number,
198200
size.bits(),
199201
align.bits() as u32,
200202
flags,
@@ -213,8 +215,8 @@ pub(super) fn stub<'ll, 'tcx>(
213215
containing_scope,
214216
name.as_c_char_ptr(),
215217
name.len(),
216-
unknown_file_metadata(cx),
217-
UNKNOWN_LINE_NUMBER,
218+
file_metadata,
219+
line_number,
218220
size.bits(),
219221
align.bits() as u32,
220222
flags,

0 commit comments

Comments
 (0)