Commit 907a03d3 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by V8 LUCI CQ

[refactor] Be explicit wrt. simple vs. detailed stack trace.

This is a non-functional refactoring to make naming of stack traces more
consistent, and thus easier to reason about whether the "simple stack
trace" (stack trace API) or the "detailed stack trace" (inspector API)
is meant. Granted, these names aren't great by themselves, but at least
we should be consistent.

This also adds a new `Isolate::GetSimpleStackTrace()` and uses that
directly to implement the Wasm C-API, avoiding the roundtrip via the
`JSMessageObject`, which actually carries a detailed stack trace (which
by chance worked out so far).

Doc: https://bit.ly/v8-stack-frame
Bug: chromium:1258599, chromium:1278647, chromium:1278650
Change-Id: I29e1a956ed156d6eeceb50150a28afaa2f11b9c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3334780
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78366}
parent a0108291
...@@ -3244,7 +3244,7 @@ Local<StackTrace> StackTrace::CurrentStackTrace(Isolate* isolate, ...@@ -3244,7 +3244,7 @@ Local<StackTrace> StackTrace::CurrentStackTrace(Isolate* isolate,
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::FixedArray> stackTrace = i::Handle<i::FixedArray> stackTrace =
i_isolate->CaptureCurrentStackTrace(frame_limit, options); i_isolate->CaptureDetailedStackTrace(frame_limit, options);
return Utils::StackTraceToLocal(stackTrace); return Utils::StackTraceToLocal(stackTrace);
} }
......
...@@ -782,7 +782,6 @@ class BuiltinExitFrame : public ExitFrame { ...@@ -782,7 +782,6 @@ class BuiltinExitFrame : public ExitFrame {
inline Object new_target_slot_object() const; inline Object new_target_slot_object() const;
friend class StackFrameIteratorBase; friend class StackFrameIteratorBase;
friend class StackTraceBuilder;
}; };
class StubFrame : public TypedFrame { class StubFrame : public TypedFrame {
......
...@@ -1200,7 +1200,7 @@ MaybeHandle<JSReceiver> Isolate::CaptureAndSetDetailedStackTrace( ...@@ -1200,7 +1200,7 @@ MaybeHandle<JSReceiver> Isolate::CaptureAndSetDetailedStackTrace(
if (capture_stack_trace_for_uncaught_exceptions_) { if (capture_stack_trace_for_uncaught_exceptions_) {
// Capture stack trace for a detailed exception message. // Capture stack trace for a detailed exception message.
Handle<Name> key = factory()->detailed_stack_trace_symbol(); Handle<Name> key = factory()->detailed_stack_trace_symbol();
Handle<FixedArray> stack_trace = CaptureCurrentStackTrace( Handle<FixedArray> stack_trace = CaptureDetailedStackTrace(
stack_trace_for_uncaught_exceptions_frame_limit_, stack_trace_for_uncaught_exceptions_frame_limit_,
stack_trace_for_uncaught_exceptions_options_); stack_trace_for_uncaught_exceptions_options_);
RETURN_ON_EXCEPTION( RETURN_ON_EXCEPTION(
...@@ -1229,14 +1229,21 @@ MaybeHandle<JSReceiver> Isolate::CaptureAndSetSimpleStackTrace( ...@@ -1229,14 +1229,21 @@ MaybeHandle<JSReceiver> Isolate::CaptureAndSetSimpleStackTrace(
} }
Handle<FixedArray> Isolate::GetDetailedStackTrace( Handle<FixedArray> Isolate::GetDetailedStackTrace(
Handle<JSObject> error_object) { Handle<JSReceiver> error_object) {
Handle<Name> key_detailed = factory()->detailed_stack_trace_symbol(); Handle<Name> key = factory()->detailed_stack_trace_symbol();
Handle<Object> stack_trace = Handle<Object> result = JSReceiver::GetDataProperty(error_object, key);
JSReceiver::GetDataProperty(error_object, key_detailed); if (result->IsFixedArray()) return Handle<FixedArray>::cast(result);
if (stack_trace->IsFixedArray()) return Handle<FixedArray>::cast(stack_trace);
return Handle<FixedArray>(); return Handle<FixedArray>();
} }
Handle<FixedArray> Isolate::GetSimpleStackTrace(
Handle<JSReceiver> error_object) {
Handle<Name> key = factory()->stack_trace_symbol();
Handle<Object> result = JSReceiver::GetDataProperty(error_object, key);
if (result->IsFixedArray()) return Handle<FixedArray>::cast(result);
return factory()->empty_fixed_array();
}
Address Isolate::GetAbstractPC(int* line, int* column) { Address Isolate::GetAbstractPC(int* line, int* column) {
JavaScriptFrameIterator it(this); JavaScriptFrameIterator it(this);
...@@ -1274,10 +1281,10 @@ Address Isolate::GetAbstractPC(int* line, int* column) { ...@@ -1274,10 +1281,10 @@ Address Isolate::GetAbstractPC(int* line, int* column) {
return frame->pc(); return frame->pc();
} }
Handle<FixedArray> Isolate::CaptureCurrentStackTrace( Handle<FixedArray> Isolate::CaptureDetailedStackTrace(
int frame_limit, StackTrace::StackTraceOptions stack_trace_options) { int limit, StackTrace::StackTraceOptions stack_trace_options) {
CaptureStackTraceOptions options; CaptureStackTraceOptions options;
options.limit = std::max(frame_limit, 0); // Ensure no negative values. options.limit = std::max(limit, 0); // Ensure no negative values.
options.skip_mode = SKIP_NONE; options.skip_mode = SKIP_NONE;
options.async_stack_trace = false; options.async_stack_trace = false;
options.filter_mode = options.filter_mode =
...@@ -2297,7 +2304,7 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception, ...@@ -2297,7 +2304,7 @@ Handle<JSMessageObject> Isolate::CreateMessage(Handle<Object> exception,
} }
if (stack_trace_object.is_null()) { if (stack_trace_object.is_null()) {
// Not an error object, we capture stack and location at throw site. // Not an error object, we capture stack and location at throw site.
stack_trace_object = CaptureCurrentStackTrace( stack_trace_object = CaptureDetailedStackTrace(
stack_trace_for_uncaught_exceptions_frame_limit_, stack_trace_for_uncaught_exceptions_frame_limit_,
stack_trace_for_uncaught_exceptions_options_); stack_trace_for_uncaught_exceptions_options_);
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "src/objects/code.h" #include "src/objects/code.h"
#include "src/objects/contexts.h" #include "src/objects/contexts.h"
#include "src/objects/debug-objects.h" #include "src/objects/debug-objects.h"
#include "src/objects/js-objects.h"
#include "src/runtime/runtime.h" #include "src/runtime/runtime.h"
#include "src/security/external-pointer-table.h" #include "src/security/external-pointer-table.h"
#include "src/security/vm-cage.h" #include "src/security/vm-cage.h"
...@@ -895,8 +896,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -895,8 +896,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
// Similar to the above but without collecting the stack trace. // Similar to the above but without collecting the stack trace.
V8_NOINLINE void PushParamsAndDie(void* ptr1 = nullptr, void* ptr2 = nullptr, V8_NOINLINE void PushParamsAndDie(void* ptr1 = nullptr, void* ptr2 = nullptr,
void* ptr3 = nullptr, void* ptr4 = nullptr); void* ptr3 = nullptr, void* ptr4 = nullptr);
Handle<FixedArray> CaptureCurrentStackTrace( Handle<FixedArray> CaptureDetailedStackTrace(
int frame_limit, StackTrace::StackTraceOptions options); int limit, StackTrace::StackTraceOptions options);
Handle<Object> CaptureSimpleStackTrace(Handle<JSReceiver> error_object, Handle<Object> CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
FrameSkipMode mode, FrameSkipMode mode,
Handle<Object> caller); Handle<Object> caller);
...@@ -905,7 +906,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory { ...@@ -905,7 +906,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
MaybeHandle<JSReceiver> CaptureAndSetSimpleStackTrace( MaybeHandle<JSReceiver> CaptureAndSetSimpleStackTrace(
Handle<JSReceiver> error_object, FrameSkipMode mode, Handle<JSReceiver> error_object, FrameSkipMode mode,
Handle<Object> caller); Handle<Object> caller);
Handle<FixedArray> GetDetailedStackTrace(Handle<JSObject> error_object); Handle<FixedArray> GetDetailedStackTrace(Handle<JSReceiver> error_object);
Handle<FixedArray> GetSimpleStackTrace(Handle<JSReceiver> error_object);
Address GetAbstractPC(int* line, int* column); Address GetAbstractPC(int* line, int* column);
......
...@@ -1057,10 +1057,8 @@ own<Frame> Trap::origin() const { ...@@ -1057,10 +1057,8 @@ own<Frame> Trap::origin() const {
i::Isolate* isolate = impl(this)->isolate(); i::Isolate* isolate = impl(this)->isolate();
i::HandleScope handle_scope(isolate); i::HandleScope handle_scope(isolate);
i::Handle<i::JSMessageObject> message = i::Handle<i::FixedArray> frames =
isolate->CreateMessage(impl(this)->v8_object(), nullptr); isolate->GetSimpleStackTrace(impl(this)->v8_object());
i::Handle<i::FixedArray> frames(i::FixedArray::cast(message->stack_frames()),
isolate);
if (frames->length() == 0) { if (frames->length() == 0) {
return own<Frame>(); return own<Frame>();
} }
...@@ -1071,10 +1069,8 @@ ownvec<Frame> Trap::trace() const { ...@@ -1071,10 +1069,8 @@ ownvec<Frame> Trap::trace() const {
i::Isolate* isolate = impl(this)->isolate(); i::Isolate* isolate = impl(this)->isolate();
i::HandleScope handle_scope(isolate); i::HandleScope handle_scope(isolate);
i::Handle<i::JSMessageObject> message = i::Handle<i::FixedArray> frames =
isolate->CreateMessage(impl(this)->v8_object(), nullptr); isolate->GetSimpleStackTrace(impl(this)->v8_object());
i::Handle<i::FixedArray> frames(i::FixedArray::cast(message->stack_frames()),
isolate);
int num_frames = frames->length(); int num_frames = frames->length();
// {num_frames} can be 0; the code below can handle that case. // {num_frames} can be 0; the code below can handle that case.
ownvec<Frame> result = ownvec<Frame>::make_uninitialized(num_frames); ownvec<Frame> result = ownvec<Frame>::make_uninitialized(num_frames);
......
...@@ -210,8 +210,8 @@ WASM_COMPILED_EXEC_TEST(CollectDetailedWasmStack_WasmUrl) { ...@@ -210,8 +210,8 @@ WASM_COMPILED_EXEC_TEST(CollectDetailedWasmStack_WasmUrl) {
// Extract stack trace from the exception. // Extract stack trace from the exception.
Handle<FixedArray> stack_trace_object = Handle<FixedArray> stack_trace_object =
isolate->GetDetailedStackTrace(Handle<JSObject>::cast(exception)); isolate->GetSimpleStackTrace(Handle<JSReceiver>::cast(exception));
CHECK(!stack_trace_object.is_null()); CHECK_NE(0, stack_trace_object->length());
Handle<CallSiteInfo> stack_frame( Handle<CallSiteInfo> stack_frame(
CallSiteInfo::cast(stack_trace_object->get(0)), isolate); CallSiteInfo::cast(stack_trace_object->get(0)), 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