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

Unified Diff: src/debug/debug.cc

Issue 2465553003: [inspector] added Debugger.getPossibleBreakpoints method (Closed)
Patch Set: addressed comments Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: src/debug/debug.cc
diff --git a/src/debug/debug.cc b/src/debug/debug.cc
index b3d8347cfd32171d95b40b55b3703532bfa46d37..f029f97507655af28009906cef5830accbc792df 100644
--- a/src/debug/debug.cc
+++ b/src/debug/debug.cc
@@ -1352,6 +1352,94 @@ bool Debug::PrepareFunctionForBreakPoints(Handle<SharedFunctionInfo> shared) {
return true;
}
+namespace {
+template <typename Iterator>
+void GetBreakablePositions(Iterator& it, int start_position, int end_position,
+ BreakPositionAlignment alignment,
+ std::vector<int>& positions) {
+ it.SkipToPosition(start_position, alignment);
+ while (!it.Done() && it.position() < end_position &&
+ it.position() >= start_position) {
+ positions.push_back(alignment == STATEMENT_ALIGNED ? it.statement_position()
+ : it.position());
+ it.Next();
+ }
+}
+} // namespace
+
+void Debug::FindBreakablePositions(Handle<DebugInfo> debug_info,
+ int start_position, int end_position,
+ BreakPositionAlignment alignment,
+ std::vector<int>& positions) {
Yang 2016/11/03 08:03:26 I've seen you do this elsewhere, but maybe we shou
kozy 2016/11/03 17:26:45 Changed to pointer.
+ if (debug_info->HasDebugCode()) {
+ CodeBreakIterator it(debug_info, ALL_BREAK_LOCATIONS);
+ GetBreakablePositions(it, start_position, end_position, alignment,
+ positions);
+ } else {
+ DCHECK(debug_info->HasDebugBytecodeArray());
+ BytecodeArrayBreakIterator it(debug_info, ALL_BREAK_LOCATIONS);
+ GetBreakablePositions(it, start_position, end_position, alignment,
+ positions);
+ }
+}
+
+bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
+ int end_position,
+ std::vector<int>& positions) {
+ while (true) {
+ if (!script->shared_function_infos()->IsWeakFixedArray()) return false;
+
+ WeakFixedArray* infos =
+ WeakFixedArray::cast(script->shared_function_infos());
+ HandleScope scope(isolate_);
+ Handle<FixedArray> candidates =
Yang 2016/11/03 08:03:26 Can we simply use a List<Handle<>> here?
kozy 2016/11/03 17:26:45 Done.
+ isolate_->factory()->NewFixedArray(infos->Length());
+ int length = 0;
+ {
+ WeakFixedArray::Iterator iterator(infos);
+ SharedFunctionInfo* info;
+ while ((info = iterator.Next<SharedFunctionInfo>())) {
+ if (info->end_position() < start_position ||
+ info->start_position() >= end_position) {
+ continue;
+ }
+ if (!info->IsSubjectToDebugging()) continue;
+ if (!info->HasDebugCode() && !info->allows_lazy_compilation()) continue;
+ candidates->set(length++, info);
+ }
+ }
+ candidates->Shrink(length);
+
+ bool was_compiled = false;
+ for (int i = 0; i < length; ++i) {
+ SharedFunctionInfo* info = SharedFunctionInfo::cast(candidates->get(i));
+ Handle<SharedFunctionInfo> info_handle(info);
+ if (!info_handle->HasDebugCode()) {
+ if (!Compiler::CompileDebugCode(info_handle)) {
+ return false;
+ } else {
+ was_compiled = true;
+ }
+ }
+ if (!info_handle->HasDebugInfo()) CreateDebugInfo(info_handle);
+ }
+ if (was_compiled) continue;
+
+ for (int i = 0; i < length; ++i) {
+ SharedFunctionInfo* info = SharedFunctionInfo::cast(candidates->get(i));
+ HandleScope scope(isolate_);
+ Handle<SharedFunctionInfo> info_handle(info);
+ CHECK(info->HasDebugInfo());
+ Handle<DebugInfo> debug_info(info_handle->GetDebugInfo());
+ FindBreakablePositions(debug_info, start_position, end_position,
+ STATEMENT_ALIGNED, positions);
+ }
+ return true;
+ }
+ UNREACHABLE();
+ return false;
+}
+
void Debug::RecordAsyncFunction(Handle<JSGeneratorObject> generator_object) {
if (last_step_action() <= StepOut) return;
if (!IsAsyncFunction(generator_object->function()->shared()->kind())) return;

Powered by Google App Engine
This is Rietveld 408576698