diff options
author | Alon Zakai <azakai@google.com> | 2022-12-15 14:02:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 22:02:53 +0000 |
commit | a9ebf0dd842dc5b239a233177cfc9ccbd675fba7 (patch) | |
tree | aadf98032ac8c13bc1d466492072961907bb3ab9 /test/lit/binary/debug-bad-binary.test | |
parent | bead42c46d48e4c5584f035f7a805911dc59ae35 (diff) | |
download | binaryen-a9ebf0dd842dc5b239a233177cfc9ccbd675fba7.tar.gz binaryen-a9ebf0dd842dc5b239a233177cfc9ccbd675fba7.tar.bz2 binaryen-a9ebf0dd842dc5b239a233177cfc9ccbd675fba7.zip |
In --debug mode, print partial wasm data that was read (#5356)
If wasm-opt or wasm-dis are given an invalid binary, after the error
message we can also print out the wasm we did manage to read. That
includes global stuff like imports and also all the functions up until
there. This can help debugging in some situations.
Only do this when --debug is passed as it can be very verbose and
in general users might not want it.
This is technically easy to do, it turns out, since we already use a
thrown exception on an error in parsing, and we fill up the wasm as
we go, so it just contains what we've read so far, and we can just
print it.
Fixes #5344
Also switch an existing test's comments to ;; from # which was
noticed here.
Diffstat (limited to 'test/lit/binary/debug-bad-binary.test')
-rw-r--r-- | test/lit/binary/debug-bad-binary.test | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/lit/binary/debug-bad-binary.test b/test/lit/binary/debug-bad-binary.test new file mode 100644 index 000000000..f45b7d494 --- /dev/null +++ b/test/lit/binary/debug-bad-binary.test @@ -0,0 +1,42 @@ +;; Verify --debug mode prints partial results even after an error. +;; +;; debug-bad-binary.test.wasm contains: +;; +;; (module +;; (global $A (mut i32) (i32.const 10)) +;; +;; (func $a +;; (drop +;; (i32.const 10) +;; ) +;; ) +;; +;; (func $b +;; ;; bad opcodes here! +;; ) +;; +;; (func $c +;; (drop +;; (i32.const 30) +;; ) +;; ) +;; ) +;; +;; We will error when we get to the bad opcodes. In --debug mode, this test +;; shows that we at least print what we read so far up to that point, which will +;; include both the global and the first function. +;; + +RUN: not wasm-opt --debug %s.wasm 2>&1 | filecheck %s + +;; CHECK: Fatal: error parsing wasm. here is what we read up to the error: +;; CHECK-NEXT: (module +;; CHECK-NEXT: (type $none_=>_none (func)) +;; CHECK-NEXT: (global $global$0 (mut i32) (i32.const 10)) +;; CHECK-NEXT: (func $0 +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (i32.const 10) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) + |