Skip to content

Commit a1191e3

Browse files
committed
force enum DISCR_* to const u64 to allow for inspection via LLDB's SBTypeStaticField::GetConstantValue()
1 parent bc4266c commit a1191e3

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const DW_ATE_unsigned: c_uint = 0x07;
7373
#[allow(non_upper_case_globals)]
7474
const DW_ATE_UTF: c_uint = 0x10;
7575

76+
#[allow(non_upper_case_globals)]
77+
const DW_TAG_const_type: c_uint = 0x26;
78+
7679
pub(super) const UNKNOWN_LINE_NUMBER: c_uint = 0;
7780
pub(super) const UNKNOWN_COLUMN_NUMBER: c_uint = 0;
7881

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

+34-17
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use crate::common::{AsCCharPtr, CodegenCx};
1515
use crate::debuginfo::metadata::enums::DiscrResult;
1616
use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId};
1717
use crate::debuginfo::metadata::{
18-
DINodeCreationResult, NO_GENERICS, NO_SCOPE_METADATA, SmallVec, UNKNOWN_LINE_NUMBER,
19-
build_field_di_node, file_metadata, file_metadata_from_def_id, size_and_align_of, type_di_node,
20-
unknown_file_metadata, visibility_di_flags,
18+
DINodeCreationResult, DW_TAG_const_type, NO_GENERICS, NO_SCOPE_METADATA, SmallVec,
19+
UNKNOWN_LINE_NUMBER, build_field_di_node, file_metadata, file_metadata_from_def_id,
20+
size_and_align_of, type_di_node, unknown_file_metadata, visibility_di_flags,
2121
};
2222
use crate::debuginfo::utils::DIB;
2323
use crate::llvm::debuginfo::{DIFile, DIFlags, DIType};
@@ -566,22 +566,39 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
566566
None,
567567
));
568568

569-
let build_assoc_const =
570-
|name: &str, type_di_node: &'ll DIType, value: u64, align: Align| unsafe {
571-
llvm::LLVMRustDIBuilderCreateStaticMemberType(
572-
DIB(cx),
573-
wrapper_struct_type_di_node,
574-
name.as_c_char_ptr(),
575-
name.len(),
576-
unknown_file_metadata(cx),
577-
UNKNOWN_LINE_NUMBER,
578-
type_di_node,
579-
DIFlags::FlagZero,
580-
Some(cx.const_u64(value)),
581-
align.bits() as u32,
582-
)
569+
let build_assoc_const = |name: &str,
570+
type_di_node_: &'ll DIType,
571+
value: u64,
572+
align: Align| unsafe {
573+
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
574+
// problems inspecting other value types. Since DISCR_* is typically only going to be
575+
// directly inspected via the debugger visualizer - which compares it to the `tag` value
576+
// (whose type is not modified at all) it shouldn't cause any real problems.
577+
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
578+
(type_di_node_, align.bits() as u32)
579+
} else {
580+
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
581+
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
583582
};
584583

584+
// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
585+
let field_type =
586+
llvm::LLVMRustDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);
587+
588+
llvm::LLVMRustDIBuilderCreateStaticMemberType(
589+
DIB(cx),
590+
wrapper_struct_type_di_node,
591+
name.as_c_char_ptr(),
592+
name.len(),
593+
unknown_file_metadata(cx),
594+
UNKNOWN_LINE_NUMBER,
595+
field_type,
596+
DIFlags::FlagZero,
597+
Some(cx.const_u64(value)),
598+
align,
599+
)
600+
};
601+
585602
// We also always have an associated constant for the discriminant value
586603
// of the variant.
587604
fields.push(build_assoc_const(

Diff for: compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,9 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType(
11421142

11431143
extern "C" LLVMMetadataRef
11441144
LLVMRustDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
1145-
LLVMMetadataRef Type) {
1146-
return wrap(unwrap(Builder)->createQualifiedType(Tag,
1147-
unwrapDI<DIType>(Type)));
1145+
LLVMMetadataRef Type) {
1146+
return wrap(
1147+
unwrap(Builder)->createQualifiedType(Tag, unwrapDI<DIType>(Type)));
11481148
}
11491149

11501150
extern "C" LLVMMetadataRef

0 commit comments

Comments
 (0)