提交 fba1f8f1 编写于 作者: J Jan-Erik Rediger

[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.
上级 7420874a
......@@ -558,7 +558,9 @@ fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>,
&llmod_id[..]);
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 {
None
};
......
......@@ -18,7 +18,9 @@
fn_should_be_ignored, is_node_local_to_unit};
use super::namespace::mangled_name_of_item;
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::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
......@@ -48,7 +50,6 @@
use syntax::parse::token;
use syntax_pos::{self, Span};
// From DWARF 5.
// See http://www.dwarfstd.org/ShowIssue.php?issue=140129.1
const DW_LANG_RUST: c_uint = 0x1c;
......@@ -981,14 +982,17 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
return ptr_metadata;
}
pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
let work_dir = &cx.sess().working_dir;
let compile_unit_name = match cx.sess().local_crate_source_file {
None => fallback_path(cx),
pub fn compile_unit_metadata(scc: &SharedCrateContext,
debug_context: &CrateDebugContext,
sess: &Session)
-> 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) => {
if abs_path.is_relative() {
cx.sess().warn("debuginfo: Invalid path to crate's local root source file!");
fallback_path(cx)
sess.warn("debuginfo: Invalid path to crate's local root source file!");
fallback_path(scc)
} else {
match abs_path.strip_prefix(work_dir) {
Ok(ref p) if p.is_relative() => {
......@@ -998,7 +1002,7 @@ pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
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";
return unsafe {
llvm::LLVMDIBuilderCreateCompileUnit(
debug_context(cx).builder,
debug_context.builder,
DW_LANG_RUST,
compile_unit_name,
work_dir.as_ptr(),
producer.as_ptr(),
cx.sess().opts.optimize != config::OptLevel::No,
sess.opts.optimize != config::OptLevel::No,
flags.as_ptr() as *const _,
0,
split_name.as_ptr() as *const _)
};
fn fallback_path(cx: &CrateContext) -> CString {
CString::new(cx.link_meta().crate_name.clone()).unwrap()
fn fallback_path(scc: &::context::SharedCrateContext) -> CString {
CString::new(scc.link_meta().crate_name.clone()).unwrap()
}
}
......
......@@ -18,7 +18,7 @@
use self::namespace::mangled_name_of_item;
use self::type_names::compute_debuginfo_type_name;
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 llvm;
......@@ -50,7 +50,7 @@
mod utils;
mod namespace;
mod type_names;
mod metadata;
pub mod metadata;
mod create_scope_map;
mod source_loc;
......@@ -168,7 +168,6 @@ pub fn finalize(cx: &CrateContext) {
}
debug!("finalize");
let _ = compile_unit_metadata(cx);
if gdb::needs_gdb_debug_scripts_section(cx) {
// Add a .debug_gdb_scripts section to this compile-unit. This will
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册