Commit 2b7ab6ad authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[stack-trace] Add additional fields to StackFrameInfo

This CL adds all fields to StackFrameInfo that are necessary to
stringify a stack trace frame. This is another step towards
disentangling symbolizing and serializing:

  - Symbolization collects all the necessary strings, numbers and
    flags for a stack trace frame.
  - Serialization turns the symbolized stack trace frame into a
    string.

Drive-by: Moves the lazy initialization of StackFrameInfo into the
private getter.

Bug: v8:8742
Change-Id: Ic3e0fb6b3d0f0e260014af44380f1f30216b1b26
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1627346Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61784}
parent 4861df10
...@@ -850,10 +850,12 @@ extern class CallableTask extends Microtask { ...@@ -850,10 +850,12 @@ extern class CallableTask extends Microtask {
extern class StackFrameInfo extends Struct { extern class StackFrameInfo extends Struct {
line_number: Smi; line_number: Smi;
column_number: Smi; column_number: Smi;
promise_all_index: Smi;
script_id: Smi; script_id: Smi;
script_name: Object; script_name: Object;
script_name_or_source_url: Object; script_name_or_source_url: Object;
function_name: Object; function_name: Object;
wasm_module_name: Object;
flag: Smi; flag: Smi;
} }
......
...@@ -307,6 +307,10 @@ Handle<Object> StackFrameBase::GetEvalOrigin() { ...@@ -307,6 +307,10 @@ Handle<Object> StackFrameBase::GetEvalOrigin() {
return FormatEvalOrigin(isolate_, GetScript()).ToHandleChecked(); return FormatEvalOrigin(isolate_, GetScript()).ToHandleChecked();
} }
Handle<Object> StackFrameBase::GetWasmModuleName() {
return isolate_->factory()->undefined_value();
}
int StackFrameBase::GetScriptId() const { int StackFrameBase::GetScriptId() const {
if (!HasScript()) return kNone; if (!HasScript()) return kNone;
return GetScript()->id(); return GetScript()->id();
...@@ -734,6 +738,17 @@ Handle<Object> WasmStackFrame::GetFunctionName() { ...@@ -734,6 +738,17 @@ Handle<Object> WasmStackFrame::GetFunctionName() {
return name; return name;
} }
Handle<Object> WasmStackFrame::GetWasmModuleName() {
Handle<Object> module_name;
Handle<WasmModuleObject> module_object(wasm_instance_->module_object(),
isolate_);
if (!WasmModuleObject::GetModuleNameOrNull(isolate_, module_object)
.ToHandle(&module_name)) {
module_name = isolate_->factory()->null_value();
}
return module_name;
}
void WasmStackFrame::ToString(IncrementalStringBuilder& builder) { void WasmStackFrame::ToString(IncrementalStringBuilder& builder) {
Handle<WasmModuleObject> module_object(wasm_instance_->module_object(), Handle<WasmModuleObject> module_object(wasm_instance_->module_object(),
isolate_); isolate_);
......
...@@ -72,6 +72,7 @@ class StackFrameBase { ...@@ -72,6 +72,7 @@ class StackFrameBase {
virtual Handle<Object> GetMethodName() = 0; virtual Handle<Object> GetMethodName() = 0;
virtual Handle<Object> GetTypeName() = 0; virtual Handle<Object> GetTypeName() = 0;
virtual Handle<Object> GetEvalOrigin(); virtual Handle<Object> GetEvalOrigin();
virtual Handle<Object> GetWasmModuleName();
// Returns the script ID if one is attached, -1 otherwise. // Returns the script ID if one is attached, -1 otherwise.
int GetScriptId() const; int GetScriptId() const;
...@@ -172,6 +173,7 @@ class WasmStackFrame : public StackFrameBase { ...@@ -172,6 +173,7 @@ class WasmStackFrame : public StackFrameBase {
Handle<Object> GetScriptNameOrSourceUrl() override { return Null(); } Handle<Object> GetScriptNameOrSourceUrl() override { return Null(); }
Handle<Object> GetMethodName() override { return Null(); } Handle<Object> GetMethodName() override { return Null(); }
Handle<Object> GetTypeName() override { return Null(); } Handle<Object> GetTypeName() override { return Null(); }
Handle<Object> GetWasmModuleName() override;
int GetPosition() const override; int GetPosition() const override;
int GetLineNumber() override { return wasm_func_index_; } int GetLineNumber() override { return wasm_func_index_; }
......
...@@ -3747,6 +3747,7 @@ Handle<StackFrameInfo> Factory::NewStackFrameInfo() { ...@@ -3747,6 +3747,7 @@ Handle<StackFrameInfo> Factory::NewStackFrameInfo() {
stack_frame_info->set_line_number(0); stack_frame_info->set_line_number(0);
stack_frame_info->set_column_number(0); stack_frame_info->set_column_number(0);
stack_frame_info->set_script_id(0); stack_frame_info->set_script_id(0);
stack_frame_info->set_promise_all_index(-1);
stack_frame_info->set_script_name(*null_value()); stack_frame_info->set_script_name(*null_value());
stack_frame_info->set_script_name_or_source_url(*null_value()); stack_frame_info->set_script_name_or_source_url(*null_value());
stack_frame_info->set_function_name(*null_value()); stack_frame_info->set_function_name(*null_value());
...@@ -3795,8 +3796,13 @@ Handle<StackFrameInfo> Factory::NewStackFrameInfo( ...@@ -3795,8 +3796,13 @@ Handle<StackFrameInfo> Factory::NewStackFrameInfo(
} }
} }
info->set_function_name(*function_name); info->set_function_name(*function_name);
info->set_wasm_module_name(*it.Frame()->GetWasmModuleName());
info->set_is_eval(it.Frame()->IsEval()); info->set_is_eval(it.Frame()->IsEval());
info->set_is_constructor(it.Frame()->IsConstructor()); info->set_is_constructor(it.Frame()->IsConstructor());
info->set_is_toplevel(it.Frame()->IsToplevel());
info->set_is_async(it.Frame()->IsAsync());
info->set_is_promise_all(it.Frame()->IsPromiseAll());
info->set_promise_all_index(it.Frame()->GetPromiseIndex());
return info; return info;
} }
......
...@@ -27,15 +27,20 @@ CAST_ACCESSOR(StackFrameInfo) ...@@ -27,15 +27,20 @@ CAST_ACCESSOR(StackFrameInfo)
SMI_ACCESSORS(StackFrameInfo, line_number, kLineNumberOffset) SMI_ACCESSORS(StackFrameInfo, line_number, kLineNumberOffset)
SMI_ACCESSORS(StackFrameInfo, column_number, kColumnNumberOffset) SMI_ACCESSORS(StackFrameInfo, column_number, kColumnNumberOffset)
SMI_ACCESSORS(StackFrameInfo, script_id, kScriptIdOffset) SMI_ACCESSORS(StackFrameInfo, script_id, kScriptIdOffset)
SMI_ACCESSORS(StackFrameInfo, promise_all_index, kPromiseAllIndexOffset)
ACCESSORS(StackFrameInfo, script_name, Object, kScriptNameOffset) ACCESSORS(StackFrameInfo, script_name, Object, kScriptNameOffset)
ACCESSORS(StackFrameInfo, script_name_or_source_url, Object, ACCESSORS(StackFrameInfo, script_name_or_source_url, Object,
kScriptNameOrSourceUrlOffset) kScriptNameOrSourceUrlOffset)
ACCESSORS(StackFrameInfo, function_name, Object, kFunctionNameOffset) ACCESSORS(StackFrameInfo, function_name, Object, kFunctionNameOffset)
ACCESSORS(StackFrameInfo, wasm_module_name, Object, kWasmModuleNameOffset)
SMI_ACCESSORS(StackFrameInfo, flag, kFlagOffset) SMI_ACCESSORS(StackFrameInfo, flag, kFlagOffset)
BOOL_ACCESSORS(StackFrameInfo, flag, is_eval, kIsEvalBit) BOOL_ACCESSORS(StackFrameInfo, flag, is_eval, kIsEvalBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_constructor, kIsConstructorBit) BOOL_ACCESSORS(StackFrameInfo, flag, is_constructor, kIsConstructorBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_wasm, kIsWasmBit) BOOL_ACCESSORS(StackFrameInfo, flag, is_wasm, kIsWasmBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_user_java_script, kIsUserJavaScriptBit) BOOL_ACCESSORS(StackFrameInfo, flag, is_user_java_script, kIsUserJavaScriptBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_toplevel, kIsToplevelBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_async, kIsAsyncBit)
BOOL_ACCESSORS(StackFrameInfo, flag, is_promise_all, kIsPromiseAllBit)
OBJECT_CONSTRUCTORS_IMPL(StackTraceFrame, Struct) OBJECT_CONSTRUCTORS_IMPL(StackTraceFrame, Struct)
NEVER_READ_ONLY_SPACE_IMPL(StackTraceFrame) NEVER_READ_ONLY_SPACE_IMPL(StackTraceFrame)
......
...@@ -10,64 +10,77 @@ namespace v8 { ...@@ -10,64 +10,77 @@ namespace v8 {
namespace internal { namespace internal {
int StackTraceFrame::GetLineNumber(Handle<StackTraceFrame> frame) { int StackTraceFrame::GetLineNumber(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
int line = GetFrameInfo(frame)->line_number(); int line = GetFrameInfo(frame)->line_number();
return line != StackFrameBase::kNone ? line : Message::kNoLineNumberInfo; return line != StackFrameBase::kNone ? line : Message::kNoLineNumberInfo;
} }
int StackTraceFrame::GetColumnNumber(Handle<StackTraceFrame> frame) { int StackTraceFrame::GetColumnNumber(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
int column = GetFrameInfo(frame)->column_number(); int column = GetFrameInfo(frame)->column_number();
return column != StackFrameBase::kNone ? column : Message::kNoColumnInfo; return column != StackFrameBase::kNone ? column : Message::kNoColumnInfo;
} }
int StackTraceFrame::GetScriptId(Handle<StackTraceFrame> frame) { int StackTraceFrame::GetScriptId(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
int id = GetFrameInfo(frame)->script_id(); int id = GetFrameInfo(frame)->script_id();
return id != StackFrameBase::kNone ? id : Message::kNoScriptIdInfo; return id != StackFrameBase::kNone ? id : Message::kNoScriptIdInfo;
} }
int StackTraceFrame::GetPromiseAllIndex(Handle<StackTraceFrame> frame) {
return GetFrameInfo(frame)->promise_all_index();
}
Handle<Object> StackTraceFrame::GetFileName(Handle<StackTraceFrame> frame) { Handle<Object> StackTraceFrame::GetFileName(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
auto name = GetFrameInfo(frame)->script_name(); auto name = GetFrameInfo(frame)->script_name();
return handle(name, frame->GetIsolate()); return handle(name, frame->GetIsolate());
} }
Handle<Object> StackTraceFrame::GetScriptNameOrSourceUrl( Handle<Object> StackTraceFrame::GetScriptNameOrSourceUrl(
Handle<StackTraceFrame> frame) { Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
auto name = GetFrameInfo(frame)->script_name_or_source_url(); auto name = GetFrameInfo(frame)->script_name_or_source_url();
return handle(name, frame->GetIsolate()); return handle(name, frame->GetIsolate());
} }
Handle<Object> StackTraceFrame::GetFunctionName(Handle<StackTraceFrame> frame) { Handle<Object> StackTraceFrame::GetFunctionName(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
auto name = GetFrameInfo(frame)->function_name(); auto name = GetFrameInfo(frame)->function_name();
return handle(name, frame->GetIsolate()); return handle(name, frame->GetIsolate());
} }
Handle<Object> StackTraceFrame::GetWasmModuleName(
Handle<StackTraceFrame> frame) {
auto module = GetFrameInfo(frame)->wasm_module_name();
return handle(module, frame->GetIsolate());
}
bool StackTraceFrame::IsEval(Handle<StackTraceFrame> frame) { bool StackTraceFrame::IsEval(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
return GetFrameInfo(frame)->is_eval(); return GetFrameInfo(frame)->is_eval();
} }
bool StackTraceFrame::IsConstructor(Handle<StackTraceFrame> frame) { bool StackTraceFrame::IsConstructor(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
return GetFrameInfo(frame)->is_constructor(); return GetFrameInfo(frame)->is_constructor();
} }
bool StackTraceFrame::IsWasm(Handle<StackTraceFrame> frame) { bool StackTraceFrame::IsWasm(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
return GetFrameInfo(frame)->is_wasm(); return GetFrameInfo(frame)->is_wasm();
} }
bool StackTraceFrame::IsUserJavaScript(Handle<StackTraceFrame> frame) { bool StackTraceFrame::IsUserJavaScript(Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
return GetFrameInfo(frame)->is_user_java_script(); return GetFrameInfo(frame)->is_user_java_script();
} }
bool StackTraceFrame::IsToplevel(Handle<StackTraceFrame> frame) {
return GetFrameInfo(frame)->is_toplevel();
}
bool StackTraceFrame::IsAsync(Handle<StackTraceFrame> frame) {
return GetFrameInfo(frame)->is_async();
}
bool StackTraceFrame::IsPromiseAll(Handle<StackTraceFrame> frame) {
return GetFrameInfo(frame)->is_promise_all();
}
Handle<StackFrameInfo> StackTraceFrame::GetFrameInfo( Handle<StackFrameInfo> StackTraceFrame::GetFrameInfo(
Handle<StackTraceFrame> frame) { Handle<StackTraceFrame> frame) {
if (frame->frame_info().IsUndefined()) InitializeFrameInfo(frame);
return handle(StackFrameInfo::cast(frame->frame_info()), frame->GetIsolate()); return handle(StackFrameInfo::cast(frame->frame_info()), frame->GetIsolate());
} }
......
...@@ -21,13 +21,18 @@ class StackFrameInfo : public Struct { ...@@ -21,13 +21,18 @@ class StackFrameInfo : public Struct {
DECL_INT_ACCESSORS(line_number) DECL_INT_ACCESSORS(line_number)
DECL_INT_ACCESSORS(column_number) DECL_INT_ACCESSORS(column_number)
DECL_INT_ACCESSORS(script_id) DECL_INT_ACCESSORS(script_id)
DECL_INT_ACCESSORS(promise_all_index)
DECL_ACCESSORS(script_name, Object) DECL_ACCESSORS(script_name, Object)
DECL_ACCESSORS(script_name_or_source_url, Object) DECL_ACCESSORS(script_name_or_source_url, Object)
DECL_ACCESSORS(function_name, Object) DECL_ACCESSORS(function_name, Object)
DECL_ACCESSORS(wasm_module_name, Object)
DECL_BOOLEAN_ACCESSORS(is_eval) DECL_BOOLEAN_ACCESSORS(is_eval)
DECL_BOOLEAN_ACCESSORS(is_constructor) DECL_BOOLEAN_ACCESSORS(is_constructor)
DECL_BOOLEAN_ACCESSORS(is_wasm) DECL_BOOLEAN_ACCESSORS(is_wasm)
DECL_BOOLEAN_ACCESSORS(is_user_java_script) DECL_BOOLEAN_ACCESSORS(is_user_java_script)
DECL_BOOLEAN_ACCESSORS(is_toplevel)
DECL_BOOLEAN_ACCESSORS(is_async)
DECL_BOOLEAN_ACCESSORS(is_promise_all)
DECL_INT_ACCESSORS(flag) DECL_INT_ACCESSORS(flag)
DECL_CAST(StackFrameInfo) DECL_CAST(StackFrameInfo)
...@@ -45,6 +50,9 @@ class StackFrameInfo : public Struct { ...@@ -45,6 +50,9 @@ class StackFrameInfo : public Struct {
static const int kIsConstructorBit = 1; static const int kIsConstructorBit = 1;
static const int kIsWasmBit = 2; static const int kIsWasmBit = 2;
static const int kIsUserJavaScriptBit = 3; static const int kIsUserJavaScriptBit = 3;
static const int kIsToplevelBit = 4;
static const int kIsAsyncBit = 5;
static const int kIsPromiseAllBit = 6;
OBJECT_CONSTRUCTORS(StackFrameInfo, Struct); OBJECT_CONSTRUCTORS(StackFrameInfo, Struct);
}; };
...@@ -74,15 +82,20 @@ class StackTraceFrame : public Struct { ...@@ -74,15 +82,20 @@ class StackTraceFrame : public Struct {
static int GetLineNumber(Handle<StackTraceFrame> frame); static int GetLineNumber(Handle<StackTraceFrame> frame);
static int GetColumnNumber(Handle<StackTraceFrame> frame); static int GetColumnNumber(Handle<StackTraceFrame> frame);
static int GetScriptId(Handle<StackTraceFrame> frame); static int GetScriptId(Handle<StackTraceFrame> frame);
static int GetPromiseAllIndex(Handle<StackTraceFrame> frame);
static Handle<Object> GetFileName(Handle<StackTraceFrame> frame); static Handle<Object> GetFileName(Handle<StackTraceFrame> frame);
static Handle<Object> GetScriptNameOrSourceUrl(Handle<StackTraceFrame> frame); static Handle<Object> GetScriptNameOrSourceUrl(Handle<StackTraceFrame> frame);
static Handle<Object> GetFunctionName(Handle<StackTraceFrame> frame); static Handle<Object> GetFunctionName(Handle<StackTraceFrame> frame);
static Handle<Object> GetWasmModuleName(Handle<StackTraceFrame> frame);
static bool IsEval(Handle<StackTraceFrame> frame); static bool IsEval(Handle<StackTraceFrame> frame);
static bool IsConstructor(Handle<StackTraceFrame> frame); static bool IsConstructor(Handle<StackTraceFrame> frame);
static bool IsWasm(Handle<StackTraceFrame> frame); static bool IsWasm(Handle<StackTraceFrame> frame);
static bool IsUserJavaScript(Handle<StackTraceFrame> frame); static bool IsUserJavaScript(Handle<StackTraceFrame> frame);
static bool IsToplevel(Handle<StackTraceFrame> frame);
static bool IsAsync(Handle<StackTraceFrame> frame);
static bool IsPromiseAll(Handle<StackTraceFrame> frame);
private: private:
OBJECT_CONSTRUCTORS(StackTraceFrame, Struct); OBJECT_CONSTRUCTORS(StackTraceFrame, Struct);
......
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