Bug 812172 - Add conditional breakpoint handling to the debugger server. r=past

This commit is contained in:
James Long committed 2014-03-24 09:37:24 -04:00
1 parent 0bbdf3d024
commit b3bc778d24
9 files changed
+230 -11

No files matched your search

+18 -5
View File
@@ -28,6 +28,8 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/devtools/Console.jsm");
let promise = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js").Promise;
const { defer, resolve, reject } = promise;
@@ -1407,17 +1409,28 @@ ThreadClient.prototype = {
* @param function aOnResponse
* Called with the thread's response.
*/
setBreakpoint: function (aLocation, aOnResponse) {
setBreakpoint: function ({ url, line, column, condition }, aOnResponse) {
// A helper function that sets the breakpoint.
let doSetBreakpoint = function (aCallback) {
let packet = { to: this._actor, type: "setBreakpoint",
location: aLocation };
const location = {
url: url,
line: line,
column: column
};
let packet = {
to: this._actor,
type: "setBreakpoint",
location: location,
condition: condition
};
this.client.request(packet, function (aResponse) {
// Ignoring errors, since the user may be setting a breakpoint in a
// dead script that will reappear on a page reload.
if (aOnResponse) {
let bpClient = new BreakpointClient(this.client, aResponse.actor,
aLocation);
let bpClient = new BreakpointClient(this.client,
aResponse.actor,
location);
if (aCallback) {
aCallback(aOnResponse(aResponse, bpClient));
} else {
+2
View File
@@ -187,6 +187,8 @@ RootActor.prototype = {
storageInspector: true,
// Wether storage inspector is read only
storageInspectorReadOnly: true,
// Wether conditional breakpoints are supported
conditionalBreakpoints: true
}
};
},
+22 -6
View File
@@ -38,7 +38,7 @@ function BreakpointStore() {
//
// is an object
//
// { url, line[, actor] }
// { url, line, column[, actor] }
//
// where the `actor` property is optional.
this._breakpoints = Object.create(null);
@@ -58,6 +58,7 @@ BreakpointStore.prototype = {
* - line
* - column (optional; omission implies that the breakpoint is for
* the whole line)
* - condition (optional)
* - actor (optional)
*/
addBreakpoint: function (aBreakpoint) {
@@ -1374,7 +1375,8 @@ ThreadActor.prototype = {
let response = this._createAndStoreBreakpoint({
url: url,
line: line,
column: column
column: column,
condition: aRequest.condition
});
// If the original location of our generated location is different from
// the original location we attempted to set the breakpoint on, we will
@@ -1442,11 +1444,13 @@ ThreadActor.prototype = {
let storedBp = this.breakpointStore.getBreakpoint(aLocation);
if (storedBp.actor) {
actor = storedBp.actor;
actor.condition = aLocation.condition;
} else {
storedBp.actor = actor = new BreakpointActor(this, {
url: aLocation.url,
line: aLocation.line,
column: aLocation.column
column: aLocation.column,
condition: aLocation.condition
});
this.threadLifetimePool.addActor(actor);
}
@@ -4221,15 +4225,17 @@ FrameActor.prototype.requestTypes = {
* @param object aLocation
* The location of the breakpoint as specified in the protocol.
*/
function BreakpointActor(aThreadActor, aLocation)
function BreakpointActor(aThreadActor, { url, line, column, condition })
{
this.scripts = [];
this.threadActor = aThreadActor;
this.location = aLocation;
this.location = { url: url, line: line, column: column };
this.condition = condition;
}
BreakpointActor.prototype = {
actorPrefix: "breakpoint",
condition: null,
/**
* Called when this same breakpoint is added to another Debugger.Script
@@ -4255,6 +4261,14 @@ BreakpointActor.prototype = {
this.scripts = [];
},
isValidCondition: function(aFrame) {
if(!this.condition) {
return true;
}
var res = aFrame.eval(this.condition);
return res.return;
},
/**
* A function that the engine calls when a breakpoint has been hit.
*
@@ -4271,7 +4285,9 @@ BreakpointActor.prototype = {
column: this.location.column
}));
if (this.threadActor.sources.isBlackBoxed(url) || aFrame.onStep) {
if (this.threadActor.sources.isBlackBoxed(url)
|| aFrame.onStep
|| !this.isValidCondition(aFrame)) {
return undefined;
}
+1
View File
@@ -65,6 +65,7 @@ this.promised = promised;
this.all = all;
Cu.import("resource://gre/modules/devtools/SourceMap.jsm");
Cu.import("resource://gre/modules/devtools/Console.jsm");
function dumpn(str) {
if (wantLogging) {
@@ -30,6 +30,7 @@ function tryImport(url) {
tryImport("resource://gre/modules/devtools/dbg-server.jsm");
tryImport("resource://gre/modules/devtools/dbg-client.jsm");
tryImport("resource://gre/modules/devtools/Loader.jsm");
tryImport("resource://gre/modules/devtools/Console.jsm");
function testExceptionHook(ex) {
try {
@@ -0,0 +1,61 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Check conditional breakpoint when condition evaluates to true.
*/
var gDebuggee;
var gClient;
var gThreadClient;
function run_test()
{
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-conditional-breakpoint");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function () {
attachTestTabAndResume(gClient, "test-conditional-breakpoint", function (aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_simple_breakpoint();
});
});
do_test_pending();
}
function test_simple_breakpoint()
{
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
gThreadClient.setBreakpoint({
url: "test.js",
line: 3,
condition: "a === 1"
}, function (aResponse, bpClient) {
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
// Check the return value.
do_check_eq(aPacket.why.type, "breakpoint");
do_check_eq(aPacket.frame.where.line, 3);
// Remove the breakpoint.
bpClient.remove(function (aResponse) {
gThreadClient.resume(function () {
finishClient(gClient);
});
});
});
// Continue until the breakpoint is hit.
gThreadClient.resume();
});
});
Components.utils.evalInSandbox("debugger;\n" + // 1
"var a = 1;\n" + // 2
"var b = 2;\n", // 3
gDebuggee,
"1.8",
"test.js",
1);
}
@@ -0,0 +1,60 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Check conditional breakpoint when condition evaluates to false.
*/
var gDebuggee;
var gClient;
var gThreadClient;
function run_test()
{
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-conditional-breakpoint");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function () {
attachTestTabAndResume(gClient, "test-conditional-breakpoint", function (aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_simple_breakpoint();
});
});
do_test_pending();
}
function test_simple_breakpoint()
{
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
gThreadClient.setBreakpoint({
url: "test.js",
line: 3,
condition: "a === 2"
}, function (aResponse, bpClient) {
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
// Check the return value.
do_check_eq(aPacket.why.type, "debuggerStatement");
do_check_eq(aPacket.frame.where.line, 4);
// Remove the breakpoint.
bpClient.remove(function (aResponse) {
gThreadClient.resume(function () {
finishClient(gClient);
});
});
});
// Continue until the breakpoint is hit.
gThreadClient.resume();
});
});
Components.utils.evalInSandbox("debugger;\n" + // 1
"var a = 1;\n" + // 2
"var b = 2;\n" + // 3
"debugger;", // 4
gDebuggee,
"1.8",
"test.js",
1);
}
@@ -0,0 +1,62 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Check conditional breakpoint when condition throws and make sure it is ignored
*/
var gDebuggee;
var gClient;
var gThreadClient;
function run_test()
{
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-conditional-breakpoint");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function () {
attachTestTabAndResume(gClient, "test-conditional-breakpoint", function (aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_simple_breakpoint();
});
});
do_test_pending();
}
function test_simple_breakpoint()
{
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
gThreadClient.setBreakpoint({
url: "test.js",
line: 3,
condition: "throw new Error()"
}, function (aResponse, bpClient) {
gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
// Check the return value.
do_check_eq(aPacket.why.type, "debuggerStatement");
do_check_eq(aPacket.frame.where.line, 4);
// Remove the breakpoint.
bpClient.remove(function (aResponse) {
gThreadClient.resume(function () {
finishClient(gClient);
});
});
});
// Continue until the breakpoint is hit.
gThreadClient.resume();
});
});
Components.utils.evalInSandbox("debugger;\n" + // 1
"var a = 1;\n" + // 2
"var b = 2;\n" + // 3
"debugger;", // 4
gDebuggee,
"1.8",
"test.js",
1);
}
@@ -112,6 +112,9 @@ reason = bug 820380
[test_breakpoint-16.js]
[test_breakpoint-17.js]
[test_breakpoint-18.js]
[test_conditional_breakpoint-01.js]
[test_conditional_breakpoint-02.js]
[test_conditional_breakpoint-03.js]
[test_eventlooplag_actor.js]
run-if = toolkit == "gonk"
[test_listsources-01.js]