Skip to content

Commit

Permalink
mv map_reg
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Mar 10, 2020
1 parent 8330f30 commit e846762
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 66 deletions.
17 changes: 10 additions & 7 deletions crates/debug/src/frame.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::transform::map_reg;
use std::collections::HashMap;
use wasmtime_environ::entity::EntityRef;
use wasmtime_environ::isa::{CallConv, RegUnit, TargetIsa};
use wasmtime_environ::isa::{CallConv, TargetIsa};
use wasmtime_environ::wasm::DefinedFuncIndex;
use wasmtime_environ::{FrameLayoutChange, FrameLayouts};

Expand All @@ -10,10 +11,6 @@ use gimli::write::{
};
use gimli::{Encoding, Format, Register, X86_64};

fn map_reg(isa: &dyn TargetIsa, reg: RegUnit) -> Register {
crate::transform::map_reg(isa, reg).unwrap()
}

fn to_cfi(
isa: &dyn TargetIsa,
change: &FrameLayoutChange,
Expand All @@ -22,7 +19,10 @@ fn to_cfi(
) -> Option<CallFrameInstruction> {
Some(match change {
FrameLayoutChange::CallFrameAddressAt { reg, offset } => {
let mapped = map_reg(isa, *reg);
let mapped = match map_reg(isa, *reg) {
Ok(r) => r,
Err(_) => return None,
};
let offset = (*offset) as i32;
if mapped != *cfa_def_reg && offset != *cfa_def_offset {
*cfa_def_reg = mapped;
Expand All @@ -41,7 +41,10 @@ fn to_cfi(
FrameLayoutChange::RegAt { reg, cfa_offset } => {
assert!(cfa_offset % -8 == 0);
let cfa_offset = *cfa_offset as i32;
let mapped = map_reg(isa, *reg);
let mapped = match map_reg(isa, *reg) {
Ok(r) => r,
Err(_) => return None,
};
CallFrameInstruction::Offset(mapped, cfa_offset)
}
FrameLayoutChange::ReturnAddressAt { cfa_offset } => {
Expand Down
62 changes: 4 additions & 58 deletions crates/debug/src/transform/expression.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::address_transform::AddressTransform;
use anyhow::{bail, Context, Error, Result};
use gimli::{self, write, Expression, Operation, Reader, ReaderOffset, Register, X86_64};
use super::map_reg::map_reg;
use anyhow::{Context, Error, Result};
use gimli::{self, write, Expression, Operation, Reader, ReaderOffset, X86_64};
use more_asserts::{assert_le, assert_lt};
use std::collections::{HashMap, HashSet};
use wasmtime_environ::entity::EntityRef;
use wasmtime_environ::ir::{StackSlots, ValueLabel, ValueLabelsRanges, ValueLoc};
use wasmtime_environ::isa::{RegUnit, TargetIsa};
use wasmtime_environ::isa::TargetIsa;
use wasmtime_environ::wasm::{get_vmctx_value_label, DefinedFuncIndex};
use wasmtime_environ::ModuleMemoryOffset;

Expand Down Expand Up @@ -70,61 +71,6 @@ impl<'a> CompiledExpression<'a> {
}
}

pub(crate) fn map_reg(isa: &dyn TargetIsa, reg: RegUnit) -> Result<Register> {
// TODO avoid duplication with fde.rs
assert!(isa.name() == "x86" && isa.pointer_bits() == 64);
// Mapping from https://github.com/bytecodealliance/cranelift/pull/902 by @iximeow
const X86_GP_REG_MAP: [gimli::Register; 16] = [
X86_64::RAX,
X86_64::RCX,
X86_64::RDX,
X86_64::RBX,
X86_64::RSP,
X86_64::RBP,
X86_64::RSI,
X86_64::RDI,
X86_64::R8,
X86_64::R9,
X86_64::R10,
X86_64::R11,
X86_64::R12,
X86_64::R13,
X86_64::R14,
X86_64::R15,
];
const X86_XMM_REG_MAP: [gimli::Register; 16] = [
X86_64::XMM0,
X86_64::XMM1,
X86_64::XMM2,
X86_64::XMM3,
X86_64::XMM4,
X86_64::XMM5,
X86_64::XMM6,
X86_64::XMM7,
X86_64::XMM8,
X86_64::XMM9,
X86_64::XMM10,
X86_64::XMM11,
X86_64::XMM12,
X86_64::XMM13,
X86_64::XMM14,
X86_64::XMM15,
];
let reg_info = isa.register_info();
let bank = reg_info.bank_containing_regunit(reg).unwrap();
match bank.name {
"IntRegs" => {
// x86 GP registers have a weird mapping to DWARF registers, so we use a
// lookup table.
Ok(X86_GP_REG_MAP[(reg - bank.first_unit) as usize])
}
"FloatRegs" => Ok(X86_XMM_REG_MAP[(reg - bank.first_unit) as usize]),
bank_name => {
bail!("unsupported register bank: {}", bank_name);
}
}
}

fn translate_loc(
loc: ValueLoc,
frame_info: Option<&FunctionFrameInfo>,
Expand Down
58 changes: 58 additions & 0 deletions crates/debug/src/transform/map_reg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use anyhow::{bail, Result};
use gimli::{Register, X86_64};
use wasmtime_environ::isa::{RegUnit, TargetIsa};

pub(crate) fn map_reg(isa: &dyn TargetIsa, reg: RegUnit) -> Result<Register> {
// TODO avoid duplication with fde.rs
assert!(isa.name() == "x86" && isa.pointer_bits() == 64);
// Mapping from https://github.com/bytecodealliance/cranelift/pull/902 by @iximeow
const X86_GP_REG_MAP: [Register; 16] = [
X86_64::RAX,
X86_64::RCX,
X86_64::RDX,
X86_64::RBX,
X86_64::RSP,
X86_64::RBP,
X86_64::RSI,
X86_64::RDI,
X86_64::R8,
X86_64::R9,
X86_64::R10,
X86_64::R11,
X86_64::R12,
X86_64::R13,
X86_64::R14,
X86_64::R15,
];
const X86_XMM_REG_MAP: [Register; 16] = [
X86_64::XMM0,
X86_64::XMM1,
X86_64::XMM2,
X86_64::XMM3,
X86_64::XMM4,
X86_64::XMM5,
X86_64::XMM6,
X86_64::XMM7,
X86_64::XMM8,
X86_64::XMM9,
X86_64::XMM10,
X86_64::XMM11,
X86_64::XMM12,
X86_64::XMM13,
X86_64::XMM14,
X86_64::XMM15,
];
let reg_info = isa.register_info();
let bank = reg_info.bank_containing_regunit(reg).unwrap();
match bank.name {
"IntRegs" => {
// x86 GP registers have a weird mapping to DWARF registers, so we use a
// lookup table.
Ok(X86_GP_REG_MAP[(reg - bank.first_unit) as usize])
}
"FloatRegs" => Ok(X86_XMM_REG_MAP[(reg - bank.first_unit) as usize]),
bank_name => {
bail!("unsupported register bank: {}", bank_name);
}
}
}
3 changes: 2 additions & 1 deletion crates/debug/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ use wasmtime_environ::isa::TargetIsa;
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};

pub use address_transform::AddressTransform;
pub(crate) use expression::map_reg;
pub(crate) use map_reg::map_reg;

mod address_transform;
mod attr;
mod expression;
mod line_program;
mod map_reg;
mod range_info_builder;
mod refs;
mod simulate;
Expand Down

0 comments on commit e846762

Please sign in to comment.