Use IndexSet and keep full source info in set_debug_loc
This commit is contained in:
parent
6b5cbc540d
commit
a12eef4d86
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -597,6 +597,7 @@ dependencies = [
|
||||
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"faerie 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gimli 0.16.1 (git+https://github.com/gimli-rs/gimli.git)",
|
||||
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -29,6 +29,7 @@ tempfile = "3.0.4"
|
||||
env_logger = "0.6"
|
||||
gimli = { git = "https://github.com/gimli-rs/gimli.git" }
|
||||
faerie = "0.7.1"
|
||||
indexmap = "1.0.2"
|
||||
|
||||
# Uncomment to use local checkout of cranelift
|
||||
#[patch."https://github.com/CraneStation/cranelift.git"]
|
||||
|
@ -108,7 +108,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
|
||||
clif_comments,
|
||||
constants: &mut cx.ccx,
|
||||
caches: &mut cx.caches,
|
||||
spans: Vec::new(),
|
||||
source_info_set: indexmap::IndexSet::new(),
|
||||
};
|
||||
|
||||
// Step 6. Codegen function
|
||||
@ -116,7 +116,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
|
||||
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
|
||||
codegen_fn_content(&mut fx);
|
||||
});
|
||||
let spans = fx.spans.clone();
|
||||
let source_info_set = fx.source_info_set.clone();
|
||||
|
||||
// Step 7. Write function to file for debugging
|
||||
#[cfg(debug_assertions)]
|
||||
@ -129,7 +129,7 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
|
||||
cx.caches.context.func = func;
|
||||
cx.module
|
||||
.define_function_peek_compiled(func_id, &mut cx.caches.context, |size, context, isa| {
|
||||
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &spans[..]));
|
||||
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &source_info_set));
|
||||
})
|
||||
.unwrap();
|
||||
//let module = &mut cx.module;
|
||||
|
@ -539,7 +539,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, B: Backend> {
|
||||
pub clif_comments: crate::pretty_clif::CommentWriter,
|
||||
pub constants: &'a mut crate::constant::ConstantCx,
|
||||
pub caches: &'a mut Caches<'tcx>,
|
||||
pub spans: Vec<Span>,
|
||||
pub source_info_set: indexmap::IndexSet<SourceInfo>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> {
|
||||
@ -620,9 +620,7 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
|
||||
}
|
||||
|
||||
pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
|
||||
// FIXME: record scope too
|
||||
let index = self.spans.len() as u32;
|
||||
self.spans.push(source_info.span);
|
||||
self.bcx.set_srcloc(SourceLoc::new(index));
|
||||
let (index, _) = self.source_info_set.insert_full(source_info);
|
||||
self.bcx.set_srcloc(SourceLoc::new(index as u32));
|
||||
}
|
||||
}
|
||||
|
@ -36,14 +36,16 @@ pub struct DebugContext<'tcx> {
|
||||
version: u16,
|
||||
address_size: u8,
|
||||
|
||||
symbols: indexmap::IndexSet<String>,
|
||||
|
||||
strings: StringTable,
|
||||
units: UnitTable,
|
||||
unit_id: UnitId,
|
||||
line_programs: LineProgramTable,
|
||||
global_line_program: LineProgramId,
|
||||
range_lists: RangeListTable,
|
||||
|
||||
unit_id: UnitId,
|
||||
global_line_program: LineProgramId,
|
||||
unit_range_list: RangeList,
|
||||
symbol_names: Vec<String>,
|
||||
|
||||
_dummy: PhantomData<&'tcx ()>,
|
||||
}
|
||||
@ -115,14 +117,17 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> {
|
||||
version,
|
||||
address_size,
|
||||
|
||||
symbols: indexmap::IndexSet::new(),
|
||||
|
||||
strings,
|
||||
units,
|
||||
unit_id,
|
||||
line_programs,
|
||||
global_line_program,
|
||||
range_lists,
|
||||
|
||||
unit_id,
|
||||
global_line_program,
|
||||
unit_range_list: RangeList(Vec::new()),
|
||||
symbol_names: Vec::new(),
|
||||
|
||||
_dummy: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -345,8 +350,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
|
||||
name: &str,
|
||||
_sig: &Signature,
|
||||
) -> Self {
|
||||
let symbol = debug_context.symbol_names.len();
|
||||
debug_context.symbol_names.push(name.to_string());
|
||||
let (symbol, _) = debug_context.symbols.insert_full(name.to_string());
|
||||
|
||||
let unit = debug_context.units.get_mut(debug_context.unit_id);
|
||||
// FIXME: add to appropriate scope intead of root
|
||||
@ -382,7 +386,7 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
|
||||
size: u32,
|
||||
context: &Context,
|
||||
isa: &cranelift::codegen::isa::TargetIsa,
|
||||
spans: &[Span],
|
||||
source_info_set: &indexmap::IndexSet<SourceInfo>,
|
||||
) {
|
||||
let unit = self.debug_context.units.get_mut(self.debug_context.unit_id);
|
||||
// FIXME: add to appropriate scope intead of root
|
||||
@ -439,8 +443,8 @@ impl<'a, 'b, 'tcx: 'b> FunctionDebugContext<'a, 'tcx> {
|
||||
|
||||
let srcloc = func.srclocs[inst];
|
||||
if !srcloc.is_default() {
|
||||
let span = spans[srcloc.bits() as usize];
|
||||
create_row_for_span(tcx, line_program, offset as u64, span);
|
||||
let source_info = *source_info_set.get_index(srcloc.bits() as usize).unwrap();
|
||||
create_row_for_span(tcx, line_program, offset as u64, source_info.span);
|
||||
} else {
|
||||
create_row_for_span(tcx, line_program, offset as u64, self.mir_span);
|
||||
}
|
||||
@ -495,7 +499,7 @@ impl<'a, 'tcx> Writer for WriterRelocate<'a, 'tcx> {
|
||||
self.relocs.push(DebugReloc {
|
||||
offset: offset as u32,
|
||||
size,
|
||||
name: self.ctx.symbol_names[symbol].clone(),
|
||||
name: self.ctx.symbols.get_index(symbol).unwrap().clone(),
|
||||
addend: addend as i64,
|
||||
});
|
||||
self.write_word(0, size)
|
||||
|
Loading…
x
Reference in New Issue
Block a user