Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 55 additions & 46 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ use self::type_map::{DINodeCreationResult, Stub, UniqueTypeId};
use super::CodegenUnitDebugContext;
use super::namespace::mangled_name_of_instance;
use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name};
use super::utils::{
DIB, create_DIArray, debug_context, get_namespace_for_item, is_node_local_to_unit,
};
use super::utils::{DIB, debug_context, get_namespace_for_item, is_node_local_to_unit};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::debuginfo::dwarf_const;
use crate::debuginfo::metadata::type_map::build_type_with_children;
Expand Down Expand Up @@ -119,17 +117,17 @@ fn build_fixed_size_array_di_node<'ll, 'tcx>(
.try_to_target_usize(cx.tcx)
.expect("expected monomorphic const in codegen") as c_longlong;

let subrange =
unsafe { Some(llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)) };
let subrange = unsafe { llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound) };
let subscripts = &[subrange];

let subscripts = create_DIArray(DIB(cx), &[subrange]);
let di_node = unsafe {
llvm::LLVMRustDIBuilderCreateArrayType(
llvm::LLVMDIBuilderCreateArrayType(
DIB(cx),
size.bits(),
align.bits() as u32,
element_type_di_node,
subscripts,
subscripts.as_ptr(),
subscripts.len() as c_uint,
)
};

Expand Down Expand Up @@ -175,17 +173,13 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
"ptr_type={ptr_type}, pointee_type={pointee_type}",
);

let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
pointee_type_di_node,
pointer_size.bits(),
pointer_align.abi.bits() as u32,
0, // Ignore DWARF address space.
ptr_type_debuginfo_name.as_c_char_ptr(),
ptr_type_debuginfo_name.len(),
)
};
let di_node = create_pointer_type(
cx,
pointee_type_di_node,
pointer_size,
pointer_align.abi,
&ptr_type_debuginfo_name,
);

DINodeCreationResult { di_node, already_stored_in_typemap: false }
}
Expand Down Expand Up @@ -233,17 +227,13 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(

// The data pointer type is a regular, thin pointer, regardless of whether this
// is a slice or a trait object.
let data_ptr_type_di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
pointee_type_di_node,
addr_field.size.bits(),
addr_field.align.abi.bits() as u32,
0, // Ignore DWARF address space.
std::ptr::null(),
0,
)
};
let data_ptr_type_di_node = create_pointer_type(
cx,
pointee_type_di_node,
addr_field.size,
addr_field.align.abi,
"",
);

smallvec![
build_field_di_node(
Expand Down Expand Up @@ -318,7 +308,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(

debug_context(cx).type_map.unique_id_to_di_node.borrow_mut().remove(&unique_type_id);

let fn_di_node = create_subroutine_type(cx, create_DIArray(DIB(cx), &signature_di_nodes[..]));
let fn_di_node = create_subroutine_type(cx, &signature_di_nodes[..]);

// This is actually a function pointer, so wrap it in pointer DI.
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
Expand All @@ -329,26 +319,44 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
}
_ => unreachable!(),
};
let di_node = unsafe {
llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx),
fn_di_node,
size.bits(),
align.bits() as u32,
0, // Ignore DWARF address space.
name.as_c_char_ptr(),
name.len(),
)
};
let di_node = create_pointer_type(cx, fn_di_node, size, align, &name);

DINodeCreationResult::new(di_node, false)
}

pub(super) fn create_subroutine_type<'ll>(
cx: &CodegenCx<'ll, '_>,
signature: &'ll DICompositeType,
signature: &[Option<&'ll llvm::Metadata>],
) -> &'ll DICompositeType {
unsafe { llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(cx), signature) }
unsafe {
llvm::LLVMDIBuilderCreateSubroutineType(
DIB(cx),
None, // ("File" is ignored and has no effect)
signature.as_ptr(),
signature.len() as c_uint,
DIFlags::FlagZero, // (default value)
)
}
}

fn create_pointer_type<'ll>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice encapsulation

