Commit 80635217 authored by Kim-Anh Tran's avatar Kim-Anh Tran Committed by Commit Bot

[debugger] Re-compile top-level functions in GetPossibleBreakpoints

This adds a re-compilation of top level functions in
getPossibleBreakpoints if no candidates could be found.
This step is necessary as the GC may remove SharedFunctionInfo about
top-level functions.

Bug: chromium:1137141
Change-Id: I8830438d78751ba318d65f43d790ee98f306a57e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2696154Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73008}
parent f360ed87
......@@ -1482,6 +1482,15 @@ void FindBreakablePositions(Handle<DebugInfo> debug_info, int start_position,
BreakIterator it(debug_info);
GetBreakablePositions(&it, start_position, end_position, locations);
}
void CompileTopLevel(Isolate* isolate, Handle<Script> script) {
UnoptimizedCompileState compile_state(isolate);
UnoptimizedCompileFlags flags =
UnoptimizedCompileFlags::ForScriptCompile(isolate, *script);
ParseInfo parse_info(isolate, flags, &compile_state);
IsCompiledScope is_compiled_scope;
Compiler::CompileToplevel(&parse_info, script, isolate, &is_compiled_scope);
}
} // namespace
bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
......@@ -1503,6 +1512,8 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
return true;
}
bool candidateSubsumesRange = false;
bool triedTopLevelCompile = false;
while (true) {
HandleScope scope(isolate_);
std::vector<Handle<SharedFunctionInfo>> candidates;
......@@ -1514,11 +1525,27 @@ bool Debug::GetPossibleBreakpoints(Handle<Script> script, int start_position,
info.StartPosition() >= end_position) {
continue;
}
candidateSubsumesRange |= info.StartPosition() <= start_position &&
info.EndPosition() >= end_position;
if (!info.IsSubjectToDebugging()) continue;
if (!info.is_compiled() && !info.allows_lazy_compilation()) continue;
candidates.push_back(i::handle(info, isolate_));
}
if (!triedTopLevelCompile && !candidateSubsumesRange &&
script->shared_function_infos().length() > 0) {
MaybeObject maybeToplevel = script->shared_function_infos().Get(0);
HeapObject heap_object;
const bool topLevelInfoExists =
maybeToplevel->GetHeapObject(&heap_object) &&
!heap_object.IsUndefined();
if (!topLevelInfoExists) {
CompileTopLevel(isolate_, script);
triedTopLevelCompile = true;
continue;
}
}
bool was_compiled = false;
for (const auto& candidate : candidates) {
IsCompiledScope is_compiled_scope(candidate->is_compiled_scope(isolate_));
......@@ -1631,17 +1658,11 @@ Handle<Object> Debug::FindSharedFunctionInfoInScript(Handle<Script> script,
IsCompiledScope is_compiled_scope;
{
shared = FindSharedFunctionInfoCandidate(position, script, isolate_);
if (shared.is_null()) {
if (shared.is_null() && iteration == 0) {
// It might be that the shared function info is not available as the
// top level functions are removed due to the GC. Try to recompile
// the top level functions.
UnoptimizedCompileState compile_state(isolate_);
UnoptimizedCompileFlags flags =
UnoptimizedCompileFlags::ForScriptCompile(isolate_, *script);
ParseInfo parse_info(isolate_, flags, &compile_state);
IsCompiledScope is_compiled_scope;
Compiler::CompileToplevel(&parse_info, script, isolate_,
&is_compiled_scope);
CompileTopLevel(isolate_, script);
continue;
}
// We found it if it's already compiled.
......
Checks if we keep alive breakpoint information for top-level functions when calling getPossibleBreakpoints.
Result of get possible breakpoints in topLevel.js
[{"scriptId":"3","lineNumber":0,"columnNumber":0},{"scriptId":"3","lineNumber":0,"columnNumber":8,"type":"call"},{"scriptId":"3","lineNumber":0,"columnNumber":43,"type":"return"}]
Result of get possible breakpoints in moduleFunc.js
[{"scriptId":"5","lineNumber":0,"columnNumber":22},{"scriptId":"5","lineNumber":0,"columnNumber":30,"type":"call"},{"scriptId":"5","lineNumber":0,"columnNumber":63,"type":"return"},{"scriptId":"5","lineNumber":0,"columnNumber":64,"type":"return"}]
Result of get possible breakpoints in mixedFunctions.js
[{"scriptId":"7","lineNumber":0,"columnNumber":15,"type":"return"},{"scriptId":"7","lineNumber":1,"columnNumber":2},{"scriptId":"7","lineNumber":1,"columnNumber":10,"type":"call"},{"scriptId":"7","lineNumber":2,"columnNumber":0,"type":"return"}]
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
let {session, contextGroup, Protocol} = InspectorTest.start(
'Checks if we keep alive breakpoint information for top-level functions when calling getPossibleBreakpoints.');
session.setupScriptMap();
var executionContextId;
const callGarbageCollector = `
%CollectGarbage("");
%CollectGarbage("");
%CollectGarbage("");
%CollectGarbage("");
`;
const topLevelFunction = `console.log('This is a top level function')`;
const moduleFunction =
`function testFunc() { console.log('This is a module function') }`;
let mixedFunctions = ` function A() {}
console.log('This is a top level function');
`;
Protocol.Debugger.enable().then(onDebuggerEnabled);
function onDebuggerEnabled() {
Protocol.Runtime.enable();
Protocol.Runtime.onExecutionContextCreated(onExecutionContextCreated);
}
async function onExecutionContextCreated(messageObject) {
executionContextId = messageObject.params.context.id;
await testGetPossibleBreakpoints(
executionContextId, topLevelFunction, 'topLevel.js');
await testGetPossibleBreakpoints(
executionContextId, moduleFunction, 'moduleFunc.js');
await testGetPossibleBreakpoints(
executionContextId, mixedFunctions, 'mixedFunctions.js');
InspectorTest.completeTest();
}
async function testGetPossibleBreakpoints(executionContextId, func, url) {
const obj = await Protocol.Runtime.compileScript({
expression: func,
sourceURL: url,
persistScript: true,
executionContextId: executionContextId
});
const scriptId = obj.result.scriptId;
const location = {start: {lineNumber: 0, columnNumber: 0, scriptId}};
await Protocol.Runtime.runScript({scriptId});
await Protocol.Runtime.evaluate({expression: `${callGarbageCollector}`});
const {result: {locations}} =
await Protocol.Debugger.getPossibleBreakpoints(location);
InspectorTest.log(`Result of get possible breakpoints in ${url}`);
InspectorTest.log(JSON.stringify(locations));
}
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