Commit 9f7c644b authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[stack trace] Create StackFrameInfo from FrameArray

This CL adds a method to the factory which converts a stack trace
frame represented by a FrameArray plus index, into a StackFrameInfo
object. This factory method will later be used to lazily populate
stack trace frames when they are retrieved via inspector API.

Drive-by: Expose the script id in StackFrameBase.

R=jgruber@chromium.org

Bug: v8:8742
Change-Id: I79965e466370706593903f3d1a336ac29736f8ac
Reviewed-on: https://chromium-review.googlesource.com/c/1454928
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59405}
parent 6c3c952d
......@@ -3884,6 +3884,51 @@ Handle<StackFrameInfo> Factory::NewStackFrameInfo() {
return stack_frame_info;
}
Handle<StackFrameInfo> Factory::NewStackFrameInfo(
Handle<FrameArray> frame_array, int index) {
FrameArrayIterator it(isolate(), frame_array, index);
DCHECK(it.HasFrame());
Handle<StackFrameInfo> info = Handle<StackFrameInfo>::cast(
NewStruct(STACK_FRAME_INFO_TYPE, NOT_TENURED));
info->set_flag(0);
const bool is_wasm = frame_array->IsAnyWasmFrame(index);
info->set_is_wasm(is_wasm);
// Line numbers are 1-based, for Wasm we need to adjust.
int line = it.Frame()->GetLineNumber();
if (is_wasm && line >= 0) line++;
info->set_line_number(line);
// Column numbers are 1-based. For Wasm we use the position
// as the iterator does not currently provide a column number.
const int column =
is_wasm ? it.Frame()->GetPosition() + 1 : it.Frame()->GetColumnNumber();
info->set_column_number(column);
info->set_script_id(it.Frame()->GetScriptId());
info->set_script_name(*it.Frame()->GetFileName());
info->set_script_name_or_source_url(*it.Frame()->GetScriptNameOrSourceUrl());
// TODO(szuend): Adjust this, once it is decided what name to use in both
// "simple" and "detailed" stack traces. This code is for
// backwards compatibility to fullfill test expectations.
auto function_name = it.Frame()->GetFunctionName();
if (!is_wasm) {
Handle<Object> function = it.Frame()->GetFunction();
if (function->IsJSFunction()) {
function_name =
JSFunction::GetDebugName(Handle<JSFunction>::cast(function));
}
}
info->set_function_name(*function_name);
info->set_is_eval(it.Frame()->IsEval());
info->set_is_constructor(it.Frame()->IsConstructor());
return info;
}
Handle<SourcePositionTableWithFrameCache>
Factory::NewSourcePositionTableWithFrameCache(
Handle<ByteArray> source_position_table,
......
......@@ -440,6 +440,8 @@ class V8_EXPORT_PRIVATE Factory {
Handle<BreakPointInfo> NewBreakPointInfo(int source_position);
Handle<BreakPoint> NewBreakPoint(int id, Handle<String> condition);
Handle<StackFrameInfo> NewStackFrameInfo();
Handle<StackFrameInfo> NewStackFrameInfo(Handle<FrameArray> frame_array,
int index);
Handle<SourcePositionTableWithFrameCache>
NewSourcePositionTableWithFrameCache(
Handle<ByteArray> source_position_table,
......
......@@ -294,6 +294,11 @@ Handle<Object> StackFrameBase::GetEvalOrigin() {
return FormatEvalOrigin(isolate_, GetScript()).ToHandleChecked();
}
int StackFrameBase::GetScriptId() const {
if (!HasScript()) return -1;
return GetScript()->id();
}
bool StackFrameBase::IsEval() {
return HasScript() &&
GetScript()->compilation_type() == Script::COMPILATION_TYPE_EVAL;
......
......@@ -63,6 +63,9 @@ class StackFrameBase {
virtual Handle<Object> GetTypeName() = 0;
virtual Handle<Object> GetEvalOrigin();
// Returns the script ID if one is attached, -1 otherwise.
int GetScriptId() const;
virtual int GetPosition() const = 0;
// Return 1-based line number, including line offset.
virtual int GetLineNumber() = 0;
......
......@@ -47,6 +47,11 @@ bool FrameArray::IsAsmJsWasmFrame(int frame_ix) const {
return (flags & kIsAsmJsWasmFrame) != 0;
}
bool FrameArray::IsAnyWasmFrame(int frame_ix) const {
return IsWasmFrame(frame_ix) || IsWasmInterpretedFrame(frame_ix) ||
IsAsmJsWasmFrame(frame_ix);
}
int FrameArray::FrameCount() const {
const int frame_count = Smi::ToInt(get(kFrameCountIndex));
DCHECK_LE(0, frame_count);
......
......@@ -39,6 +39,7 @@ class FrameArray : public FixedArray {
inline bool IsWasmFrame(int frame_ix) const;
inline bool IsWasmInterpretedFrame(int frame_ix) const;
inline bool IsAsmJsWasmFrame(int frame_ix) const;
inline bool IsAnyWasmFrame(int frame_ix) const;
inline int FrameCount() const;
void ShrinkToFit(Isolate* isolate);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment