From 103d68d6c5e6201f76a17b14b29ddca82ad02350 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Tue, 28 Apr 2020 15:54:48 +1000 Subject: [PATCH] WIP update gimli --- Cargo.lock | 2 -- Cargo.toml | 3 ++ cranelift/codegen/src/isa/unwind/systemv.rs | 37 +-------------------- crates/debug/src/transform/attr.rs | 2 +- crates/debug/src/transform/expression.rs | 10 +++--- crates/debug/src/transform/refs.rs | 4 +-- crates/debug/src/transform/simulate.rs | 2 +- crates/debug/src/transform/unit.rs | 16 ++++----- crates/debug/src/transform/utils.rs | 10 +++--- 9 files changed, 26 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6881d48021e3..4b886f046aa0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -899,8 +899,6 @@ dependencies = [ [[package]] name = "gimli" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633" dependencies = [ "arrayvec", "byteorder", diff --git a/Cargo.toml b/Cargo.toml index d68ed6f44fd1..024ae162a1c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,3 +85,6 @@ maintenance = { status = "actively-developed" } [[test]] name = "host_segfault" harness = false + +[patch.crates-io] +gimli = { path = "../gimli" } diff --git a/cranelift/codegen/src/isa/unwind/systemv.rs b/cranelift/codegen/src/isa/unwind/systemv.rs index 5985082f7195..d9583f7b4d74 100644 --- a/cranelift/codegen/src/isa/unwind/systemv.rs +++ b/cranelift/codegen/src/isa/unwind/systemv.rs @@ -8,7 +8,6 @@ use thiserror::Error; use serde::{Deserialize, Serialize}; type Register = u16; -type Expression = Vec; /// Enumerate the errors possible in mapping Cranelift registers to their DWARF equivalent. #[allow(missing_docs)] @@ -30,48 +29,21 @@ pub(crate) enum CallFrameInstruction { Cfa(Register, i32), CfaRegister(Register), CfaOffset(i32), - CfaExpression(Expression), Restore(Register), Undefined(Register), SameValue(Register), Offset(Register, i32), ValOffset(Register, i32), Register(Register, Register), - Expression(Register, Expression), - ValExpression(Register, Expression), RememberState, RestoreState, ArgsSize(u32), } -impl From for CallFrameInstruction { - fn from(cfi: gimli::write::CallFrameInstruction) -> Self { - use gimli::write::CallFrameInstruction; - - match cfi { - CallFrameInstruction::Cfa(reg, offset) => Self::Cfa(reg.0, offset), - CallFrameInstruction::CfaRegister(reg) => Self::CfaRegister(reg.0), - CallFrameInstruction::CfaOffset(offset) => Self::CfaOffset(offset), - CallFrameInstruction::CfaExpression(expr) => Self::CfaExpression(expr.0), - CallFrameInstruction::Restore(reg) => Self::Restore(reg.0), - CallFrameInstruction::Undefined(reg) => Self::Undefined(reg.0), - CallFrameInstruction::SameValue(reg) => Self::SameValue(reg.0), - CallFrameInstruction::Offset(reg, offset) => Self::Offset(reg.0, offset), - CallFrameInstruction::ValOffset(reg, offset) => Self::ValOffset(reg.0, offset), - CallFrameInstruction::Register(reg1, reg2) => Self::Register(reg1.0, reg2.0), - CallFrameInstruction::Expression(reg, expr) => Self::Expression(reg.0, expr.0), - CallFrameInstruction::ValExpression(reg, expr) => Self::ValExpression(reg.0, expr.0), - CallFrameInstruction::RememberState => Self::RememberState, - CallFrameInstruction::RestoreState => Self::RestoreState, - CallFrameInstruction::ArgsSize(size) => Self::ArgsSize(size), - } - } -} - impl Into for CallFrameInstruction { fn into(self) -> gimli::write::CallFrameInstruction { use gimli::{ - write::{CallFrameInstruction, Expression}, + write::CallFrameInstruction, Register, }; @@ -79,7 +51,6 @@ impl Into for CallFrameInstruction { Self::Cfa(reg, offset) => CallFrameInstruction::Cfa(Register(reg), offset), Self::CfaRegister(reg) => CallFrameInstruction::CfaRegister(Register(reg)), Self::CfaOffset(offset) => CallFrameInstruction::CfaOffset(offset), - Self::CfaExpression(expr) => CallFrameInstruction::CfaExpression(Expression(expr)), Self::Restore(reg) => CallFrameInstruction::Restore(Register(reg)), Self::Undefined(reg) => CallFrameInstruction::Undefined(Register(reg)), Self::SameValue(reg) => CallFrameInstruction::SameValue(Register(reg)), @@ -88,12 +59,6 @@ impl Into for CallFrameInstruction { Self::Register(reg1, reg2) => { CallFrameInstruction::Register(Register(reg1), Register(reg2)) } - Self::Expression(reg, expr) => { - CallFrameInstruction::Expression(Register(reg), Expression(expr)) - } - Self::ValExpression(reg, expr) => { - CallFrameInstruction::ValExpression(Register(reg), Expression(expr)) - } Self::RememberState => CallFrameInstruction::RememberState, Self::RestoreState => CallFrameInstruction::RestoreState, Self::ArgsSize(size) => CallFrameInstruction::ArgsSize(size), diff --git a/crates/debug/src/transform/attr.rs b/crates/debug/src/transform/attr.rs index 0820a82b17ab..f5674f634246 100644 --- a/crates/debug/src/transform/attr.rs +++ b/crates/debug/src/transform/attr.rs @@ -217,7 +217,7 @@ where let mut found_expr: Option = None; for (_, _, expr) in &exprs { if let Some(ref prev_expr) = found_expr { - if expr.0.eq(&prev_expr.0) { + if expr == prev_expr { continue; // the same expression } found_expr = None; diff --git a/crates/debug/src/transform/expression.rs b/crates/debug/src/transform/expression.rs index 81394f8371d8..c0c45e964fad 100644 --- a/crates/debug/src/transform/expression.rs +++ b/crates/debug/src/transform/expression.rs @@ -173,7 +173,7 @@ impl<'a> CompiledExpression<'a> { pub fn build(&self) -> Option { if let [CompiledExpressionPart::Code(code)] = self.parts.as_slice() { - return Some(write::Expression(code.to_vec())); + return Some(write::Expression::raw(code.to_vec())); } // locals found, not supported None @@ -194,7 +194,7 @@ impl<'a> CompiledExpression<'a> { let mut result_scope = Vec::new(); for s in scope { for (addr, len) in addr_tr.translate_ranges(s.0, s.1) { - result_scope.push((addr, len, write::Expression(code.to_vec()))); + result_scope.push((addr, len, write::Expression::raw(code.to_vec()))); } } return Ok(result_scope); @@ -281,7 +281,7 @@ impl<'a> CompiledExpression<'a> { addend: start as i64, }, (end - start) as u64, - write::Expression(code_buf), + write::Expression::raw(code_buf), )); } @@ -348,7 +348,7 @@ where parts.push(CompiledExpressionPart::Local(label)); } else { let pos = pc.offset_from(&expr.0).into_u64() as usize; - let op = Operation::parse(&mut pc, &expr.0, encoding)?; + let op = Operation::parse(&mut pc, encoding)?; match op { Operation::FrameOffset { offset } => { // Expand DW_OP_fpreg into frame location and DW_OP_plus_uconst. @@ -370,7 +370,7 @@ where code_chunk.extend(writer.into_vec()); continue; } - Operation::Literal { .. } | Operation::PlusConstant { .. } => (), + Operation::UnsignedConstant { .. } | Operation::SignedConstant { .. } | Operation::PlusConstant { .. } => (), Operation::StackValue => { need_deref = false; } diff --git a/crates/debug/src/transform/refs.rs b/crates/debug/src/transform/refs.rs index 1780f06495e6..4afe734afb7a 100644 --- a/crates/debug/src/transform/refs.rs +++ b/crates/debug/src/transform/refs.rs @@ -58,7 +58,7 @@ impl UnitRefsMap { for (die_id, attr_name, offset) in refs.refs { let die = comp_unit.get_mut(die_id); if let Some(unit_id) = self.map.get(&offset) { - die.set(attr_name, write::AttributeValue::ThisUnitEntryRef(*unit_id)); + die.set(attr_name, write::AttributeValue::UnitRef(*unit_id)); } } } @@ -102,7 +102,7 @@ impl DebugInfoRefsMap { if let Some((id, entry_id)) = self.map.get(&offset) { die.set( attr_name, - write::AttributeValue::AnyUnitEntryRef((*id, *entry_id)), + write::AttributeValue::DebugInfoRef(write::Reference::Entry(*id, *entry_id)), ); } } diff --git a/crates/debug/src/transform/simulate.rs b/crates/debug/src/transform/simulate.rs index ec70dec4ea7f..7e0f47c95cc1 100644 --- a/crates/debug/src/transform/simulate.rs +++ b/crates/debug/src/transform/simulate.rs @@ -265,7 +265,7 @@ fn generate_vars( var.set(gimli::DW_AT_name, write::AttributeValue::StringRef(name_id)); var.set( gimli::DW_AT_type, - write::AttributeValue::ThisUnitEntryRef(type_die_id), + write::AttributeValue::UnitRef(type_die_id), ); var.set( gimli::DW_AT_location, diff --git a/crates/debug/src/transform/unit.rs b/crates/debug/src/transform/unit.rs index c37788e5fa37..5eecaabcdd2c 100644 --- a/crates/debug/src/transform/unit.rs +++ b/crates/debug/src/transform/unit.rs @@ -132,7 +132,7 @@ where // Build DW_TAG_pointer_type for `WebAssemblyPtrWrapper*`: // .. DW_AT_type = add_tag!(parent_id, gimli::DW_TAG_pointer_type => wrapper_ptr_type as wrapper_ptr_type_id { - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_die_id) + gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_die_id) }); let base_type_id = pointer_type_entry.attr_value(gimli::DW_AT_type)?; @@ -166,7 +166,7 @@ where // .. DW_AT_location = 0 add_tag!(wrapper_die_id, gimli::DW_TAG_member => m_die as m_die_id { gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("__ptr")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wp_die_id), + gimli::DW_AT_type = write::AttributeValue::UnitRef(wp_die_id), gimli::DW_AT_data_member_location = write::AttributeValue::Data1(0) }); @@ -180,10 +180,10 @@ where add_tag!(wrapper_die_id, gimli::DW_TAG_subprogram => deref_op_die as deref_op_die_id { gimli::DW_AT_linkage_name = write::AttributeValue::StringRef(out_strings.add("resolve_vmctx_memory_ptr")), gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("ptr")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(ptr_type_id) + gimli::DW_AT_type = write::AttributeValue::UnitRef(ptr_type_id) }); add_tag!(deref_op_die_id, gimli::DW_TAG_formal_parameter => deref_op_this_param as deref_op_this_param_id { - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_ptr_type_id), + gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_ptr_type_id), gimli::DW_AT_artificial = write::AttributeValue::Flag(true) }); @@ -197,10 +197,10 @@ where add_tag!(wrapper_die_id, gimli::DW_TAG_subprogram => deref_op_die as deref_op_die_id { gimli::DW_AT_linkage_name = write::AttributeValue::StringRef(out_strings.add("resolve_vmctx_memory_ptr")), gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("operator*")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(ref_type_id) + gimli::DW_AT_type = write::AttributeValue::UnitRef(ref_type_id) }); add_tag!(deref_op_die_id, gimli::DW_TAG_formal_parameter => deref_op_this_param as deref_op_this_param_id { - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_ptr_type_id), + gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_ptr_type_id), gimli::DW_AT_artificial = write::AttributeValue::Flag(true) }); @@ -214,10 +214,10 @@ where add_tag!(wrapper_die_id, gimli::DW_TAG_subprogram => deref_op_die as deref_op_die_id { gimli::DW_AT_linkage_name = write::AttributeValue::StringRef(out_strings.add("resolve_vmctx_memory_ptr")), gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("operator->")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(ptr_type_id) + gimli::DW_AT_type = write::AttributeValue::UnitRef(ptr_type_id) }); add_tag!(deref_op_die_id, gimli::DW_TAG_formal_parameter => deref_op_this_param as deref_op_this_param_id { - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(wrapper_ptr_type_id), + gimli::DW_AT_type = write::AttributeValue::UnitRef(wrapper_ptr_type_id), gimli::DW_AT_artificial = write::AttributeValue::Flag(true) }); diff --git a/crates/debug/src/transform/utils.rs b/crates/debug/src/transform/utils.rs index 506b6b71c008..a75bf0c7627a 100644 --- a/crates/debug/src/transform/utils.rs +++ b/crates/debug/src/transform/utils.rs @@ -56,7 +56,7 @@ pub(crate) fn add_internal_types( // .. DW_AT_type = add_tag!(root_id, gimli::DW_TAG_pointer_type => memory_bytes_die as memory_bytes_die_id { gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("u8*")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(memory_byte_die_id) + gimli::DW_AT_type = write::AttributeValue::UnitRef(memory_byte_die_id) }); // Create artificial VMContext type and its reference for convinience viewing @@ -87,7 +87,7 @@ pub(crate) fn add_internal_types( // .. DW_AT_data_member_location = `memory_offset` add_tag!(vmctx_die_id, gimli::DW_TAG_member => m_die as m_die_id { gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("memory")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(memory_bytes_die_id), + gimli::DW_AT_type = write::AttributeValue::UnitRef(memory_bytes_die_id), gimli::DW_AT_data_member_location = write::AttributeValue::Udata(memory_offset as u64) }); } @@ -102,7 +102,7 @@ pub(crate) fn add_internal_types( // .. DW_AT_type = add_tag!(root_id, gimli::DW_TAG_pointer_type => vmctx_ptr_die as vmctx_ptr_die_id { gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("WasmtimeVMContext*")), - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(vmctx_die_id) + gimli::DW_AT_type = write::AttributeValue::UnitRef(vmctx_die_id) }); // Build vmctx_die's DW_TAG_subprogram for `set` method: @@ -116,7 +116,7 @@ pub(crate) fn add_internal_types( gimli::DW_AT_name = write::AttributeValue::StringRef(out_strings.add("set")) }); add_tag!(vmctx_set_id, gimli::DW_TAG_formal_parameter => vmctx_set_this_param as vmctx_set_this_param_id { - gimli::DW_AT_type = write::AttributeValue::ThisUnitEntryRef(vmctx_ptr_die_id), + gimli::DW_AT_type = write::AttributeValue::UnitRef(vmctx_ptr_die_id), gimli::DW_AT_artificial = write::AttributeValue::Flag(true) }); @@ -159,7 +159,7 @@ pub(crate) fn append_vmctx_info( ); var_die.set( gimli::DW_AT_type, - write::AttributeValue::ThisUnitEntryRef(vmctx_die_id), + write::AttributeValue::UnitRef(vmctx_die_id), ); var_die.set(gimli::DW_AT_location, loc);