2021-02-19 14:50:15 -06:00
|
|
|
use super::metadata::file_metadata;
|
2020-02-25 00:00:00 +00:00
|
|
|
use super::utils::DIB;
|
2019-12-22 17:42:04 -05:00
|
|
|
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
|
2020-02-11 22:52:59 +02:00
|
|
|
use rustc_codegen_ssa::traits::*;
|
2015-04-29 18:14:37 +12:00
|
|
|
|
2019-12-22 17:42:04 -05:00
|
|
|
use crate::common::CodegenCx;
|
2019-02-18 03:58:58 +09:00
|
|
|
use crate::llvm;
|
2020-02-11 01:27:33 +02:00
|
|
|
use crate::llvm::debuginfo::{DILocation, DIScope};
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::mir::{Body, SourceScope};
|
2021-09-02 00:09:34 +03:00
|
|
|
use rustc_middle::ty::layout::FnAbiOf;
|
2020-02-11 01:27:33 +02:00
|
|
|
use rustc_middle::ty::{self, Instance};
|
2020-02-11 22:52:59 +02:00
|
|
|
use rustc_session::config::DebugInfo;
|
2015-04-29 18:14:37 +12:00
|
|
|
|
2019-09-26 05:30:10 +00:00
|
|
|
use rustc_index::bit_set::BitSet;
|
2019-09-11 17:52:39 +03:00
|
|
|
use rustc_index::vec::Idx;
|
2016-08-24 19:34:31 -07:00
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Produces DIScope DIEs for each MIR Scope which has variables defined in it.
|
2020-02-11 01:27:33 +02:00
|
|
|
// FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`.
|
2021-12-14 13:49:49 -05:00
|
|
|
pub fn compute_mir_scopes<'ll, 'tcx>(
|
2020-02-11 01:27:33 +02:00
|
|
|
cx: &CodegenCx<'ll, 'tcx>,
|
|
|
|
instance: Instance<'tcx>,
|
|
|
|
mir: &Body<'tcx>,
|
2020-02-10 22:30:51 +02:00
|
|
|
fn_dbg_scope: &'ll DIScope,
|
2020-02-11 01:27:33 +02:00
|
|
|
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
|
2019-09-11 17:52:39 +03:00
|
|
|
) {
|
2016-04-07 22:35:11 +03:00
|
|
|
// Find all the scopes with variables defined in them.
|
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.
This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs --> bit_set.rs
- indexed_set.rs --> (removed)
- BitArray + IdxSet --> BitSet (merged, see below)
- BitVector --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix --> BitMatrix
- SparseBitMatrix --> SparseBitMatrix
The changes within the bitset types themselves are as follows.
```
OLD OLD NEW
BitArray<C> IdxSet<T> BitSet<T>
-------- ------ ------
grow - grow
new - (remove)
new_empty new_empty new_empty
new_filled new_filled new_filled
- to_hybrid to_hybrid
clear clear clear
set_up_to set_up_to set_up_to
clear_above - clear_above
count - count
contains(T) contains(&T) contains(T)
contains_all - superset
is_empty - is_empty
insert(T) add(&T) insert(T)
insert_all - insert_all()
remove(T) remove(&T) remove(T)
words words words
words_mut words_mut words_mut
- overwrite overwrite
merge union union
- subtract subtract
- intersect intersect
iter iter iter
```
In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
`insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
over `contains_all`, `domain_size` over `num_bits`).
Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
2018-09-14 15:07:25 +10:00
|
|
|
let mut has_variables = BitSet::new_empty(mir.source_scopes.len());
|
2020-02-11 22:52:59 +02:00
|
|
|
|
|
|
|
// Only consider variables when they're going to be emitted.
|
|
|
|
// FIXME(eddyb) don't even allocate `has_variables` otherwise.
|
|
|
|
if cx.sess().opts.debuginfo == DebugInfo::Full {
|
|
|
|
// FIXME(eddyb) take into account that arguments always have debuginfo,
|
|
|
|
// irrespective of their name (assuming full debuginfo is enabled).
|
|
|
|
// NOTE(eddyb) actually, on second thought, those are always in the
|
|
|
|
// function scope, which always exists.
|
|
|
|
for var_debug_info in &mir.var_debug_info {
|
|
|
|
has_variables.insert(var_debug_info.source_info.scope);
|
|
|
|
}
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate all scopes.
|
2018-05-28 14:16:09 +03:00
|
|
|
for idx in 0..mir.source_scopes.len() {
|
|
|
|
let scope = SourceScope::new(idx);
|
2021-09-30 19:38:50 +02:00
|
|
|
make_mir_scope(cx, instance, mir, fn_dbg_scope, &has_variables, debug_context, scope);
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 13:49:49 -05:00
|
|
|
fn make_mir_scope<'ll, 'tcx>(
|
2020-02-11 01:27:33 +02:00
|
|
|
cx: &CodegenCx<'ll, 'tcx>,
|
|
|
|
instance: Instance<'tcx>,
|
|
|
|
mir: &Body<'tcx>,
|
2020-02-10 22:30:51 +02:00
|
|
|
fn_dbg_scope: &'ll DIScope,
|
2019-12-22 17:42:04 -05:00
|
|
|
has_variables: &BitSet<SourceScope>,
|
2020-02-11 01:27:33 +02:00
|
|
|
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
|
2019-12-22 17:42:04 -05:00
|
|
|
scope: SourceScope,
|
|
|
|
) {
|
2020-02-10 22:52:30 +02:00
|
|
|
if debug_context.scopes[scope].dbg_scope.is_some() {
|
2016-04-07 22:35:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:16:09 +03:00
|
|
|
let scope_data = &mir.source_scopes[scope];
|
2016-04-07 22:35:11 +03:00
|
|
|
let parent_scope = if let Some(parent) = scope_data.parent_scope {
|
2020-02-11 01:27:33 +02:00
|
|
|
make_mir_scope(cx, instance, mir, fn_dbg_scope, has_variables, debug_context, parent);
|
2019-09-11 17:52:39 +03:00
|
|
|
debug_context.scopes[parent]
|
2016-04-07 22:35:11 +03:00
|
|
|
} else {
|
|
|
|
// The root is the function itself.
|
2020-02-25 00:00:00 +00:00
|
|
|
let loc = cx.lookup_debug_loc(mir.span.lo());
|
2019-09-11 17:52:39 +03:00
|
|
|
debug_context.scopes[scope] = DebugScope {
|
2020-02-10 22:52:30 +02:00
|
|
|
dbg_scope: Some(fn_dbg_scope),
|
2020-02-11 01:27:33 +02:00
|
|
|
inlined_at: None,
|
2016-08-24 19:34:31 -07:00
|
|
|
file_start_pos: loc.file.start_pos,
|
|
|
|
file_end_pos: loc.file.end_pos,
|
|
|
|
};
|
2016-04-07 22:35:11 +03:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2020-02-11 01:27:33 +02:00
|
|
|
if !has_variables.contains(scope) && scope_data.inlined.is_none() {
|
|
|
|
// Do not create a DIScope if there are no variables defined in this
|
|
|
|
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
|
2020-02-08 17:58:00 +02:00
|
|
|
debug_context.scopes[scope] = parent_scope;
|
|
|
|
return;
|
2016-04-16 21:51:26 +03:00
|
|
|
}
|
|
|
|
|
2020-02-25 00:00:00 +00:00
|
|
|
let loc = cx.lookup_debug_loc(scope_data.span.lo());
|
2020-02-10 03:03:24 +02:00
|
|
|
let file_metadata = file_metadata(cx, &loc.file);
|
2017-04-24 19:01:19 +02:00
|
|
|
|
2020-02-11 01:27:33 +02:00
|
|
|
let dbg_scope = match scope_data.inlined {
|
|
|
|
Some((callee, _)) => {
|
|
|
|
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
|
|
|
|
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
|
|
|
|
let callee = cx.tcx.subst_and_normalize_erasing_regions(
|
|
|
|
instance.substs,
|
|
|
|
ty::ParamEnv::reveal_all(),
|
2020-10-24 02:21:18 +02:00
|
|
|
callee,
|
2020-02-11 01:27:33 +02:00
|
|
|
);
|
2021-09-02 00:29:15 +03:00
|
|
|
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
|
2021-09-30 19:38:50 +02:00
|
|
|
cx.dbg_scope_fn(callee, callee_fn_abi, None)
|
2020-02-11 01:27:33 +02:00
|
|
|
}
|
|
|
|
None => unsafe {
|
|
|
|
llvm::LLVMRustDIBuilderCreateLexicalBlock(
|
|
|
|
DIB(cx),
|
|
|
|
parent_scope.dbg_scope.unwrap(),
|
|
|
|
file_metadata,
|
2021-02-19 14:50:15 -06:00
|
|
|
loc.line,
|
|
|
|
loc.col,
|
2020-02-11 01:27:33 +02:00
|
|
|
)
|
|
|
|
},
|
2016-04-07 22:35:11 +03:00
|
|
|
};
|
2020-02-11 01:27:33 +02:00
|
|
|
|
|
|
|
let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {
|
|
|
|
// FIXME(eddyb) this doesn't account for the macro-related
|
|
|
|
// `Span` fixups that `rustc_codegen_ssa::mir::debuginfo` does.
|
|
|
|
let callsite_scope = parent_scope.adjust_dbg_scope_for_span(cx, callsite_span);
|
|
|
|
cx.dbg_loc(callsite_scope, parent_scope.inlined_at, callsite_span)
|
|
|
|
});
|
|
|
|
|
2019-09-11 17:52:39 +03:00
|
|
|
debug_context.scopes[scope] = DebugScope {
|
2020-02-11 01:27:33 +02:00
|
|
|
dbg_scope: Some(dbg_scope),
|
|
|
|
inlined_at: inlined_at.or(parent_scope.inlined_at),
|
2016-08-24 19:34:31 -07:00
|
|
|
file_start_pos: loc.file.start_pos,
|
|
|
|
file_end_pos: loc.file.end_pos,
|
|
|
|
};
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|