Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/debug/debug-frames.cc

Issue 1264993002: Debugger: refactor ScopeIterator, FrameInspector and DebugEvaluate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: readd include Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/debug/debug-frames.h"
6
7 namespace v8 {
8 namespace internal {
9
10 FrameInspector::FrameInspector(JavaScriptFrame* frame,
11 int inlined_jsframe_index, Isolate* isolate)
12 : frame_(frame), deoptimized_frame_(NULL), isolate_(isolate) {
13 has_adapted_arguments_ = frame_->has_adapted_arguments();
14 is_bottommost_ = inlined_jsframe_index == 0;
15 is_optimized_ = frame_->is_optimized();
16 // Calculate the deoptimized frame.
17 if (frame->is_optimized()) {
18 // TODO(turbofan): Revisit once we support deoptimization.
19 if (frame->LookupCode()->is_turbofanned() &&
20 frame->function()->shared()->asm_function() &&
21 !FLAG_turbo_asm_deoptimization) {
22 is_optimized_ = false;
23 return;
24 }
25
26 deoptimized_frame_ = Deoptimizer::DebuggerInspectableFrame(
27 frame, inlined_jsframe_index, isolate);
28 }
29 }
30
31
32 FrameInspector::~FrameInspector() {
33 // Get rid of the calculated deoptimized frame if any.
34 if (deoptimized_frame_ != NULL) {
35 Deoptimizer::DeleteDebuggerInspectableFrame(deoptimized_frame_, isolate_);
36 }
37 }
38
39
40 int FrameInspector::GetParametersCount() {
41 return is_optimized_ ? deoptimized_frame_->parameters_count()
42 : frame_->ComputeParametersCount();
43 }
44
45
46 int FrameInspector::expression_count() {
47 return deoptimized_frame_->expression_count();
48 }
49
50
51 Object* FrameInspector::GetFunction() {
52 return is_optimized_ ? deoptimized_frame_->GetFunction() : frame_->function();
53 }
54
55
56 Object* FrameInspector::GetParameter(int index) {
57 return is_optimized_ ? deoptimized_frame_->GetParameter(index)
58 : frame_->GetParameter(index);
59 }
60
61
62 Object* FrameInspector::GetExpression(int index) {
63 // TODO(turbofan): Revisit once we support deoptimization.
64 if (frame_->LookupCode()->is_turbofanned() &&
65 frame_->function()->shared()->asm_function() &&
66 !FLAG_turbo_asm_deoptimization) {
67 return isolate_->heap()->undefined_value();
68 }
69 return is_optimized_ ? deoptimized_frame_->GetExpression(index)
70 : frame_->GetExpression(index);
71 }
72
73
74 int FrameInspector::GetSourcePosition() {
75 return is_optimized_ ? deoptimized_frame_->GetSourcePosition()
76 : frame_->LookupCode()->SourcePosition(frame_->pc());
77 }
78
79
80 bool FrameInspector::IsConstructor() {
81 return is_optimized_ && !is_bottommost_
82 ? deoptimized_frame_->HasConstructStub()
83 : frame_->IsConstructor();
84 }
85
86
87 Object* FrameInspector::GetContext() {
88 return is_optimized_ ? deoptimized_frame_->GetContext() : frame_->context();
89 }
90
91
92 // To inspect all the provided arguments the frame might need to be
93 // replaced with the arguments frame.
94 void FrameInspector::SetArgumentsFrame(JavaScriptFrame* frame) {
95 DCHECK(has_adapted_arguments_);
96 frame_ = frame;
97 is_optimized_ = frame_->is_optimized();
98 DCHECK(!is_optimized_);
99 }
100
101
102 // Create a plain JSObject which materializes the local scope for the specified
103 // frame.
104 void FrameInspector::MaterializeStackLocals(Handle<JSObject> target,
105 Handle<ScopeInfo> scope_info) {
106 HandleScope scope(isolate_);
107 // First fill all parameters.
108 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
109 // Do not materialize the parameter if it is shadowed by a context local.
110 Handle<String> name(scope_info->ParameterName(i));
111 if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;
112
113 Handle<Object> value(i < GetParametersCount()
114 ? GetParameter(i)
115 : isolate_->heap()->undefined_value(),
116 isolate_);
117 DCHECK(!value->IsTheHole());
118
119 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check();
120 }
121
122 // Second fill all stack locals.
123 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
124 if (scope_info->LocalIsSynthetic(i)) continue;
125 Handle<String> name(scope_info->StackLocalName(i));
126 Handle<Object> value(GetExpression(scope_info->StackLocalIndex(i)),
127 isolate_);
128 if (value->IsTheHole()) value = isolate_->factory()->undefined_value();
129
130 JSObject::SetOwnPropertyIgnoreAttributes(target, name, value, NONE).Check();
131 }
132 }
133
134
135 void FrameInspector::MaterializeStackLocals(Handle<JSObject> target,
136 Handle<JSFunction> function) {
137 Handle<SharedFunctionInfo> shared(function->shared());
138 Handle<ScopeInfo> scope_info(shared->scope_info());
139 MaterializeStackLocals(target, scope_info);
140 }
141
142
143 void FrameInspector::UpdateStackLocalsFromMaterializedObject(
144 Handle<JSObject> target, Handle<ScopeInfo> scope_info) {
145 if (is_optimized_) {
146 // Optimized frames are not supported. Simply give up.
147 return;
148 }
149
150 HandleScope scope(isolate_);
151
152 // Parameters.
153 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
154 // Shadowed parameters were not materialized.
155 Handle<String> name(scope_info->ParameterName(i));
156 if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;
157
158 DCHECK(!frame_->GetParameter(i)->IsTheHole());
159 Handle<Object> value =
160 Object::GetPropertyOrElement(target, name).ToHandleChecked();
161 frame_->SetParameterValue(i, *value);
162 }
163
164 // Stack locals.
165 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
166 if (scope_info->LocalIsSynthetic(i)) continue;
167 int index = scope_info->StackLocalIndex(i);
168 if (frame_->GetExpression(index)->IsTheHole()) continue;
169 Handle<Object> value =
170 Object::GetPropertyOrElement(
171 target, handle(scope_info->StackLocalName(i), isolate_))
172 .ToHandleChecked();
173 frame_->SetExpression(index, *value);
174 }
175 }
176
177
178 bool FrameInspector::ParameterIsShadowedByContextLocal(
179 Handle<ScopeInfo> info, Handle<String> parameter_name) {
180 VariableMode mode;
181 VariableLocation location;
182 InitializationFlag init_flag;
183 MaybeAssignedFlag maybe_assigned_flag;
184 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &location,
185 &init_flag, &maybe_assigned_flag) != -1;
186 }
187
188
189 SaveContext* DebugFrameHelper::FindSavedContextForFrame(
190 Isolate* isolate, JavaScriptFrame* frame) {
191 SaveContext* save = isolate->save_context();
192 while (save != NULL && !save->IsBelowFrame(frame)) {
193 save = save->prev();
194 }
195 DCHECK(save != NULL);
196 return save;
197 }
198
199
200 int DebugFrameHelper::FindIndexedNonNativeFrame(JavaScriptFrameIterator* it,
201 int index) {
202 int count = -1;
203 for (; !it->done(); it->Advance()) {
204 List<FrameSummary> frames(FLAG_max_inlining_levels + 1);
205 it->frame()->Summarize(&frames);
206 for (int i = frames.length() - 1; i >= 0; i--) {
207 // Omit functions from native and extension scripts.
208 if (!frames[i].function()->IsSubjectToDebugging()) continue;
209 if (++count == index) return i;
210 }
211 }
212 return -1;
213 }
214
215
216 } // namespace internal
217 } // namespace v8
OLDNEW
« no previous file with comments | « src/debug/debug-frames.h ('k') | src/debug/debug-scopes.h » ('j') | src/debug/debug-scopes.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698