Commit 8ee846d8 authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[DevTools] allow to set breakpoint almost everywhere

Lookup for inline breakpoints only at current line.
If nothing found that try to set breakpoint at next breakable location
inside current function.

R=dgozman@chromium.org

Bug: chromium:856665
Change-Id: I3b5d474815adf3778430813f0a6de1d79ae35fec
Reviewed-on: https://chromium-review.googlesource.com/1114467
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: default avatarJoel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570975}
parent 734d2825
Check that we can set breakpoint in collected function
evaluate script and collect function foo..
set breakpoint inside function foo and dump it..
breakpoint at 1
run script again, dump pause location and inline breakpoints..
Script execution paused.
Call stack:
0) foo (foo.js:2)
1) (foo.js:7)
breakpoint at 1
inline breakpoint at (1, 2)
inline breakpoint at (1, 11) disabled
Script execution resumed.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function test() {
TestRunner.addResult(
'Check that we can set breakpoint in collected function');
await TestRunner.loadModule('sources_test_runner');
await TestRunner.showPanel('sources');
await SourcesTestRunner.startDebuggerTestPromise();
TestRunner.addResult('evaluate script and collect function foo..');
const script = `function foo() {
return 1;
}
function boo() {
return 2;
}
foo();
foo = null;
//# sourceURL=foo.js`;
await TestRunner.evaluateInPageAnonymously(script);
await Promise.all(SDK.targetManager.models(SDK.HeapProfilerModel)
.map(model => model.collectGarbage()));
TestRunner.addResult('set breakpoint inside function foo and dump it..');
let sourceFrame = await new Promise(
resolve => SourcesTestRunner.showScriptSource('foo.js', resolve));
SourcesTestRunner.toggleBreakpoint(sourceFrame, 1, false);
await new Promise(
resolve => TestRunner.addSniffer(
Sources.DebuggerPlugin.prototype, '_breakpointWasSetForTest',
resolve));
await SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
TestRunner.addResult(
'run script again, dump pause location and inline breakpoints..');
TestRunner.evaluateInPageAnonymously(script);
let inlineBreakpointsReady =
SourcesTestRunner.waitDebuggerPluginBreakpoints();
let callFrames = await SourcesTestRunner.waitUntilPausedPromise();
SourcesTestRunner.captureStackTrace(callFrames);
sourceFrame = await new Promise(
resolve => SourcesTestRunner.showScriptSource('foo.js', resolve));
await inlineBreakpointsReady;
await SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.completeDebuggerTest();
})();
\ No newline at end of file
Tests shifted breakpoint.
Set enabled breakpoint close to shifted location
breakpoint at 27
inline breakpoint at (27, 2)
inline breakpoint at (27, 11) disabled
breakpoint at 29
Remove breakpoint
Set disabled breakpoint close to shifted location
breakpoint at 27 disabled
breakpoint at 25 disabled
Remove breakpoint
Set enabled breakpoint far away from shifted location
breakpoint at 27
inline breakpoint at (27, 2)
inline breakpoint at (27, 11) disabled
breakpoint at 29
Remove breakpoint
Set disabled breakpoint far away from shifted location
breakpoint at 27 disabled
breakpoint at 19 disabled
Remove breakpoint
Set breakpoint after script end
Set two breakpoints with the same shifted line
breakpoint at 27
inline breakpoint at (27, 2)
inline breakpoint at (27, 11) disabled
breakpoint at 29
Remove breakpoint
......@@ -16,7 +16,7 @@
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
TestRunner.addResult('Remove breakpoint');
SourcesTestRunner.toggleBreakpoint(sourceFrame, 27, false);
SourcesTestRunner.toggleBreakpoint(sourceFrame, 29, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
......@@ -26,7 +26,7 @@
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
TestRunner.addResult('Remove breakpoint');
SourcesTestRunner.toggleBreakpoint(sourceFrame, 27, false);
SourcesTestRunner.toggleBreakpoint(sourceFrame, 25, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
......@@ -36,7 +36,7 @@
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
TestRunner.addResult('Remove breakpoint');
SourcesTestRunner.toggleBreakpoint(sourceFrame, 27, false);
SourcesTestRunner.toggleBreakpoint(sourceFrame, 29, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
......@@ -46,7 +46,7 @@
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
TestRunner.addResult('Remove breakpoint');
SourcesTestRunner.toggleBreakpoint(sourceFrame, 27, false);
SourcesTestRunner.toggleBreakpoint(sourceFrame, 19, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
......@@ -57,12 +57,13 @@
TestRunner.addResult('Set two breakpoints with the same shifted line');
SourcesTestRunner.toggleBreakpoint(sourceFrame, 19, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.toggleBreakpoint(sourceFrame, 25, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
TestRunner.addResult('Remove breakpoint');
SourcesTestRunner.toggleBreakpoint(sourceFrame, 27, false);
SourcesTestRunner.toggleBreakpoint(sourceFrame, 29, false);
await SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame);
SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame);
......
......@@ -3,8 +3,8 @@ Checks that locations are correctly resolved for gutter click.
3: breakpointAdded(3, 11)
4: breakpointAdded(4, 8)
5: breakpointAdded(5, 0)
6: breakpointAdded(10, 8)
6: breakpointAdded(6, 0)
11: breakpointAdded(11, 0)
12: breakpointAdded(12, 0)
13: breakpointAdded(14, 8)
13: breakpointAdded(13, 0)
......@@ -25,11 +25,11 @@ breakpoint at 2
inline breakpoint at (2, 4)
inline breakpoint at (2, 13) disabled
Adding conditional enabled breakpoint
breakpoint at 2 conditional
breakpoint at 2
inline breakpoint at (2, 4)
inline breakpoint at (2, 13) disabled
Disable breakpoints
breakpoint at 2 disabled conditional
breakpoint at 2 disabled
Enable breakpoints
breakpoint at 2 conditional
inline breakpoint at (2, 4)
......
......@@ -9,7 +9,7 @@
await TestRunner.addScriptTag('resources/edit-me-breakpoints.js');
function waitAndDumpDecorations(sourceFrame) {
return SourcesTestRunner.waitBreakpointSidebarPane(true).then(
return SourcesTestRunner.waitDebuggerPluginBreakpoints(sourceFrame).then(
() => SourcesTestRunner.dumpDebuggerPluginBreakpoints(sourceFrame));
}
......@@ -42,7 +42,8 @@
javaScriptSourceFrame = sourceFrame;
TestRunner.addResult('Setting breakpoint');
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 2, '', true)
.then(() => SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 0, 'true', true))
.then(() => SourcesTestRunner.waitBreakpointSidebarPane(true))
.then(() => SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 2, 'true', true))
.then(() => waitAndDumpDecorations(javaScriptSourceFrame))
.then(removeBreakpoint);
}
......@@ -68,19 +69,19 @@
function addConditionalDisabled() {
TestRunner.addResult('Adding conditional disabled breakpoint');
waitAndDumpDecorations(javaScriptSourceFrame).then(addRegularEnabled);
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 0, 'true', false);
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 2, 'true', false);
}
function addRegularEnabled() {
TestRunner.addResult('Adding regular enabled breakpoint');
waitAndDumpDecorations(javaScriptSourceFrame).then(addConditionalEnabled);
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 0, '', true);
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 2, '', true);
}
function addConditionalEnabled() {
TestRunner.addResult('Adding conditional enabled breakpoint');
waitAndDumpDecorations(javaScriptSourceFrame).then(disableAll);
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 0, 'true', true);
SourcesTestRunner.createNewBreakpoint(javaScriptSourceFrame, 2, 'true', true);
}
function disableAll() {
......
......@@ -61,8 +61,8 @@ Click by first inline breakpoints
Running: testAddRemoveBreakpointInLineWithoutBreakableLocations
Setting breakpoint
breakpoint at 25
inline breakpoint at (25, 8)
inline breakpoint at (25, 18) disabled
breakpoint at 28
inline breakpoint at (28, 6)
inline breakpoint at (28, 14) disabled
Toggle breakpoint
......@@ -25,6 +25,8 @@
function boo() {
return 42;
}
console.log(42);
//# sourceURL=foo.js
`);
......@@ -141,7 +143,7 @@
TestRunner.addResult('Toggle breakpoint');
let decorationsPromise = waitAndDumpDecorations(javaScriptSourceFrame);
SourcesTestRunner.toggleBreakpoint(javaScriptSourceFrame, 25);
SourcesTestRunner.toggleBreakpoint(javaScriptSourceFrame, 28);
await decorationsPromise;
next();
}
......
......@@ -1535,18 +1535,8 @@ Sources.DebuggerPlugin = class extends Sources.UISourceCodeFrame.Plugin {
*/
async _createNewBreakpoint(editorLineNumber, condition, enabled) {
Host.userMetrics.actionTaken(Host.UserMetrics.Action.ScriptsBreakpointSet);
const origin = this._transformer.editorToRawLocation(editorLineNumber, 0);
const maxLengthToCheck = 1024;
let linesToCheck = 5;
for (; editorLineNumber < this._textEditor.linesCount && linesToCheck > 0; ++editorLineNumber) {
const lineLength = this._textEditor.line(editorLineNumber).length;
if (lineLength > maxLengthToCheck)
break;
if (lineLength === 0)
continue;
--linesToCheck;
if (editorLineNumber < this._textEditor.linesCount) {
const lineLength = Math.min(this._textEditor.line(editorLineNumber).length, 1024);
const start = this._transformer.editorToRawLocation(editorLineNumber, 0);
const end = this._transformer.editorToRawLocation(editorLineNumber, lineLength);
const locations = await this._breakpointManager.possibleBreakpoints(
......@@ -1556,7 +1546,8 @@ Sources.DebuggerPlugin = class extends Sources.UISourceCodeFrame.Plugin {
return;
}
}
this._setBreakpoint(origin[0], origin[1], condition, enabled);
const origin = this._transformer.editorToRawLocation(editorLineNumber, 0);
await this._setBreakpoint(origin[0], origin[1], condition, enabled);
}
/**
......
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