Skip to content

Commit

Permalink
LibJS: Don't crash when dumping a backtrace with the
Browse files Browse the repository at this point in the history
Previously, we would crash when attempting to log a backtrace if the
program counter value for the current frame was larger than the
current executable bytecode, or if a source mapping couldn't be found
for the current program counter value.
  • Loading branch information
tcl3 committed Jul 24, 2024
1 parent 40f9c9f commit 107ea97
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Userland/Libraries/LibJS/Runtime/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,15 @@ void VM::dump_backtrace() const
for (ssize_t i = m_execution_context_stack.size() - 1; i >= 0; --i) {
auto& frame = m_execution_context_stack[i];
if (frame->executable && frame->program_counter.has_value()) {
auto source_range = frame->executable->source_range_at(frame->program_counter.value()).realize();
dbgln("-> {} @ {}:{},{}", frame->function_name ? frame->function_name->utf8_string() : ""_string, source_range.filename(), source_range.start.line, source_range.start.column);
auto unrealized_source_range = frame->executable->source_range_at(frame->program_counter.value());
if (unrealized_source_range.source_code) {
auto source_range = unrealized_source_range.realize();
dbgln("-> {} @ {}:{},{}", frame->function_name ? frame->function_name->utf8_string() : ""_string, source_range.filename(), source_range.start.line, source_range.start.column);
continue;
}
}
if (frame->executable) {
dbgln("-> {} @ {}", frame->function_name ? frame->function_name->utf8_string() : ""_string, frame->executable->source_code->filename());
} else {
dbgln("-> {}", frame->function_name ? frame->function_name->utf8_string() : ""_string);
}
Expand Down

0 comments on commit 107ea97

Please sign in to comment.