ejrgilbert / whamm

5 stars 2 forks source link

Stale Instrumentation offset #81

Open ahuoguo opened 2 days ago

ahuoguo commented 2 days ago
(module
  (type (;0;) (func))
  (type (;1;) (func (param i32 i32) (result i32)))
  (func (;0;) (type 0))
  (func (;1;) (type 0)
    call 0
    ;; call 0
    call 0)
  (memory (;0;) 1))

instrumented with:

i32 i;
wasm:bytecode:call:before {
    i = 10;
}

gives me

 (func (;1;) (type 0)
    i32.const 10
    i32.const 10
    global.set 0
    global.set 0
    call 2
    call 2)

Shouldn't this better be

 (func (;1;) (type 0)
    i32.const 10
    global.set 0
    call 2
    i32.const 10
    global.set 0
    call 2)

In fact, currently:

(module
  (type (;0;) (func))
  (type (;1;) (func (param i32 i32) (result i32)))
  (func $add (;0;) (type 1) (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.add)
  (func (;1;) (type 0)
    i32.const 1
    i32.const 2
    call 0
    i32.const 1
    i32.const 2
    call 0
    i32.const 1
    i32.const 2
    call 0
    drop
    drop
    drop)
  (memory (;0;) 1))

instrument with the same script will give me instrumented code with type error

  (func (;1;) (type 0)
    (local i32 i32 i32 i32 i32 i32)
    i32.const 1
    i32.const 2
    local.set 0
    local.set 1
    local.get 0
    local.set 2
    local.set 3
    local.get 2
    local.set 4
    local.set 5
    local.get 4
    local.get 5
    i32.const 10
    global.set 0
    local.get 3
    i32.const 10
    global.set 0
    local.get 1
    i32.const 10
    global.set 0
    call 2
    i32.const 1
    i32.const 2
    call 2
    i32.const 1
    i32.const 2
    call 2
    drop
    drop
    drop)

As local.get 1 local.get 3 are misplaced.

This seems to be the issue of the probe location staying the same and it never dynamically updates after instrumentation.