Create a safe wrapper around LLVMRustDIBuilderCreateBasicType
This commit is contained in:
parent
cc41dd4fa1
commit
018032c682
1 changed files with 36 additions and 31 deletions
|
@ -39,8 +39,8 @@ use crate::debuginfo::metadata::type_map::build_type_with_children;
|
||||||
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
|
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
|
||||||
use crate::llvm;
|
use crate::llvm;
|
||||||
use crate::llvm::debuginfo::{
|
use crate::llvm::debuginfo::{
|
||||||
DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType,
|
DIBasicType, DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock,
|
||||||
DebugEmissionKind, DebugNameTableKind,
|
DIScope, DIType, DebugEmissionKind, DebugNameTableKind,
|
||||||
};
|
};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
|
@ -491,7 +491,6 @@ pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) ->
|
||||||
// FIXME(mw): Cache this via a regular UniqueTypeId instead of an extra field in the debug context.
|
// FIXME(mw): Cache this via a regular UniqueTypeId instead of an extra field in the debug context.
|
||||||
fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll DIType {
|
fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll DIType {
|
||||||
*debug_context(cx).recursion_marker_type.get_or_init(move || {
|
*debug_context(cx).recursion_marker_type.get_or_init(move || {
|
||||||
unsafe {
|
|
||||||
// The choice of type here is pretty arbitrary -
|
// The choice of type here is pretty arbitrary -
|
||||||
// anything reading the debuginfo for a recursive
|
// anything reading the debuginfo for a recursive
|
||||||
// type is going to see *something* weird - the only
|
// type is going to see *something* weird - the only
|
||||||
|
@ -502,15 +501,12 @@ fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll D
|
||||||
//
|
//
|
||||||
// FIXME: it might make sense to use an actual pointer type here
|
// FIXME: it might make sense to use an actual pointer type here
|
||||||
// so that debuggers can show the address.
|
// so that debuggers can show the address.
|
||||||
let name = "<recur_type>";
|
create_basic_type(
|
||||||
llvm::LLVMRustDIBuilderCreateBasicType(
|
cx,
|
||||||
DIB(cx),
|
"<recur_type>",
|
||||||
name.as_c_char_ptr(),
|
cx.tcx.data_layout.pointer_size,
|
||||||
name.len(),
|
|
||||||
cx.tcx.data_layout.pointer_size.bits(),
|
|
||||||
dwarf_const::DW_ATE_unsigned,
|
dwarf_const::DW_ATE_unsigned,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,15 +784,7 @@ fn build_basic_type_di_node<'ll, 'tcx>(
|
||||||
_ => bug!("debuginfo::build_basic_type_di_node - `t` is invalid type"),
|
_ => bug!("debuginfo::build_basic_type_di_node - `t` is invalid type"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty_di_node = unsafe {
|
let ty_di_node = create_basic_type(cx, name, cx.size_of(t), encoding);
|
||||||
llvm::LLVMRustDIBuilderCreateBasicType(
|
|
||||||
DIB(cx),
|
|
||||||
name.as_c_char_ptr(),
|
|
||||||
name.len(),
|
|
||||||
cx.size_of(t).bits(),
|
|
||||||
encoding,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
if !cpp_like_debuginfo {
|
if !cpp_like_debuginfo {
|
||||||
return DINodeCreationResult::new(ty_di_node, false);
|
return DINodeCreationResult::new(ty_di_node, false);
|
||||||
|
@ -824,6 +812,23 @@ fn build_basic_type_di_node<'ll, 'tcx>(
|
||||||
DINodeCreationResult::new(typedef_di_node, false)
|
DINodeCreationResult::new(typedef_di_node, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_basic_type<'ll, 'tcx>(
|
||||||
|
cx: &CodegenCx<'ll, 'tcx>,
|
||||||
|
name: &str,
|
||||||
|
size: Size,
|
||||||
|
encoding: u32,
|
||||||
|
) -> &'ll DIBasicType {
|
||||||
|
unsafe {
|
||||||
|
llvm::LLVMRustDIBuilderCreateBasicType(
|
||||||
|
DIB(cx),
|
||||||
|
name.as_c_char_ptr(),
|
||||||
|
name.len(),
|
||||||
|
size.bits(),
|
||||||
|
encoding,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn build_foreign_type_di_node<'ll, 'tcx>(
|
fn build_foreign_type_di_node<'ll, 'tcx>(
|
||||||
cx: &CodegenCx<'ll, 'tcx>,
|
cx: &CodegenCx<'ll, 'tcx>,
|
||||||
t: Ty<'tcx>,
|
t: Ty<'tcx>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue