[LLVM-3.9] Setup the compile unit information immediately
Since LLVM reversed the order of the debug info graphs, we need to have a compile unit that exists *before* any functions (`DISubprogram`s) are created. This allows the LLVM debug info builder to automatically link the functions to the compile unit.
This commit is contained in:
parent
7420874a97
commit
fba1f8f123
3 changed files with 22 additions and 17 deletions
|
@ -558,7 +558,9 @@ impl<'tcx> LocalCrateContext<'tcx> {
|
||||||
&llmod_id[..]);
|
&llmod_id[..]);
|
||||||
|
|
||||||
let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
|
let dbg_cx = if shared.tcx.sess.opts.debuginfo != NoDebugInfo {
|
||||||
Some(debuginfo::CrateDebugContext::new(llmod))
|
let dctx = debuginfo::CrateDebugContext::new(llmod);
|
||||||
|
debuginfo::metadata::compile_unit_metadata(shared, &dctx, shared.tcx.sess);
|
||||||
|
Some(dctx)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,9 @@ use super::utils::{debug_context, DIB, span_start, bytes_to_bits, size_and_align
|
||||||
fn_should_be_ignored, is_node_local_to_unit};
|
fn_should_be_ignored, is_node_local_to_unit};
|
||||||
use super::namespace::mangled_name_of_item;
|
use super::namespace::mangled_name_of_item;
|
||||||
use super::type_names::{compute_debuginfo_type_name, push_debuginfo_type_name};
|
use super::type_names::{compute_debuginfo_type_name, push_debuginfo_type_name};
|
||||||
use super::{declare_local, VariableKind, VariableAccess};
|
use super::{declare_local, VariableKind, VariableAccess, CrateDebugContext};
|
||||||
|
use context::SharedCrateContext;
|
||||||
|
use session::Session;
|
||||||
|
|
||||||
use llvm::{self, ValueRef};
|
use llvm::{self, ValueRef};
|
||||||
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
|
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
|
||||||
|
@ -48,7 +50,6 @@ use syntax::ast;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
use syntax_pos::{self, Span};
|
use syntax_pos::{self, Span};
|
||||||
|
|
||||||
|
|
||||||
// From DWARF 5.
|
// From DWARF 5.
|
||||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1
|
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1
|
||||||
const DW_LANG_RUST: c_uint = 0x1c;
|
const DW_LANG_RUST: c_uint = 0x1c;
|
||||||
|
@ -981,14 +982,17 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||||
return ptr_metadata;
|
return ptr_metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
|
pub fn compile_unit_metadata(scc: &SharedCrateContext,
|
||||||
let work_dir = &cx.sess().working_dir;
|
debug_context: &CrateDebugContext,
|
||||||
let compile_unit_name = match cx.sess().local_crate_source_file {
|
sess: &Session)
|
||||||
None => fallback_path(cx),
|
-> DIDescriptor {
|
||||||
|
let work_dir = &sess.working_dir;
|
||||||
|
let compile_unit_name = match sess.local_crate_source_file {
|
||||||
|
None => fallback_path(scc),
|
||||||
Some(ref abs_path) => {
|
Some(ref abs_path) => {
|
||||||
if abs_path.is_relative() {
|
if abs_path.is_relative() {
|
||||||
cx.sess().warn("debuginfo: Invalid path to crate's local root source file!");
|
sess.warn("debuginfo: Invalid path to crate's local root source file!");
|
||||||
fallback_path(cx)
|
fallback_path(scc)
|
||||||
} else {
|
} else {
|
||||||
match abs_path.strip_prefix(work_dir) {
|
match abs_path.strip_prefix(work_dir) {
|
||||||
Ok(ref p) if p.is_relative() => {
|
Ok(ref p) if p.is_relative() => {
|
||||||
|
@ -998,7 +1002,7 @@ pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
|
||||||
path2cstr(&Path::new(".").join(p))
|
path2cstr(&Path::new(".").join(p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => fallback_path(cx)
|
_ => fallback_path(scc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1015,19 +1019,19 @@ pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
|
||||||
let split_name = "\0";
|
let split_name = "\0";
|
||||||
return unsafe {
|
return unsafe {
|
||||||
llvm::LLVMDIBuilderCreateCompileUnit(
|
llvm::LLVMDIBuilderCreateCompileUnit(
|
||||||
debug_context(cx).builder,
|
debug_context.builder,
|
||||||
DW_LANG_RUST,
|
DW_LANG_RUST,
|
||||||
compile_unit_name,
|
compile_unit_name,
|
||||||
work_dir.as_ptr(),
|
work_dir.as_ptr(),
|
||||||
producer.as_ptr(),
|
producer.as_ptr(),
|
||||||
cx.sess().opts.optimize != config::OptLevel::No,
|
sess.opts.optimize != config::OptLevel::No,
|
||||||
flags.as_ptr() as *const _,
|
flags.as_ptr() as *const _,
|
||||||
0,
|
0,
|
||||||
split_name.as_ptr() as *const _)
|
split_name.as_ptr() as *const _)
|
||||||
};
|
};
|
||||||
|
|
||||||
fn fallback_path(cx: &CrateContext) -> CString {
|
fn fallback_path(scc: &::context::SharedCrateContext) -> CString {
|
||||||
CString::new(cx.link_meta().crate_name.clone()).unwrap()
|
CString::new(scc.link_meta().crate_name.clone()).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use self::utils::{DIB, span_start, create_DIArray, is_node_local_to_unit};
|
||||||
use self::namespace::mangled_name_of_item;
|
use self::namespace::mangled_name_of_item;
|
||||||
use self::type_names::compute_debuginfo_type_name;
|
use self::type_names::compute_debuginfo_type_name;
|
||||||
use self::metadata::{type_metadata, diverging_type_metadata};
|
use self::metadata::{type_metadata, diverging_type_metadata};
|
||||||
use self::metadata::{file_metadata, scope_metadata, TypeMap, compile_unit_metadata};
|
use self::metadata::{file_metadata, scope_metadata, TypeMap};
|
||||||
use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
|
use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
|
||||||
|
|
||||||
use llvm;
|
use llvm;
|
||||||
|
@ -50,7 +50,7 @@ pub mod gdb;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod namespace;
|
mod namespace;
|
||||||
mod type_names;
|
mod type_names;
|
||||||
mod metadata;
|
pub mod metadata;
|
||||||
mod create_scope_map;
|
mod create_scope_map;
|
||||||
mod source_loc;
|
mod source_loc;
|
||||||
|
|
||||||
|
@ -168,7 +168,6 @@ pub fn finalize(cx: &CrateContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("finalize");
|
debug!("finalize");
|
||||||
let _ = compile_unit_metadata(cx);
|
|
||||||
|
|
||||||
if gdb::needs_gdb_debug_scripts_section(cx) {
|
if gdb::needs_gdb_debug_scripts_section(cx) {
|
||||||
// Add a .debug_gdb_scripts section to this compile-unit. This will
|
// Add a .debug_gdb_scripts section to this compile-unit. This will
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue