1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

LibWasm: Give traps a reason and display it when needed

This makes debugging wasm code a bit easier, as we now know what fails
instead of just "too bad, something went wrong".
This commit is contained in:
Ali Mohammad Pur 2021-07-01 17:03:17 +04:30 committed by Ali Mohammad Pur
parent 62ca81fdcc
commit b538e15548
10 changed files with 54 additions and 50 deletions

View file

@ -35,10 +35,10 @@ static bool post_interpret_hook(Wasm::Configuration&, Wasm::InstructionPointer&
{
if (interpreter.did_trap()) {
g_continue = false;
const_cast<Wasm::Interpreter&>(interpreter).clear_trap();
warnln("Trapped when executing ip={}", ip);
g_printer.print(instr);
warnln("");
warnln("Trap reason: {}", interpreter.trap_reason());
const_cast<Wasm::Interpreter&>(interpreter).clear_trap();
}
return true;
}
@ -206,7 +206,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
result = config.call(g_interpreter, *address, move(values));
}
if (result.is_trap())
warnln("Execution trapped!");
warnln("Execution trapped: {}", result.trap().reason);
if (!result.values().is_empty())
warnln("Returned:");
for (auto& value : result.values()) {