From d24f4462c7fb70ea33adda9f7eb4751924c1c2e6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 6 Jun 2021 22:53:44 +0200 Subject: [PATCH] LibJS: Add VM::dump_backtrace() This is just a simple helper that dumps the current VM call stack to the debug console. I find myself rewriting this function over and over, so let's just have it in the tree. --- Userland/Libraries/LibJS/Runtime/VM.cpp | 6 ++++++ Userland/Libraries/LibJS/Runtime/VM.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 53014ffe9f..4069263041 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -544,4 +544,10 @@ void VM::promise_rejection_tracker(const Promise& promise, Promise::RejectionOpe } } +void VM::dump_backtrace() const +{ + for (ssize_t i = m_call_stack.size() - 1; i >= 0; --i) + dbgln("-> {}", m_call_stack[i]->function_name); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 74c2bd96d5..90a2d701ce 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -71,6 +71,8 @@ public: void set_exception(Exception& exception) { m_exception = &exception; } void clear_exception() { m_exception = nullptr; } + void dump_backtrace() const; + class InterpreterExecutionScope { public: InterpreterExecutionScope(Interpreter&);