Browse Source

Implement FIXME in debug/src/expression.rs (#902)

pull/903/head
Yury Delendik 5 years ago
committed by GitHub
parent
commit
b3ac718421
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      crates/debug/src/transform/expression.rs
  2. 10
      crates/fuzzing/src/oracles.rs
  3. 10
      crates/fuzzing/tests/regressions.rs
  4. 49
      crates/fuzzing/tests/regressions/issue694.wat

17
crates/debug/src/transform/expression.rs

@ -119,16 +119,27 @@ fn map_reg(reg: RegUnit) -> Register {
}
fn translate_loc(loc: ValueLoc, frame_info: Option<&FunctionFrameInfo>) -> Option<Vec<u8>> {
use gimli::write::Writer;
match loc {
ValueLoc::Reg(reg) => {
let machine_reg = map_reg(reg).0 as u8;
assert_lt!(machine_reg, 32); // FIXME
Some(vec![gimli::constants::DW_OP_reg0.0 + machine_reg])
Some(if machine_reg < 32 {
vec![gimli::constants::DW_OP_reg0.0 + machine_reg]
} else {
let endian = gimli::RunTimeEndian::Little;
let mut writer = write::EndianVec::new(endian);
writer
.write_u8(gimli::constants::DW_OP_regx.0 as u8)
.expect("regx");
writer
.write_uleb128(machine_reg.into())
.expect("machine_reg");
writer.into_vec()
})
}
ValueLoc::Stack(ss) => {
if let Some(frame_info) = frame_info {
if let Some(ss_offset) = frame_info.stack_slots[ss].offset {
use gimli::write::Writer;
let endian = gimli::RunTimeEndian::Little;
let mut writer = write::EndianVec::new(endian);
writer

10
crates/fuzzing/src/oracles.rs

@ -27,6 +27,16 @@ pub fn instantiate(wasm: &[u8], strategy: Strategy) {
config
.strategy(strategy)
.expect("failed to enable lightbeam");
instantiate_with_config(wasm, config);
}
/// Instantiate the Wasm buffer, and implicitly fail if we have an unexpected
/// panic or segfault or anything else that can be detected "passively".
///
/// The engine will be configured using provided config.
///
/// See also `instantiate` functions.
pub fn instantiate_with_config(wasm: &[u8], config: Config) {
let engine = Engine::new(&config);
let store = Store::new(&engine);

10
crates/fuzzing/tests/regressions.rs

@ -5,7 +5,7 @@
//! use the Wasm binary by including it via
//! `include_bytes!("./regressions/some-descriptive-name.wasm")`.
use wasmtime::Strategy;
use wasmtime::{Config, Strategy};
use wasmtime_fuzzing::oracles;
#[test]
@ -19,3 +19,11 @@ fn instantiate_empty_module_with_memory() {
let data = wat::parse_str(include_str!("./regressions/empty_with_memory.wat")).unwrap();
oracles::instantiate(&data, Strategy::Auto);
}
#[test]
fn instantiate_module_that_compiled_to_x64_has_register_32() {
let mut config = Config::new();
config.debug_info(true);
let data = wat::parse_str(include_str!("./regressions/issue694.wat")).unwrap();
oracles::instantiate_with_config(&data, config);
}

49
crates/fuzzing/tests/regressions/issue694.wat

@ -0,0 +1,49 @@
(module
(type (;0;) (func))
(type (;1;) (func (param i64)))
(func (;0;) (type 0))
(func (;1;) (type 0))
(func (;2;) (type 0))
(func (;3;) (type 0))
(func (;4;) (type 1) (param i64)
(local f32 f32 f32)
loop (result i64) ;; label = @1
global.get 0
if ;; label = @2
local.get 1
return
end
block (result i64) ;; label = @2
loop ;; label = @3
block ;; label = @4
global.get 0
if ;; label = @5
i32.const 5
if (result f32) ;; label = @6
block (result f32) ;; label = @7
call 0
i32.const 7
if (result f32) ;; label = @8
local.get 2
else
f32.const 0x1p+0 (;=1;)
end
end
else
f32.const 0x1p+0 (;=1;)
end
local.tee 1
local.set 3
end
end
end
i32.const 8
br_if 1 (;@1;)
i64.const 4
end
end
return)
(memory (;0;) 1)
(global (;0;) i32 (i32.const 0))
)
Loading…
Cancel
Save