5 #include "src/debug/debug-stack-trace-iterator.h" 7 #include "src/api-inl.h" 8 #include "src/debug/debug-evaluate.h" 9 #include "src/debug/debug-scope-iterator.h" 10 #include "src/debug/debug.h" 11 #include "src/debug/liveedit.h" 12 #include "src/frames-inl.h" 13 #include "src/isolate.h" 17 std::unique_ptr<debug::StackTraceIterator> debug::StackTraceIterator::Create(
18 v8::Isolate* isolate,
int index) {
19 return std::unique_ptr<debug::StackTraceIterator>(
20 new internal::DebugStackTraceIterator(
21 reinterpret_cast<internal::Isolate*>(isolate), index));
26 DebugStackTraceIterator::DebugStackTraceIterator(Isolate* isolate,
int index)
28 iterator_(isolate, isolate->debug()->break_frame_id()),
30 if (iterator_.done())
return;
31 std::vector<FrameSummary> frames;
32 iterator_.frame()->Summarize(&frames);
33 inlined_frame_index_ =
static_cast<int>(frames.size());
35 for (; !Done() && index > 0; --index) Advance();
38 DebugStackTraceIterator::~DebugStackTraceIterator() =
default;
40 bool DebugStackTraceIterator::Done()
const {
return iterator_.done(); }
42 void DebugStackTraceIterator::Advance() {
44 --inlined_frame_index_;
45 for (; inlined_frame_index_ >= 0; --inlined_frame_index_) {
47 if (FrameSummary::Get(iterator_.frame(), inlined_frame_index_)
48 .is_subject_to_debugging()) {
51 is_top_frame_ =
false;
53 if (inlined_frame_index_ >= 0) {
54 frame_inspector_.reset(
new FrameInspector(
55 iterator_.frame(), inlined_frame_index_, isolate_));
58 is_top_frame_ =
false;
59 frame_inspector_.reset();
61 if (iterator_.done())
break;
62 std::vector<FrameSummary> frames;
63 iterator_.frame()->Summarize(&frames);
64 inlined_frame_index_ =
static_cast<int>(frames.size());
68 int DebugStackTraceIterator::GetContextId()
const {
70 Handle<Object> context = frame_inspector_->GetContext();
71 if (context->IsContext()) {
73 Context::cast(*context)->native_context()->debug_context_id();
74 if (value->IsSmi())
return Smi::ToInt(value);
81 if (frame_inspector_->IsJavaScript() &&
82 frame_inspector_->GetFunction()->shared()->kind() == kArrowFunction) {
86 Handle<JSFunction>
function = frame_inspector_->GetFunction();
87 Handle<Context> context(function->context(), isolate_);
91 ScopeIterator scope_iterator(isolate_, frame_inspector_.get(),
92 ScopeIterator::COLLECT_NON_LOCALS);
95 if (!scope_iterator.GetNonLocals()->Has(isolate_,
96 isolate_->factory()->this_string()))
99 Handle<ScopeInfo> scope_info(context->scope_info(), isolate_);
101 InitializationFlag flag;
102 MaybeAssignedFlag maybe_assigned_flag;
103 int slot_index = ScopeInfo::ContextSlotIndex(
104 scope_info, isolate_->factory()->this_string(), &mode, &flag,
105 &maybe_assigned_flag);
107 Handle<Object> value = handle(context->get(slot_index), isolate_);
109 return Utils::ToLocal(value);
111 Handle<Object> value = frame_inspector_->GetReceiver();
112 if (value.is_null() || (value->IsSmi() || !value->IsTheHole(isolate_))) {
113 return Utils::ToLocal(value);
120 if (frame_inspector_ && frame_inspector_->IsWasm()) {
123 bool is_optimized = iterator_.frame()->is_optimized();
124 if (is_optimized || !is_top_frame_ ||
125 !isolate_->debug()->IsBreakAtReturn(iterator_.javascript_frame())) {
128 return Utils::ToLocal(isolate_->debug()->return_value_handle());
133 return Utils::ToLocal(frame_inspector_->GetFunctionName());
138 Handle<Object> value = frame_inspector_->GetScript();
140 return ToApiHandle<debug::Script>(Handle<Script>::cast(value));
143 debug::Location DebugStackTraceIterator::GetSourceLocation()
const {
147 return script->GetSourceLocation(frame_inspector_->GetSourcePosition());
153 return Utils::ToLocal(frame_inspector_->GetFunction());
156 std::unique_ptr<v8::debug::ScopeIterator>
157 DebugStackTraceIterator::GetScopeIterator()
const {
159 StandardFrame* frame = iterator_.frame();
160 if (frame->is_wasm_interpreter_entry()) {
161 return std::unique_ptr<v8::debug::ScopeIterator>(
new DebugWasmScopeIterator(
162 isolate_, iterator_.frame(), inlined_frame_index_));
164 return std::unique_ptr<v8::debug::ScopeIterator>(
165 new DebugScopeIterator(isolate_, frame_inspector_.get()));
168 bool DebugStackTraceIterator::Restart() {
170 if (iterator_.is_wasm())
return false;
171 return !LiveEdit::RestartFrame(iterator_.javascript_frame());
177 Handle<Object> value;
179 if (!DebugEvaluate::Local(isolate_, iterator_.frame()->id(),
180 inlined_frame_index_, Utils::OpenHandle(*source),
181 throw_on_side_effect)
183 isolate_->OptionalRescheduleException(
false);
186 return Utils::ToLocal(value);
V8_INLINE bool IsEmpty() const