Skip to content

Commit 8edbbc4

Browse files
committed
Implement local reading for locals on stack
1 parent d8e9148 commit 8edbbc4

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

src/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
1717
let mut debug_context = cx
1818
.debug_context
1919
.as_mut()
20-
.map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name, &sig));
20+
.map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name));
2121

2222
// Make FunctionBuilder
2323
let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig);
@@ -61,6 +61,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
6161
let instance = fx.instance;
6262
let clif_comments = fx.clif_comments;
6363
let source_info_set = fx.source_info_set;
64+
let local_map = fx.local_map;
6465

6566
#[cfg(debug_assertions)]
6667
crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &func, &clif_comments, None);
@@ -92,7 +93,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
9293
let isa = cx.module.isa();
9394
debug_context
9495
.as_mut()
95-
.map(|x| x.define(context, isa, &source_info_set));
96+
.map(|x| x.define(context, isa, &source_info_set, local_map));
9697

9798
// Clear context to make it usable for the next function
9899
context.clear();

src/debuginfo/line_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::source_map::FileName;
55
use cranelift::codegen::binemit::CodeOffset;
66

77
use gimli::write::{
8-
Address, AttributeValue, FileId, LineProgram, LineString, LineStringTable, Range, UnitEntryId,
8+
Address, AttributeValue, FileId, LineProgram, LineString, LineStringTable, UnitEntryId,
99
};
1010

1111
fn line_program_add_file(

src/debuginfo/mod.rs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
172172
instance: Instance<'tcx>,
173173
func_id: FuncId,
174174
name: &str,
175-
_sig: &Signature,
176175
) -> Self {
177176
let mir = debug_context.tcx.instance_mir(instance.def);
178177

@@ -235,6 +234,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
235234
context: &Context,
236235
isa: &dyn cranelift::codegen::isa::TargetIsa,
237236
source_info_set: &indexmap::IndexSet<(Span, mir::SourceScope)>,
237+
local_map: HashMap<mir::Local, CPlace<'tcx>>,
238238
) {
239239
let end = self.create_debug_lines(context, isa, source_info_set);
240240

@@ -251,34 +251,53 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
251251

252252
let value_labels_ranges = context.build_value_labels_ranges(isa).unwrap();
253253

254-
for (value_label, value_loc_ranges) in value_labels_ranges.iter() {
255-
let var_id = self.define_local(mir::Local::from_u32(value_label.as_u32()));
256-
257-
let loc_list = LocationList(
258-
value_loc_ranges
259-
.iter()
260-
.map(|value_loc_range| Location::StartEnd {
261-
begin: Address::Symbol {
262-
symbol: self.symbol,
263-
addend: i64::from(value_loc_range.start),
264-
},
265-
end: Address::Symbol {
266-
symbol: self.symbol,
267-
addend: i64::from(value_loc_range.end),
268-
},
269-
data: Expression(
270-
translate_loc(value_loc_range.loc, &context.func.stack_slots).unwrap(),
271-
),
272-
})
273-
.collect(),
274-
);
275-
let loc_list_id = self.debug_context.dwarf.unit.locations.add(loc_list);
254+
for (local, _local_decl) in self.mir.local_decls.iter_enumerated() {
255+
let var_id = self.define_local(local);
256+
let value_label = cranelift::codegen::ir::ValueLabel::from_u32(local.as_u32());
257+
258+
let location = match local_map[&local].inner() {
259+
CPlaceInner::Var(_) => {
260+
if let Some(value_loc_ranges) = value_labels_ranges.get(&value_label) {
261+
let loc_list = LocationList(
262+
value_loc_ranges
263+
.iter()
264+
.map(|value_loc_range| Location::StartEnd {
265+
begin: Address::Symbol {
266+
symbol: self.symbol,
267+
addend: i64::from(value_loc_range.start),
268+
},
269+
end: Address::Symbol {
270+
symbol: self.symbol,
271+
addend: i64::from(value_loc_range.end),
272+
},
273+
data: Expression(
274+
translate_loc(value_loc_range.loc, &context.func.stack_slots).unwrap(),
275+
),
276+
})
277+
.collect(),
278+
);
279+
let loc_list_id = self.debug_context.dwarf.unit.locations.add(loc_list);
280+
281+
AttributeValue::LocationListRef(loc_list_id)
282+
} else {
283+
// FIXME set value labels for unused locals
284+
285+
AttributeValue::Exprloc(Expression(vec![]))
286+
}
287+
}
288+
CPlaceInner::Addr(_, _) => {
289+
// FIXME implement this (used by arguments and returns)
290+
291+
AttributeValue::Exprloc(Expression(vec![]))
292+
}
293+
CPlaceInner::Stack(stack_slot) => {
294+
AttributeValue::Exprloc(Expression(translate_loc(ValueLoc::Stack(*stack_slot), &context.func.stack_slots).unwrap()))
295+
}
296+
CPlaceInner::NoPlace => AttributeValue::Exprloc(Expression(vec![])),
297+
};
276298

277299
let var_entry = self.debug_context.dwarf.unit.get_mut(var_id);
278-
var_entry.set(
279-
gimli::DW_AT_location,
280-
AttributeValue::LocationListRef(loc_list_id),
281-
);
300+
var_entry.set(gimli::DW_AT_location, location);
282301
}
283302
}
284303
}

0 commit comments

Comments
 (0)