Skip to content

Toolkit for dealing with wasm (webassembly), including an strace like tool.

License

Notifications You must be signed in to change notification settings

loopholelabs/wasm-toolkit

Repository files navigation

WASM Toolkit

A Toolkit for working with WebAssembly

License: Apache 2.0 Discord Go Version Go Reference

Features

  • Encoding and decoding from .wasm binary (99% done)

  • Encoding and decoding from .wat text (99% done)

  • Adding strace like output to a wasm file, which gets output to STDERR as it runs.

    • All function calls, with arguments and return
    • All calls to imported functions, with args and return
    • Dwarf source file and line number ranges
    • Dwarf paramater names
    • Wasi preview1 call and return values
    • Function call count and timings summary
    • Watch globals by name (i32 only so far)
  • wasm2wat but including dwarf debug information - line numbers, variable names, etc

  • POC Embedding a file into a wasm which is then available to the module.

Quickstart

  • wasm2wat - ./wasm-toolkit wasm2wat -i something.wasm -o something.wat
  • wat2wasm - ./wasm-toolkit wat2wasm -i something.wat -o something.wasm
  • strace - ./wasm-toolkit strace -i something.wasm -o something-with-strace-stderr.wasm
  • embedfile - ./wasm-toolkit embedfile -i something.wasm -o something_embed.wasm --filename embedtest --content "This is some file data :)"

Strace

Simple example

./wasm-toolkit strace -i ../module1.wasm -o module1_strace.wasm --all --color --func '^\$IMPORT.*|\_start'

alt text

Filter functions

./wasm-toolkit strace -i ../module1.wasm -o module1_strace.wasm --all --color --func '^\$main'

alt text

Profiling

./wasm-toolkit strace -i ../module1.wasm -o module1_strace.wasm --all --color --func '.*' --timing true

alt text

Watch global variables

./wasm-toolkit strace -i ../module1.wasm -o module1_strace.wasm --all --color --func '^\$main' --watch main.some_global,main.another_global

alt text

alt text

You can also compile wasm-toolkit to wasm and add tracing to it :)

Embed file (POC)

alt text

Example output

On the left is an strace like output. On the right is a wat output with debugging info.

alt text

TODO

  • Dwarf watched globals - automatically determine type/length from dwarf data, support many types.
  • Hook unreachable calls and add far more context to aid debugging. eg show all watched variables.
  • Output to open telemetry standard.
  • More dwarf data - check up on the rust generated data.
  • Implement remainder of wasm instructions, fix bugs in wat parsing (comments etc).
  • More work on linking / composability.
  • Finish wasi file embed.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/loopholelabs/wasm-toolkit. For more contribution information check out the contribution guide.

License

The WASM Toolkit project is available as open source under the terms of the Apache License, Version 2.0.

Code of Conduct

Everyone interacting in the WASM Toolkit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the CNCF Code of Conduct.

Project Managed By:

https://loopholelabs.io