Skip to content

Commit

Permalink
WIP update gimli
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Apr 28, 2020
1 parent 4d2670a commit 103d68d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 60 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ maintenance = { status = "actively-developed" }
[[test]]
name = "host_segfault"
harness = false

[patch.crates-io]
gimli = { path = "../gimli" }
37 changes: 1 addition & 36 deletions cranelift/codegen/src/isa/unwind/systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use thiserror::Error;
use serde::{Deserialize, Serialize};

type Register = u16;
type Expression = Vec<u8>;

/// Enumerate the errors possible in mapping Cranelift registers to their DWARF equivalent.
#[allow(missing_docs)]
Expand All @@ -30,56 +29,28 @@ 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<gimli::write::CallFrameInstruction> 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<gimli::write::CallFrameInstruction> for CallFrameInstruction {
fn into(self) -> gimli::write::CallFrameInstruction {
use gimli::{
write::{CallFrameInstruction, Expression},
write::CallFrameInstruction,
Register,
};

match self {
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)),
Expand All @@ -88,12 +59,6 @@ impl Into<gimli::write::CallFrameInstruction> 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),
Expand Down
2 changes: 1 addition & 1 deletion crates/debug/src/transform/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ where
let mut found_expr: Option<write::Expression> = 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;
Expand Down
10 changes: 5 additions & 5 deletions crates/debug/src/transform/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'a> CompiledExpression<'a> {

pub fn build(&self) -> Option<write::Expression> {
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
Expand All @@ -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);
Expand Down Expand Up @@ -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),
));
}

Expand Down Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/debug/src/transform/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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)),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/debug/src/transform/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions crates/debug/src/transform/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ where
// Build DW_TAG_pointer_type for `WebAssemblyPtrWrapper<T>*`:
// .. DW_AT_type = <wrapper_die>
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)?;
Expand Down Expand Up @@ -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)
});

Expand All @@ -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)
});

Expand All @@ -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)
});

Expand All @@ -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)
});

Expand Down
10 changes: 5 additions & 5 deletions crates/debug/src/transform/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn add_internal_types(
// .. DW_AT_type = <memory_byte_die>
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
Expand Down Expand Up @@ -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)
});
}
Expand All @@ -102,7 +102,7 @@ pub(crate) fn add_internal_types(
// .. DW_AT_type = <vmctx_die>
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:
Expand All @@ -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)
});

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 103d68d

Please sign in to comment.