ejrgilbert / whamm

5 stars 2 forks source link

Enable `local` state for probe rules #52

Open ejrgilbert opened 2 weeks ago

ejrgilbert commented 2 weeks ago

Consider the following probe rule:

map<(loc, i32), i32> count;
wasm:bytecode:br:before {
    i32 index = tos != 0 ? 1 : 0;
    count[(loc, i32)]++;
}

This could be simplified if we enabled the use of local state for probes that will give an instance of some object at each probed bytecode, e.g.:

wasm:bytecode:br:before {
    local map<i32, i32> count;
    i32 index = tos != 0 ? 1 : 0;
    count[(loc, i32)]++;
}

This will also simplify "dumping" collected instrumentation data at the end of program execution since this global cache of local state can be dumped, with the contents containing references to both the bytecode locations and the rules that were injected at that point, e.g.:

map {
    // at Wasm bytecode location "0"
    0 -> map {
        // Rule with ID 0 matched location "0", here is its `local` state
        0 -> map {
            "count" -> GID
        }
    }
    // at Wasm bytecode location "8"
    8 -> map {
        // Rule with ID 0 matched location "8", here is its `local` state
        0 -> map {
            "count" -> GID
        }
    }
}