Path: blob/main/crates/cranelift/src/debug/transform/utils.rs
3064 views
use crate::debug::Reader;12use super::address_transform::AddressTransform;3use super::expression::{CompiledExpression, FunctionFrameInfo};4use cranelift_codegen::isa::TargetIsa;5use gimli::{AttributeValue, UnitRef, write};6use wasmtime_environ::error::Error;78pub(crate) fn append_vmctx_info(9comp_unit: &mut write::Unit,10parent_id: write::UnitEntryId,11vmctx_ptr_die_ref: write::DebugInfoRef,12addr_tr: &AddressTransform,13frame_info: Option<&FunctionFrameInfo>,14scope_ranges: &[(u64, u64)],15out_strings: &mut write::StringTable,16isa: &dyn TargetIsa,17) -> Result<(), Error> {18let loc = {19let expr = CompiledExpression::vmctx();20let locs = expr21.build_with_locals(scope_ranges, addr_tr, frame_info, isa)22.expressions23.map(|i| {24i.map(|(begin, length, data)| write::Location::StartLength {25begin,26length,27data,28})29})30.collect::<Result<Vec<_>, _>>()?;31let list_id = comp_unit.locations.add(write::LocationList(locs));32write::AttributeValue::LocationListRef(list_id)33};3435let var_die_id = comp_unit.add(parent_id, gimli::DW_TAG_variable);36let var_die = comp_unit.get_mut(var_die_id);37var_die.set(38gimli::DW_AT_name,39write::AttributeValue::StringRef(out_strings.add("__vmctx")),40);41var_die.set(42gimli::DW_AT_type,43write::AttributeValue::DebugInfoRef(vmctx_ptr_die_ref),44);45var_die.set(gimli::DW_AT_location, loc);4647Ok(())48}4950pub fn resolve_die_ref<'a, 'r>(51unit: UnitRef<'a, Reader<'r>>,52die_ref: &AttributeValue<Reader<'r>>,53) -> Result<Option<write::ConvertUnitEntry<'a, Reader<'r>>>, Error> {54let die = match die_ref {55AttributeValue::UnitRef(unit_offs) => {56Some(write::ConvertUnitEntry::read(unit, *unit_offs)?)57}58// TODO-DebugInfo: support AttributeValue::DebugInfoRef. The trouble is that we don't have59// a fast way to go from a DI offset to a unit offset (which is needed to parse the DIE).60// We would likely need to maintain a cache.61_ => None,62};63Ok(die)64}656667