Skip to content

Cleanup debuginfo generation a bit #68959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 3 additions & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
}
}

debuginfo::create_global_var_metadata(&self, def_id, g);
if let Some(dbg_cx) = self.dbg_cx.as_ref() {
debuginfo::create_global_var_metadata(dbg_cx, def_id, g);
}

if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
llvm::set_thread_local_mode(g, self.tls_model);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());

let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
let dctx = debuginfo::CrateDebugContext::new(llmod);
let dctx = debuginfo::CrateDebugContext::new(tcx, llmod);
debuginfo::metadata::compile_unit_metadata(tcx, &codegen_unit.name().as_str(), &dctx);
Some(dctx)
} else {
Expand Down
29 changes: 12 additions & 17 deletions src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::CrateDebugContext;
use super::metadata::file_metadata;
use super::utils::{span_start, DIB};
use super::utils::span_start;
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};

use crate::common::CodegenCx;
use crate::llvm;
use crate::llvm::debuginfo::{DIScope, DISubprogram};
use rustc::mir::{Body, SourceScope};
Expand All @@ -16,7 +16,7 @@ use rustc_index::vec::Idx;

/// Produces DIScope DIEs for each MIR Scope which has variables defined in it.
pub fn compute_mir_scopes(
cx: &CodegenCx<'ll, '_>,
dbg_cx: &CrateDebugContext<'ll, '_>,
mir: &Body<'_>,
fn_metadata: &'ll DISubprogram,
debug_context: &mut FunctionDebugContext<&'ll DIScope>,
Expand All @@ -32,12 +32,12 @@ pub fn compute_mir_scopes(
// Instantiate all scopes.
for idx in 0..mir.source_scopes.len() {
let scope = SourceScope::new(idx);
make_mir_scope(cx, &mir, fn_metadata, &has_variables, debug_context, scope);
make_mir_scope(dbg_cx, &mir, fn_metadata, &has_variables, debug_context, scope);
}
}

fn make_mir_scope(
cx: &CodegenCx<'ll, '_>,
dbg_cx: &CrateDebugContext<'ll, '_>,
mir: &Body<'_>,
fn_metadata: &'ll DISubprogram,
has_variables: &BitSet<SourceScope>,
Expand All @@ -50,11 +50,11 @@ fn make_mir_scope(

let scope_data = &mir.source_scopes[scope];
let parent_scope = if let Some(parent) = scope_data.parent_scope {
make_mir_scope(cx, mir, fn_metadata, has_variables, debug_context, parent);
make_mir_scope(dbg_cx, mir, fn_metadata, has_variables, debug_context, parent);
debug_context.scopes[parent]
} else {
// The root is the function itself.
let loc = span_start(cx, mir.span);
let loc = span_start(dbg_cx.tcx, mir.span);
debug_context.scopes[scope] = DebugScope {
scope_metadata: Some(fn_metadata),
file_start_pos: loc.file.start_pos,
Expand All @@ -67,21 +67,16 @@ fn make_mir_scope(
// Do not create a DIScope if there are no variables
// defined in this MIR Scope, to avoid debuginfo bloat.

// However, we don't skip creating a nested scope if
// our parent is the root, because we might want to
// put arguments in the root and not have shadowing.
if parent_scope.scope_metadata.unwrap() != fn_metadata {
debug_context.scopes[scope] = parent_scope;
return;
}
debug_context.scopes[scope] = parent_scope;
return;
}

let loc = span_start(cx, scope_data.span);
let file_metadata = file_metadata(cx, &loc.file.name, debug_context.defining_crate);
let loc = span_start(dbg_cx.tcx, scope_data.span);
let file_metadata = file_metadata(dbg_cx, &loc.file.name, debug_context.defining_crate);

let scope_metadata = unsafe {
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx),
dbg_cx.builder,
parent_scope.scope_metadata.unwrap(),
file_metadata,
loc.line as c_uint,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! utilizing a cache. The way to get a shared metadata node when needed is
//! thus to just call the corresponding function in this module:
//!
//! let file_metadata = file_metadata(crate_context, path);
//! let file_metadata = file_metadata(debug_context, path);
//!
//! The function will take care of probing the cache for an existing node for
//! that exact file path.
Expand Down
Loading