diff --git a/src/base.rs b/src/base.rs index 705629888aa..91c25873313 100644 --- a/src/base.rs +++ b/src/base.rs @@ -21,6 +21,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( // Make FunctionBuilder let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig); + func.collect_debug_info(); let mut func_ctx = FunctionBuilderContext::new(); let mut bcx = FunctionBuilder::new(&mut func, &mut func_ctx); diff --git a/src/debuginfo.rs b/src/debuginfo.rs index e6d133c6451..0998236e582 100644 --- a/src/debuginfo.rs +++ b/src/debuginfo.rs @@ -305,6 +305,48 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { let entry = self.debug_context.dwarf.unit.get_mut(self.entry_id); entry.set(gimli::DW_AT_high_pc, AttributeValue::Udata(end as u64)); + { + let value_labels_ranges = context.build_value_labels_ranges(isa).unwrap(); + + for (value_label, value_loc_ranges) in value_labels_ranges.iter() { + let live_ranges = RangeList( + Some(Range::BaseAddress { + address: Address::Symbol { + symbol: self.symbol, + addend: 0, + }, + }) + .into_iter() + .chain( + value_loc_ranges + .iter() + .map(|val_loc_range| Range::OffsetPair { + begin: u64::from(val_loc_range.start), + end: u64::from(val_loc_range.end), + }), + ) + .collect(), + ); + let live_ranges_id = self.debug_context.dwarf.unit.ranges.add(live_ranges); + + let var_id = self + .debug_context + .dwarf + .unit + .add(self.entry_id, gimli::DW_TAG_variable); + let var_entry = self.debug_context.dwarf.unit.get_mut(var_id); + + var_entry.set( + gimli::DW_AT_ranges, + AttributeValue::RangeListRef(live_ranges_id), + ); + var_entry.set( + gimli::DW_AT_name, + AttributeValue::String(format!("{:?}", value_label).into_bytes()), + ); + } + } + self.debug_context .unit_range_list .0 diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 142795a91eb..8016a802dab 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -299,7 +299,11 @@ impl<'tcx> CPlace<'tcx> { pub fn to_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CValue<'tcx> { let layout = self.layout(); match self.inner { - CPlaceInner::Var(var) => CValue::by_val(fx.bcx.use_var(mir_var(var)), layout), + CPlaceInner::Var(var) => { + let val = fx.bcx.use_var(mir_var(var)); + fx.bcx.set_val_label(val, cranelift::codegen::ir::ValueLabel::from_u32(var.as_u32())); + CValue::by_val(val, layout) + } CPlaceInner::Addr(addr, extra) => { assert!(extra.is_none(), "unsized values are not yet supported"); CValue::by_ref(addr, layout)