Support emitting inline breakpoints in singlepass.

This commit is contained in:
losfair 2019-10-11 21:05:42 +08:00
parent 94f97109ff
commit 36f95fc660
3 changed files with 22 additions and 1 deletions

View File

@ -1904,11 +1904,12 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
Event::Internal(x) => {
match x {
InternalEvent::Breakpoint(callback) => {
a.emit_bkpt();
use wasmer_runtime_core::backend::InlineBreakpointType;
self.breakpoints
.as_mut()
.unwrap()
.insert(a.get_offset(), callback);
a.emit_inline_breakpoint(InlineBreakpointType::Middleware);
}
InternalEvent::FunctionBegin(_) | InternalEvent::FunctionEnd => {}
InternalEvent::GetInternal(idx) => {

View File

@ -1,5 +1,6 @@
use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
pub use wasmer_runtime_core::state::x64_decl::{GPR, XMM};
use wasmer_runtime_core::backend::{InlineBreakpointType};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Location {
@ -171,6 +172,7 @@ pub trait Emitter {
fn emit_bkpt(&mut self);
fn emit_homomorphic_host_redirection(&mut self, target: GPR);
fn emit_inline_breakpoint(&mut self, ty: InlineBreakpointType);
}
fn _dummy(a: &mut Assembler) {
@ -951,4 +953,13 @@ impl Emitter for Assembler {
fn emit_homomorphic_host_redirection(&mut self, target: GPR) {
self.emit_jmp_location(Location::GPR(target));
}
fn emit_inline_breakpoint(&mut self, ty: InlineBreakpointType) {
dynasm!(self
; ud2
; .byte 0x0f ; .byte (0xb9u8 as i8) // ud
; int -1
; .byte (ty as u8 as i8)
);
}
}

View File

@ -3,6 +3,7 @@
use crate::codegen_x64::*;
use crate::emitter_x64::*;
use dynasmrt::{aarch64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
use wasmer_runtime_core::backend::{InlineBreakpointType};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub struct AX(pub u32);
@ -1474,6 +1475,14 @@ impl Emitter for Assembler {
; br x_tmp1
);
}
fn emit_inline_breakpoint(&mut self, ty: InlineBreakpointType) {
dynasm!(self
; .dword 0
; .dword -1
; .dword (ty as u8 as i32)
);
}
}
fn emit_clz_variant(assembler: &mut Assembler, sz: Size, src: &Location, dst: &Location, reversed: bool) {