Skip to content

Commit

Permalink
Fuzzer: Standardize notation for exception prefixes (WebAssembly#6369)
Browse files Browse the repository at this point in the history
We had exception: in one and exception thrown: in another. Making those
consistent allows fuzz_shell.js to print the exception after that prefix, which
makes debugging easier sometimes.

Also canonicalize tag names. Like funcref names, JS VMs print out the internal
name, which can change after opts, so canonicalize it.
  • Loading branch information
kripken committed Mar 5, 2024
1 parent 6896d05 commit d1a7d4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ def pick_initial_contents():
# and also see the --dce workaround below that also links to those issues.
V8_UNINITIALIZED_NONDEF_LOCAL = 'uninitialized non-defaultable local'

# JS exceptions are logged as exception thrown: REASON
EXCEPTION_PREFIX = 'exception thrown: '


# given a call line that includes FUZZ_EXEC_CALL_PREFIX, return the export that
# is called
Expand Down Expand Up @@ -585,7 +588,7 @@ def fix_double(x):
out = re.sub(r'f64\.const (-?[nanN:abcdefxIity\d+-.]+)', fix_double, out)

# mark traps from wasm-opt as exceptions, even though they didn't run in a vm
out = out.replace(TRAP_PREFIX, 'exception: ' + TRAP_PREFIX)
out = out.replace(TRAP_PREFIX, EXCEPTION_PREFIX + TRAP_PREFIX)

# funcref(0) has the index of the function in it, and optimizations can
# change that index, so ignore it
Expand All @@ -595,6 +598,9 @@ def fix_double(x):
# to "N".
out = re.sub(r'i31ref\((-?\d+)\)', r'\1', out)

# Tag names may change due to opts, so canonicalize them.
out = re.sub(r' tag\$\d+', ' tag', out)

lines = out.splitlines()
for i in range(len(lines)):
line = lines[i]
Expand All @@ -604,7 +610,7 @@ def fix_double(x):
# developer can see it.
print(line)
lines[i] = None
elif 'exception' in line:
elif EXCEPTION_PREFIX in line:
# exceptions may differ when optimizing, but an exception should
# occur, so ignore their types (also js engines print them out
# slightly differently)
Expand Down
4 changes: 2 additions & 2 deletions scripts/fuzz_shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var instance;
try {
instance = new WebAssembly.Instance(module, imports);
} catch (e) {
console.log('exception: failed to instantiate module');
console.log('exception thrown: failed to instantiate module');
quit();
}

Expand Down Expand Up @@ -143,7 +143,7 @@ for (var e in exports) {
console.log('[fuzz-exec] note result: ' + e + ' => ' + printed(result));
}
} catch (e) {
console.log('exception!');// + [e, e.stack]);
console.log('exception thrown: ' + e);
}
}

0 comments on commit d1a7d4b

Please sign in to comment.