Skip to content
Permalink
Browse files

[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.
  • Loading branch information...
shepmaster committed Jun 12, 2016
1 parent d9aefd2 commit e2e997f15b5fcadca5148c850bd224b825dd7922
Showing with 18 additions and 16 deletions.
  1. +3 −1 src/librustc_trans/context.rs
  2. +12 −12 src/librustc_trans/debuginfo/metadata.rs
  3. +3 −3 src/librustc_trans/debuginfo/mod.rs
@@ -532,7 +532,9 @@ impl<'tcx> LocalCrateContext<'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,7 @@ use super::utils::{debug_context, DIB, span_start, bytes_to_bits, size_and_align
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 llvm::{self, ValueRef};
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
@@ -980,14 +980,14 @@ 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: &::context::SharedCrateContext, debug_context: &CrateDebugContext, sess: &::session::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() => {
@@ -997,7 +997,7 @@ pub fn compile_unit_metadata(cx: &CrateContext) -> DIDescriptor {
path2cstr(&Path::new(".").join(p))
}
}
_ => fallback_path(cx)
_ => fallback_path(scc)
}
}
}
@@ -1014,19 +1014,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::utils::{DIB, span_start, create_DIArray, is_node_local_to_unit};
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 @@ pub mod gdb;
mod utils;
mod namespace;
mod type_names;
mod metadata;
pub mod metadata;
mod create_scope_map;
mod source_loc;

@@ -168,7 +168,7 @@ pub fn finalize(cx: &CrateContext) {
}

debug!("finalize");
let _ = compile_unit_metadata(cx);
//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

0 comments on commit e2e997f

Please sign in to comment.
You can’t perform that action at this time.