cx: &CodegenCx<'ll, '_>,
pointee_ty: &'ll llvm::Metadata,
size: Size,
align: Align,
name: &str,
) -> &'ll llvm::Metadata {
unsafe {
llvm::LLVMDIBuilderCreatePointerType(
DIB(cx),
pointee_ty,
size.bits(),
align.bits() as u32,
0, // Ignore DWARF address space.
name.as_ptr(),
name.len(),
)
}
}

/// Create debuginfo for `dyn SomeTrait` types. Currently these are empty structs
Expand Down Expand Up @@ -834,12 +842,13 @@ fn create_basic_type<'ll, 'tcx>(
encoding: u32,
) -> &'ll DIBasicType {
unsafe {
llvm::LLVMRustDIBuilderCreateBasicType(
llvm::LLVMDIBuilderCreateBasicType(
DIB(cx),
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
size.bits(),
encoding,
DIFlags::FlagZero,
)
}
}
Expand Down
27 changes: 15 additions & 12 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cell::RefCell;

use libc::c_uint;
use rustc_abi::{Align, Size, VariantIdx};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
Expand All @@ -9,7 +10,7 @@ use rustc_middle::bug;
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt};

use super::{DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::utils::{DIB, create_DIArray, debug_context};
use crate::llvm::debuginfo::{DIFlags, DIScope, DIType};
use crate::llvm::{self};
Expand Down Expand Up @@ -191,7 +192,7 @@ pub(super) fn stub<'ll, 'tcx>(
containing_scope: Option<&'ll DIScope>,
flags: DIFlags,
) -> StubInfo<'ll, 'tcx> {
let empty_array = create_DIArray(DIB(cx), &[]);
let no_elements: &[Option<&llvm::Metadata>] = &[];
let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx);

let (file_metadata, line_number) = if let Some(def_location) = def_location {
Expand All @@ -207,39 +208,41 @@ pub(super) fn stub<'ll, 'tcx>(
_ => None,
};
unsafe {
llvm::LLVMRustDIBuilderCreateStructType(
llvm::LLVMDIBuilderCreateStructType(
DIB(cx),
containing_scope,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
file_metadata,
line_number,
size.bits(),
align.bits() as u32,
flags,
None,
empty_array,
0,
no_elements.as_ptr(),
no_elements.len() as c_uint,
0u32, // (Objective-C runtime version; default is 0)
vtable_holder,
unique_type_id_str.as_c_char_ptr(),
unique_type_id_str.as_ptr(),
unique_type_id_str.len(),
)
}
}
Stub::Union => unsafe {
llvm::LLVMRustDIBuilderCreateUnionType(
llvm::LLVMDIBuilderCreateUnionType(
DIB(cx),
containing_scope,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
file_metadata,
line_number,
size.bits(),
align.bits() as u32,
flags,
Some(empty_array),
0,
unique_type_id_str.as_c_char_ptr(),
no_elements.as_ptr(),
no_elements.len() as c_uint,
0u32, // (Objective-C runtime version; default is 0)
unique_type_id_str.as_ptr(),
unique_type_id_str.len(),
)
},
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let file_metadata = file_metadata(self, &loc.file);

let function_type_metadata =
create_subroutine_type(self, get_function_signature(self, fn_abi));
create_subroutine_type(self, &get_function_signature(self, fn_abi));

let mut name = String::with_capacity(64);
type_names::push_item_name(tcx, def_id, false, &mut name);
Expand Down Expand Up @@ -441,9 +441,9 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn get_function_signature<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
) -> &'ll DIArray {
) -> Vec<Option<&'ll llvm::Metadata>> {
if cx.sess().opts.debuginfo != DebugInfo::Full {
return create_DIArray(DIB(cx), &[]);
return vec![];
}

let mut signature = Vec::with_capacity(fn_abi.args.len() + 1);
Expand Down Expand Up @@ -484,7 +484,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
.extend(fn_abi.args.iter().map(|arg| Some(type_di_node(cx, arg.layout.ty))));
}

create_DIArray(DIB(cx), &signature[..])
signature
}

fn get_template_parameters<'ll, 'tcx>(
Expand Down
Loading
Loading