OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/debug/debug-frames.h" | 5 #include "src/debug/debug-frames.h" |
6 | 6 |
7 #include "src/frames-inl.h" | 7 #include "src/frames-inl.h" |
8 #include "src/wasm/wasm-debug.h" | |
9 #include "src/wasm/wasm-module.h" | |
8 | 10 |
9 namespace v8 { | 11 namespace v8 { |
10 namespace internal { | 12 namespace internal { |
11 | 13 |
12 FrameInspector::FrameInspector(JavaScriptFrame* frame, | 14 FrameInspector::FrameInspector(StandardFrame* frame, int inlined_jsframe_index, |
13 int inlined_jsframe_index, Isolate* isolate) | 15 Isolate* isolate) |
14 : frame_(frame), deoptimized_frame_(NULL), isolate_(isolate) { | 16 : frame_(frame), deoptimized_frame_(NULL), isolate_(isolate) { |
15 has_adapted_arguments_ = frame_->has_adapted_arguments(); | 17 JavaScriptFrame* js_frame = |
18 frame->is_java_script() ? javascript_frame() : nullptr; | |
19 DCHECK(js_frame || frame->is_wasm()); | |
20 has_adapted_arguments_ = js_frame && js_frame->has_adapted_arguments(); | |
16 is_bottommost_ = inlined_jsframe_index == 0; | 21 is_bottommost_ = inlined_jsframe_index == 0; |
17 is_optimized_ = frame_->is_optimized(); | 22 is_optimized_ = frame_->is_optimized(); |
18 is_interpreted_ = frame_->is_interpreted(); | 23 is_interpreted_ = frame_->is_interpreted(); |
19 // Calculate the deoptimized frame. | 24 // Calculate the deoptimized frame. |
20 if (frame->is_optimized()) { | 25 if (frame->is_optimized()) { |
26 DCHECK(js_frame != nullptr); | |
21 // TODO(turbofan): Revisit once we support deoptimization. | 27 // TODO(turbofan): Revisit once we support deoptimization. |
22 if (frame->LookupCode()->is_turbofanned() && | 28 if (js_frame->LookupCode()->is_turbofanned() && |
23 frame->function()->shared()->asm_function() && | 29 js_frame->function()->shared()->asm_function() && |
24 !FLAG_turbo_asm_deoptimization) { | 30 !FLAG_turbo_asm_deoptimization) { |
25 is_optimized_ = false; | 31 is_optimized_ = false; |
26 return; | 32 return; |
27 } | 33 } |
28 | 34 |
29 deoptimized_frame_ = Deoptimizer::DebuggerInspectableFrame( | 35 deoptimized_frame_ = Deoptimizer::DebuggerInspectableFrame( |
30 frame, inlined_jsframe_index, isolate); | 36 js_frame, inlined_jsframe_index, isolate); |
31 } | 37 } |
32 } | 38 } |
33 | 39 |
34 | 40 |
35 FrameInspector::~FrameInspector() { | 41 FrameInspector::~FrameInspector() { |
36 // Get rid of the calculated deoptimized frame if any. | 42 // Get rid of the calculated deoptimized frame if any. |
37 if (deoptimized_frame_ != NULL) { | 43 if (deoptimized_frame_ != NULL) { |
38 Deoptimizer::DeleteDebuggerInspectableFrame(deoptimized_frame_, isolate_); | 44 Deoptimizer::DeleteDebuggerInspectableFrame(deoptimized_frame_, isolate_); |
39 } | 45 } |
40 } | 46 } |
41 | 47 |
42 | 48 |
43 int FrameInspector::GetParametersCount() { | 49 int FrameInspector::GetParametersCount() { |
44 return is_optimized_ ? deoptimized_frame_->parameters_count() | 50 if (is_optimized_) return deoptimized_frame_->parameters_count(); |
45 : frame_->ComputeParametersCount(); | 51 if (frame_->is_wasm()) { |
52 // TODO(clemensh): return real parameter count | |
53 return 0; | |
54 } | |
55 return javascript_frame()->ComputeParametersCount(); | |
Yang
2016/06/16 14:10:41
Can we make ComputeParameterCount a virtual method
Clemens Hammacher
2016/06/16 17:02:30
Done.
| |
46 } | 56 } |
47 | 57 |
48 Handle<Object> FrameInspector::GetFunction() { | 58 Handle<Script> FrameInspector::GetScript() { |
59 if (frame_->is_wasm()) { | |
60 DCHECK(wasm_frame()->wasm_obj()->IsJSObject()); | |
Yang
2016/06/16 14:10:41
I wish we don't have to check against is_wasm ever
Clemens Hammacher
2016/06/16 17:02:30
We don't have a JSFunction for wasm frames, that's
| |
61 JSObject* wasm_obj = JSObject::cast(wasm_frame()->wasm_obj()); | |
62 int func_index = wasm_frame()->function_index(); | |
63 return handle(wasm::GetDebugInfo(wasm_obj)->GetFunctionScript(func_index), | |
64 isolate_); | |
65 } | |
66 return handle(Script::cast(GetFunction()->shared()->script()), isolate_); | |
67 } | |
68 | |
69 Handle<JSFunction> FrameInspector::GetFunction() { | |
70 DCHECK(!frame_->is_wasm()); | |
49 return is_optimized_ ? deoptimized_frame_->GetFunction() | 71 return is_optimized_ ? deoptimized_frame_->GetFunction() |
50 : handle(frame_->function(), isolate_); | 72 : handle(javascript_frame()->function(), isolate_); |
51 } | 73 } |
52 | 74 |
53 Handle<Object> FrameInspector::GetParameter(int index) { | 75 Handle<Object> FrameInspector::GetParameter(int index) { |
54 return is_optimized_ ? deoptimized_frame_->GetParameter(index) | 76 if (is_optimized_) return deoptimized_frame_->GetParameter(index); |
55 : handle(frame_->GetParameter(index), isolate_); | 77 if (frame_->is_wasm()) { |
78 // TODO(clemensh): return real parameter value for debugged frame | |
79 return isolate_->factory()->undefined_value(); | |
80 } | |
81 return handle(javascript_frame()->GetParameter(index), isolate_); | |
Yang
2016/06/16 14:10:41
Same here. GetParameter could be a virtual method
Clemens Hammacher
2016/06/16 17:02:30
Done.
| |
56 } | 82 } |
57 | 83 |
58 Handle<Object> FrameInspector::GetExpression(int index) { | 84 Handle<Object> FrameInspector::GetExpression(int index) { |
85 if (frame_->is_wasm()) { | |
86 // TODO(clemensh): find out what this function does, and whether we can do | |
87 // anything for wasm | |
88 return isolate_->factory()->undefined_value(); | |
89 } | |
90 | |
91 JavaScriptFrame* js_frame = javascript_frame(); | |
59 // TODO(turbofan): Revisit once we support deoptimization. | 92 // TODO(turbofan): Revisit once we support deoptimization. |
60 if (frame_->LookupCode()->is_turbofanned() && | 93 if (js_frame->LookupCode()->is_turbofanned() && |
61 frame_->function()->shared()->asm_function() && | 94 js_frame->function()->shared()->asm_function() && |
62 !FLAG_turbo_asm_deoptimization) { | 95 !FLAG_turbo_asm_deoptimization) { |
63 return isolate_->factory()->undefined_value(); | 96 return isolate_->factory()->undefined_value(); |
64 } | 97 } |
65 return is_optimized_ ? deoptimized_frame_->GetExpression(index) | 98 return is_optimized_ ? deoptimized_frame_->GetExpression(index) |
66 : handle(frame_->GetExpression(index), isolate_); | 99 : handle(js_frame->GetExpression(index), isolate_); |
67 } | 100 } |
68 | 101 |
69 | 102 |
70 int FrameInspector::GetSourcePosition() { | 103 int FrameInspector::GetSourcePosition() { |
71 if (is_optimized_) { | 104 if (is_optimized_) { |
72 return deoptimized_frame_->GetSourcePosition(); | 105 return deoptimized_frame_->GetSourcePosition(); |
73 } else if (is_interpreted_) { | 106 } else if (is_interpreted_) { |
74 InterpretedFrame* frame = reinterpret_cast<InterpretedFrame*>(frame_); | 107 InterpretedFrame* frame = reinterpret_cast<InterpretedFrame*>(frame_); |
75 BytecodeArray* bytecode_array = frame->GetBytecodeArray(); | 108 BytecodeArray* bytecode_array = frame->GetBytecodeArray(); |
76 return bytecode_array->SourcePosition(frame->GetBytecodeOffset()); | 109 return bytecode_array->SourcePosition(frame->GetBytecodeOffset()); |
77 } else { | 110 } else { |
78 Code* code = frame_->LookupCode(); | 111 Code* code = frame_->LookupCode(); |
79 int offset = static_cast<int>(frame_->pc() - code->instruction_start()); | 112 int offset = static_cast<int>(frame_->pc() - code->instruction_start()); |
80 return code->SourcePosition(offset); | 113 return code->SourcePosition(offset); |
81 } | 114 } |
82 } | 115 } |
83 | 116 |
84 | 117 |
85 bool FrameInspector::IsConstructor() { | 118 bool FrameInspector::IsConstructor() { |
119 if (frame_->is_wasm()) return false; | |
86 return is_optimized_ && !is_bottommost_ | 120 return is_optimized_ && !is_bottommost_ |
87 ? deoptimized_frame_->HasConstructStub() | 121 ? deoptimized_frame_->HasConstructStub() |
88 : frame_->IsConstructor(); | 122 : javascript_frame()->IsConstructor(); |
Yang
2016/06/16 14:10:41
Same here.
Clemens Hammacher
2016/06/16 17:02:31
Done.
| |
89 } | 123 } |
90 | 124 |
91 Handle<Object> FrameInspector::GetContext() { | 125 Handle<Object> FrameInspector::GetContext() { |
92 return is_optimized_ ? deoptimized_frame_->GetContext() | 126 if (frame_->is_wasm()) return isolate_->factory()->undefined_value(); |
93 : handle(frame_->context(), isolate_); | 127 if (is_optimized_) return deoptimized_frame_->GetContext(); |
128 return handle(javascript_frame()->context(), isolate_); | |
Yang
2016/06/16 14:10:41
And here.
Clemens Hammacher
2016/06/16 17:02:30
Done.
| |
94 } | 129 } |
95 | 130 |
96 | 131 |
97 // To inspect all the provided arguments the frame might need to be | 132 // To inspect all the provided arguments the frame might need to be |
98 // replaced with the arguments frame. | 133 // replaced with the arguments frame. |
99 void FrameInspector::SetArgumentsFrame(JavaScriptFrame* frame) { | 134 void FrameInspector::SetArgumentsFrame(StandardFrame* frame) { |
100 DCHECK(has_adapted_arguments_); | 135 DCHECK(has_adapted_arguments_); |
136 DCHECK(frame->is_arguments_adaptor()); | |
101 frame_ = frame; | 137 frame_ = frame; |
102 is_optimized_ = frame_->is_optimized(); | 138 is_optimized_ = frame_->is_optimized(); |
103 is_interpreted_ = frame_->is_interpreted(); | 139 is_interpreted_ = frame_->is_interpreted(); |
104 DCHECK(!is_optimized_); | 140 DCHECK(!is_optimized_); |
105 } | 141 } |
106 | 142 |
107 | 143 |
108 // Create a plain JSObject which materializes the local scope for the specified | 144 // Create a plain JSObject which materializes the local scope for the specified |
109 // frame. | 145 // frame. |
110 void FrameInspector::MaterializeStackLocals(Handle<JSObject> target, | 146 void FrameInspector::MaterializeStackLocals(Handle<JSObject> target, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 void FrameInspector::MaterializeStackLocals(Handle<JSObject> target, | 185 void FrameInspector::MaterializeStackLocals(Handle<JSObject> target, |
150 Handle<JSFunction> function) { | 186 Handle<JSFunction> function) { |
151 Handle<SharedFunctionInfo> shared(function->shared()); | 187 Handle<SharedFunctionInfo> shared(function->shared()); |
152 Handle<ScopeInfo> scope_info(shared->scope_info()); | 188 Handle<ScopeInfo> scope_info(shared->scope_info()); |
153 MaterializeStackLocals(target, scope_info); | 189 MaterializeStackLocals(target, scope_info); |
154 } | 190 } |
155 | 191 |
156 | 192 |
157 void FrameInspector::UpdateStackLocalsFromMaterializedObject( | 193 void FrameInspector::UpdateStackLocalsFromMaterializedObject( |
158 Handle<JSObject> target, Handle<ScopeInfo> scope_info) { | 194 Handle<JSObject> target, Handle<ScopeInfo> scope_info) { |
159 if (is_optimized_) { | 195 // Optimized frames and wasm frames are not supported. Simply give up. |
160 // Optimized frames are not supported. Simply give up. | 196 if (is_optimized_ || frame_->is_wasm()) return; |
161 return; | |
162 } | |
163 | 197 |
164 HandleScope scope(isolate_); | 198 HandleScope scope(isolate_); |
165 | 199 |
166 // Parameters. | 200 // Parameters. |
167 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 201 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
168 // Shadowed parameters were not materialized. | 202 // Shadowed parameters were not materialized. |
169 Handle<String> name(scope_info->ParameterName(i)); | 203 Handle<String> name(scope_info->ParameterName(i)); |
170 if (ScopeInfo::VariableIsSynthetic(*name)) continue; | 204 if (ScopeInfo::VariableIsSynthetic(*name)) continue; |
171 if (ParameterIsShadowedByContextLocal(scope_info, name)) continue; | 205 if (ParameterIsShadowedByContextLocal(scope_info, name)) continue; |
172 | 206 |
173 DCHECK(!frame_->GetParameter(i)->IsTheHole(isolate_)); | 207 DCHECK(!javascript_frame()->GetParameter(i)->IsTheHole(isolate_)); |
174 Handle<Object> value = | 208 Handle<Object> value = |
175 Object::GetPropertyOrElement(target, name).ToHandleChecked(); | 209 Object::GetPropertyOrElement(target, name).ToHandleChecked(); |
176 frame_->SetParameterValue(i, *value); | 210 javascript_frame()->SetParameterValue(i, *value); |
177 } | 211 } |
178 | 212 |
179 // Stack locals. | 213 // Stack locals. |
180 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { | 214 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
181 Handle<String> name(scope_info->StackLocalName(i)); | 215 Handle<String> name(scope_info->StackLocalName(i)); |
182 if (ScopeInfo::VariableIsSynthetic(*name)) continue; | 216 if (ScopeInfo::VariableIsSynthetic(*name)) continue; |
183 int index = scope_info->StackLocalIndex(i); | 217 int index = scope_info->StackLocalIndex(i); |
184 if (frame_->GetExpression(index)->IsTheHole(isolate_)) continue; | 218 if (frame_->GetExpression(index)->IsTheHole(isolate_)) continue; |
185 Handle<Object> value = | 219 Handle<Object> value = |
186 Object::GetPropertyOrElement(target, name).ToHandleChecked(); | 220 Object::GetPropertyOrElement(target, name).ToHandleChecked(); |
187 frame_->SetExpression(index, *value); | 221 frame_->SetExpression(index, *value); |
188 } | 222 } |
189 } | 223 } |
190 | 224 |
191 | 225 |
192 bool FrameInspector::ParameterIsShadowedByContextLocal( | 226 bool FrameInspector::ParameterIsShadowedByContextLocal( |
193 Handle<ScopeInfo> info, Handle<String> parameter_name) { | 227 Handle<ScopeInfo> info, Handle<String> parameter_name) { |
194 VariableMode mode; | 228 VariableMode mode; |
195 InitializationFlag init_flag; | 229 InitializationFlag init_flag; |
196 MaybeAssignedFlag maybe_assigned_flag; | 230 MaybeAssignedFlag maybe_assigned_flag; |
197 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag, | 231 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag, |
198 &maybe_assigned_flag) != -1; | 232 &maybe_assigned_flag) != -1; |
199 } | 233 } |
200 | 234 |
201 | 235 SaveContext* DebugFrameHelper::FindSavedContextForFrame(Isolate* isolate, |
202 SaveContext* DebugFrameHelper::FindSavedContextForFrame( | 236 StandardFrame* frame) { |
203 Isolate* isolate, JavaScriptFrame* frame) { | |
204 SaveContext* save = isolate->save_context(); | 237 SaveContext* save = isolate->save_context(); |
205 while (save != NULL && !save->IsBelowFrame(frame)) { | 238 while (save != NULL && !save->IsBelowFrame(frame)) { |
206 save = save->prev(); | 239 save = save->prev(); |
207 } | 240 } |
208 DCHECK(save != NULL); | 241 DCHECK(save != NULL); |
209 return save; | 242 return save; |
210 } | 243 } |
211 | 244 |
212 | 245 int DebugFrameHelper::FindIndexedNonNativeFrame(StackTraceFrameIterator* it, |
213 int DebugFrameHelper::FindIndexedNonNativeFrame(JavaScriptFrameIterator* it, | |
214 int index) { | 246 int index) { |
215 int count = -1; | 247 int count = -1; |
216 for (; !it->done(); it->Advance()) { | 248 for (; !it->done(); it->Advance()) { |
249 if (it->is_wasm()) { | |
250 if (++count == index) return 0; | |
251 continue; | |
252 } | |
217 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); | 253 List<FrameSummary> frames(FLAG_max_inlining_levels + 1); |
218 it->frame()->Summarize(&frames); | 254 it->javascript_frame()->Summarize(&frames); |
219 for (int i = frames.length() - 1; i >= 0; i--) { | 255 for (int i = frames.length() - 1; i >= 0; i--) { |
220 // Omit functions from native and extension scripts. | 256 // Omit functions from native and extension scripts. |
221 if (!frames[i].function()->shared()->IsSubjectToDebugging()) continue; | 257 if (!frames[i].function()->shared()->IsSubjectToDebugging()) continue; |
222 if (++count == index) return i; | 258 if (++count == index) return i; |
223 } | 259 } |
224 } | 260 } |
225 return -1; | 261 return -1; |
226 } | 262 } |
227 | 263 |
228 | 264 |
229 } // namespace internal | 265 } // namespace internal |
230 } // namespace v8 | 266 } // namespace v8 |
OLD | NEW |