瀏覽代碼

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.
Andreas Kling 4 年之前
父節點
當前提交
d24f4462c7
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 6 0
      Userland/Libraries/LibJS/Runtime/VM.cpp
  2. 2 0
      Userland/Libraries/LibJS/Runtime/VM.h

+ 6 - 0
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);
+}
+
 }

+ 2 - 0
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&);