GithubHelp home page GithubHelp logo

wasm3 / wasm-debug Goto Github PK

View Code? Open in Web Editor NEW
38.0 8.0 3.0 58 KB

Direct, source-level WebAssembly debugger

License: MIT License

Python 90.63% C 1.54% Rust 7.83%
webassembly gdb lldb debugger remote-debugger

wasm-debug's Introduction

wasm-debug

Direct, source-level WebAssembly debugger

We're exploring the possibility of direct, source-level debugging of WebAssembly binaries.
rustc/clang compilers can generate DWARF debug info, and embed it into the wasm binaries,
however debuggers like gdb/lldb currently do not know how to work with such files directly.

Status:

  • Created wasm2dbg.py utility to repackage the DWARF info from wasm to elf format.
    The resulting file can be loaded by unmodified versions of debuggers.
  • Created gdb-stub.py, which uses GDB Remote Serial Protocol to communicate to gdb and lldb.
    This is a prototype of a VM that successfully emulates a breakpoint hit.

Next:

  • Implement Wasm3-based opcode-level debugger
  • Connect Wasm3 to gdb/lldb via Remote Serial Protocol

NOTE: This is work-in-progress, and highly experimental!

This work should actually be a good starting point to start adding direct wasm support to debuggers.
Looks like LLDB already started some movement in this direction (see here and here).
Also, DWARF format has to be extended to allow representing wasm local, global or operand stack variables.

Building test apps

See Rust and C example apps.

Extracting DWARF debug info

./wasm2dbg.py ./test_app_c/app.wasm

# Strip debug info from the wasm file (optional):
wasm-strip ./test_app_c/app.wasm

Debugging

# Using GDB:
./prototype/gdbstub.py &
cd test_app_c
gdb -q -x ../.gdbscript app.wasm.dbg

# Or LLDB:
./prototype/gdbstub.py &
cd test_app_c
lldb -s ../.lldbscript app.wasm.dbg

Examining the GDB RSP protocol

To debug the RSP packets, it's convenient to use tcpdump + tcpflow:

sudo tcpdump -i lo -l -w - port 4444 | tcpflow -C -g -r -

Also, debuggers provide built-in logs for this:

GDB:

(gdb) set debug remote 1

GDB, log to a separate file:

(gdb) set remotelogfile gdb-rsp.log

LLDB:

(lldb) log enable gdb-remote packets

Examining the produced wasm binaries

After building the app, it may be interesting to inspect WASM contents.
There are multiple tools for that, here are some examples:

llvm-objdump-10 -h app.wasm
llvm-dwarfdump-10 app.wasm --all -o app.dwarfdump
wasm-objdump -hxd app.wasm > app.objdump
wasm-dis -sm app.wasm.map app.wasm -o app.dis
wasm-decompile app.wasm -o app.decompile

License

This project is released under The MIT License (MIT)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.