Confirmed users
231
edits
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
Besides the low-level [https://developer.mozilla.org/en/SpiderMonkey/JS_Debugger_API_Guide JS Debugger API], there is a debugger client module that allows | Besides the "low-level", direct [https://developer.mozilla.org/en/SpiderMonkey/JS_Debugger_API_Guide JS Debugger API], there is a debugger client module that allows applications to be written that control the debugger using the [https://wiki.mozilla.org/Remote_Debugging_Protocol Remote Debugging Protocol]. | ||
function startDebugger() | = Starting the Debugger<br> = | ||
In order to communicate with the Debugger, a client and a server instance must be created and a protocol connection must be established. The connection can be either over a TCP socket or an nsIPipe. The startDebugger function displayed below establishes an nsIPipe-backed connection:<br> | |||
<pre>function startDebugger() | |||
{ | { | ||
// Start the server. | // Start the server. | ||
| Line 17: | Line 13: | ||
// Listen to an nsIPipe | // Listen to an nsIPipe | ||
let transport = DebuggerServer.connectPipe(); | let transport = DebuggerServer.connectPipe(); | ||
// Start the client. | |||
client = new DebuggerClient(transport); | |||
// Attach listeners for client events. | |||
client.addListener("tabNavigated", onTab); | |||
client.addListener("newScript", fooListener); | |||
client.ready(function(aType, aTraits) { | |||
// Now the client is conected to the server. | |||
debugTab(); | |||
}); | |||
} | |||
</pre> | |||
If a TCP socket is required, the function should be split in two parts, a server-side and a client-side, like this:<br> | |||
<pre>function serverStartDebugger() | |||
{ | |||
// Start the server. | |||
if (!DebuggerServer.initialized) { | |||
DebuggerServer.init(); | |||
DebuggerServer.addBrowserActors(); | |||
} | |||
// For an nsIServerSocket we do this: | // For an nsIServerSocket we do this: | ||
DebuggerServer.openListener(2929, true); // A localhost-only connection on port 2929. | |||
} | |||
function clientStartDebugger() | |||
{ | |||
let transport = debuggerSocketConnect(aHost, aPort); | |||
// Start the client. | // Start the client. | ||
| Line 32: | Line 51: | ||
}); | }); | ||
} | } | ||
</pre> | |||
= Shutting down the Debugger<br> = | |||
When the application is finished, it has to notify the client to shut down the protocol connection. This makes sure that memory leaks are avoided and the server is terminated in an orderly fashion. Shutting down is as simple as it gets: | |||
foo | |||
boo | |||
function shutdownDebugger() | <pre>function shutdownDebugger() | ||
{ | { | ||
client.close(); | client.close(); | ||