Skip to content

Commit a1f1d9e

Browse files
Hendiadyoin1awesomekling
authored andcommitted
LibJS: Expose some information about the bytecode interpreters state
This is quite helpful, when reporting internal errors.
1 parent 937fcfc commit a1f1d9e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
6161
pushed_execution_context = true;
6262
}
6363

64-
auto block = entry_point ?: &executable.basic_blocks.first();
64+
m_current_block = entry_point ?: &executable.basic_blocks.first();
6565
if (in_frame)
6666
m_register_windows.append(in_frame);
6767
else
@@ -70,7 +70,9 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
7070
registers().resize(executable.number_of_registers);
7171

7272
for (;;) {
73-
Bytecode::InstructionStreamIterator pc(block->instruction_stream());
73+
Bytecode::InstructionStreamIterator pc(m_current_block->instruction_stream());
74+
TemporaryChange temp_change { m_pc, &pc };
75+
7476
bool will_jump = false;
7577
bool will_return = false;
7678
while (!pc.at_end()) {
@@ -85,7 +87,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
8587
if (unwind_context.executable != m_current_executable)
8688
break;
8789
if (unwind_context.handler) {
88-
block = unwind_context.handler;
90+
m_current_block = unwind_context.handler;
8991
unwind_context.handler = nullptr;
9092

9193
// If there's no finalizer, there's nowhere for the handler block to unwind to, so the unwind context is no longer needed.
@@ -98,7 +100,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
98100
break;
99101
}
100102
if (unwind_context.finalizer) {
101-
block = unwind_context.finalizer;
103+
m_current_block = unwind_context.finalizer;
102104
m_unwind_contexts.take_last();
103105
will_jump = true;
104106
break;
@@ -108,7 +110,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
108110
VERIFY_NOT_REACHED();
109111
}
110112
if (m_pending_jump.has_value()) {
111-
block = m_pending_jump.release_value();
113+
m_current_block = m_pending_jump.release_value();
112114
will_jump = true;
113115
break;
114116
}

Userland/Libraries/LibJS/Bytecode/Interpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class Interpreter {
6464
ThrowCompletionOr<void> continue_pending_unwind(Label const& resume_label);
6565

6666
Executable const& current_executable() { return *m_current_executable; }
67+
BasicBlock const& current_block() const { return *m_current_block; }
68+
size_t pc() const { return m_pc ? m_pc->offset() : 0; }
6769

6870
enum class OptimizationLevel {
6971
None,
@@ -99,6 +101,8 @@ class Interpreter {
99101
Vector<UnwindInfo> m_unwind_contexts;
100102
Handle<Value> m_saved_exception;
101103
OwnPtr<JS::Interpreter> m_ast_interpreter;
104+
BasicBlock const* m_current_block { nullptr };
105+
InstructionStreamIterator* m_pc { nullptr };
102106
};
103107

104108
extern bool g_dump_bytecode;

0 commit comments

Comments
 (0)