Bug 795917 - Get executable lines through the remote debugging protocol;r=ejpbruel

This commit is contained in:
Seris 2014-10-01 17:57:49 +01:00
Родитель 13ad141eb6
Коммит 7c671812bf
6 изменённых файлов: 206 добавлений и 5 удалений

Просмотреть файл

@ -5729,6 +5729,20 @@
"n_buckets": "50",
"description": "The total number of distinct attempts by third-party sites to place cookies which have been rejected. Measures are normalized per 24h."
},
"DEVTOOLS_DEBUGGER_RDP_LOCAL_GET_EXECUTABLE_LINES_MS": {
"expires_in_version": "never",
"kind": "exponential",
"high": "10000",
"n_buckets": "1000",
"description": "The time (in milliseconds) that it took a 'getExecutableLines' request to go round trip."
},
"DEVTOOLS_DEBUGGER_RDP_REMOTE_GET_EXECUTABLE_LINES_MS": {
"expires_in_version": "never",
"kind": "exponential",
"high": "10000",
"n_buckets": "1000",
"description": "The time (in milliseconds) that it took a 'getExecutableLines' request to go round trip."
},
"DEVTOOLS_DEBUGGER_RDP_LOCAL_BLACKBOX_MS": {
"expires_in_version": "never",
"kind": "exponential",

Просмотреть файл

@ -2425,6 +2425,23 @@ SourceClient.prototype = {
}
}),
/**
* Get Executable Lines from a source
*
* @param aCallback Function
* The callback function called when we receive the response from the server.
*/
getExecutableLines: function(cb){
let packet = {
to: this._form.actor,
type: "getExecutableLines"
};
this._client.request(packet, res => {
cb(res.lines);
});
},
/**
* Get a long string grip for this SourceClient's source.
*/

Просмотреть файл

@ -2642,6 +2642,66 @@ SourceActor.prototype = {
return sourceFetched;
},
/**
* Get all executable lines from the current source
* @return Array - Executable lines of the current script
**/
getExecutableLines: function () {
// Check if the original source is source mapped
let packet = {
from: this.actorID
};
let lines;
if (this._sourceMap) {
lines = new Set();
// Position of executable lines in the generated source
let offsets = this.getExecutableOffsets(this._generatedSource, false);
for (let offset of offsets) {
let {line, source} = this._sourceMap.originalPositionFor({
line: offset.lineNumber,
column: offset.columnNumber
});
if (source === this._url) {
lines.add(line);
}
}
} else {
// Converting the set given by getExecutableOffsets to an array
lines = this.getExecutableOffsets(this._url, true);
}
// Converting the Set into an array
packet.lines = [line for (line of lines)];
packet.lines.sort((a, b) => {
return a - b;
});
return packet;
},
/**
* Extract all executable offsets from the given script
* @param String url - extract offsets of the script with this url
* @param Boolean onlyLine - will return only the line number
* @return Set - Executable offsets/lines of the script
**/
getExecutableOffsets: function (url, onlyLine) {
let offsets = new Set();
for (let s of this.threadActor.dbg.findScripts(this.threadActor.global)) {
if (s.url === url) {
for (let offset of s.getAllColumnOffsets()) {
offsets.add(onlyLine ? offset.lineNumber : offset);
}
}
}
return offsets;
},
/**
* Handler for the "source" packet.
*/
@ -2858,7 +2918,8 @@ SourceActor.prototype.requestTypes = {
"blackbox": SourceActor.prototype.onBlackBox,
"unblackbox": SourceActor.prototype.onUnblackBox,
"prettyPrint": SourceActor.prototype.onPrettyPrint,
"disablePrettyPrint": SourceActor.prototype.onDisablePrettyPrint
"disablePrettyPrint": SourceActor.prototype.onDisablePrettyPrint,
"getExecutableLines": SourceActor.prototype.getExecutableLines
};

Просмотреть файл

@ -0,0 +1,56 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test if getExecutableLines return correct information
*/
let gDebuggee;
let gClient;
let gThreadClient;
const SOURCE_MAPPED_FILE = getFileUrl("sourcemapped.js");
function run_test() {
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-get-executable-lines");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function _onConnect() {
attachTestTabAndResume(
gClient,
"test-get-executable-lines",
function (aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_executable_lines();
}
);
});
do_test_pending();
}
function test_executable_lines() {
gClient.addOneTimeListener("newSource", function _onNewSource(evt, packet) {
do_check_eq(evt, "newSource");
gThreadClient.getSources(function ({error, sources}) {
do_check_true(!error);
let source = gThreadClient.source(sources[0]);
source.getExecutableLines(function(lines){
do_check_true(arrays_equal([1, 2, 4, 6], lines));
finishClient(gClient);
});
});
});
let code = readFile("sourcemapped.js") + "\n//# sourceMappingURL=" +
getFileUrl("source-map-data/sourcemapped.map");
Components.utils.evalInSandbox(code, gDebuggee, "1.8",
SOURCE_MAPPED_FILE, 1);
}
function arrays_equal(a,b) {
return !(a<b || b<a);
}

Просмотреть файл

@ -0,0 +1,55 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Test if getExecutableLines return correct information
*/
let gDebuggee;
let gClient;
let gThreadClient;
const SOURCE_MAPPED_FILE = getFileUrl("sourcemapped.js");
function run_test() {
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-get-executable-lines");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function _onConnect() {
attachTestTabAndResume(
gClient,
"test-get-executable-lines",
function (aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_executable_lines();
}
);
});
do_test_pending();
}
function test_executable_lines() {
gClient.addOneTimeListener("newSource", function _onNewSource(evt, packet) {
do_check_eq(evt, "newSource");
gThreadClient.getSources(function ({error, sources}) {
do_check_true(!error);
let source = gThreadClient.source(sources[0]);
source.getExecutableLines(function(lines){
do_check_true(arrays_equal([2, 3, 5, 6, 7, 8, 12, 14, 16], lines));
finishClient(gClient);
});
});
});
let code = readFile("sourcemapped.js");
Components.utils.evalInSandbox(code, gDebuggee, "1.8",
SOURCE_MAPPED_FILE, 1);
}
function arrays_equal(a,b) {
return !(a<b || b<a);
}

Просмотреть файл

@ -213,7 +213,5 @@ reason = bug 937197
[test_monitor_actor.js]
[test_symbols-01.js]
[test_symbols-02.js]
[test_memory_footprint.js]
run-sequentially = measure memory, has to be run solo
skip-if = os != 'linux' || debug || asan
reason = bug 1014071
[test_get-executable-lines.js]
[test_get-executable-lines-source-map.js]