bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.08k stars 1.26k forks source link

Display expected/actual type signature in "indirect call type mismatch" error? #3705

Open TerrorJack opened 2 years ago

TerrorJack commented 2 years ago

Feature

Currently, when a call_indirect opcode is executed with mismatching types, wasmtime would display something like:

Error: failed to run main module `closure.wasm`

Caused by:
    0: failed to invoke command default
    1: wasm trap: indirect call type mismatch
       wasm backtrace:
           0: 0x40515a - <unknown>!__main_void
           1: 0x4051af - <unknown>!__original_main
           2: 0x405197 - <unknown>!_start
           3: 0x4078c8 - <unknown>!_start.command_export

It would be nice to have enriched error message that displays the expected/actual type signatures here, this will help debugging a lot.

bjorn3 commented 2 years ago

This would be nice to have IMHO. It doesn't seem like there is an obvious way to pass the id of the actual and expected signature back to the wasmtime runtime. The trap is raised using a hardware trap instruction like ud2. This doesn't allow any arguments. Using a call instead would be possible though I suspect it will cause a perf regression, but I will leave it to others to judge as I am not familiar with this part of the code.

https://github.com/bytecodealliance/wasmtime/blob/1532516a363eed88b5a36726a1710411a9883049/crates/cranelift/src/func_environ.rs#L1378