summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-07-01 17:03:17 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-02 04:53:01 +0430
commitb538e15548cf3760c71e4b60cf3820c902748c8f (patch)
tree5daed8e96d8ed5043c3528baef31559c7d07f9a6 /Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h
parent62ca81fdcc7ab999739e3ddb6c26e196e9357962 (diff)
downloadserenity-b538e15548cf3760c71e4b60cf3820c902748c8f.zip
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".
Diffstat (limited to 'Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h')
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h
index d494511cfe..7a917ab6fc 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h
+++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h
@@ -14,8 +14,9 @@ namespace Wasm {
struct BytecodeInterpreter : public Interpreter {
virtual void interpret(Configuration&) override;
virtual ~BytecodeInterpreter() override = default;
- virtual bool did_trap() const override { return m_do_trap; }
- virtual void clear_trap() override { m_do_trap = false; }
+ virtual bool did_trap() const override { return m_trap.has_value(); }
+ virtual String trap_reason() const override { return m_trap.value().reason; }
+ virtual void clear_trap() override { m_trap.clear(); }
struct CallFrameHandle {
explicit CallFrameHandle(BytecodeInterpreter& interpreter, Configuration& configuration)
@@ -48,13 +49,14 @@ protected:
T read_value(ReadonlyBytes data);
Vector<Value> pop_values(Configuration& configuration, size_t count);
- bool trap_if_not(bool value)
+ bool trap_if_not(bool value, String reason)
{
if (!value)
- m_do_trap = true;
- return m_do_trap;
+ m_trap = Trap { move(reason) };
+ return m_trap.has_value();
}
- bool m_do_trap { false };
+
+ Optional<Trap> m_trap;
};
struct DebuggerBytecodeInterpreter : public BytecodeInterpreter {